Merge branch 'master' into dev

This commit is contained in:
Alex Yatskov 2017-08-30 20:47:18 -07:00
commit 6c9e3126cb
12 changed files with 133 additions and 0 deletions

19
.travis.yml Normal file
View File

@ -0,0 +1,19 @@
sudo: required
language: python
addons:
hosts:
- docker
services:
- docker
python:
- "2.7"
install:
- docker build -f tests/docker/$ANKI_VERSION/Dockerfile -t txgio/anki-connect:$ANKI_VERSION .
script:
- docker run -ti -d --rm -p 8888:8765 -e ANKICONNECT_BIND_ADDRESS=0.0.0.0 txgio/anki-connect:$ANKI_VERSION
- ./tests/scripts/wait-up.sh http://docker:8888
- python -m unittest discover -s tests -v
env:
- ANKI_VERSION=2.0.x
- ANKI_VERSION=2.1.x

5
build_zip.sh Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/bash
rm AnkiConnect.zip
cp AnkiConnect.py __init__.py
7za a AnkiConnect.zip __init__.py
rm __init__.py

View File

@ -0,0 +1,14 @@
FROM txgio/anki:2.0.45
RUN apt-get update && \
apt-get install -y xvfb
COPY AnkiConnect.py /data/addons/AnkiConnect.py
COPY tests/docker/2.0.x/prefs.db /data/prefs.db
ADD tests/docker/2.0.x/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["anki", "-b", "/data"]

View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e
# Start Xvfb
Xvfb -ac -screen scrn 1280x2000x24 :99.0 &
export DISPLAY=:99.0
exec "$@"

BIN
tests/docker/2.0.x/prefs.db Normal file

Binary file not shown.

View File

@ -0,0 +1,14 @@
FROM txgio/anki:2.1.0beta14
RUN apt-get update && \
apt-get install -y xvfb
COPY AnkiConnect.py /data/addons21/AnkiConnect/__init__.py
COPY tests/docker/2.1.x/prefs21.db /data/prefs21.db
ADD tests/docker/2.1.x/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["anki", "-b", "/data"]

View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e
# Start Xvfb
Xvfb -ac -screen scrn 1280x2000x24 :99.0 &
export DISPLAY=:99.0
exec "$@"

Binary file not shown.

28
tests/scripts/wait-up.sh Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -e
if [ $# -lt 1 ]; then
printf "First parameter URL required.\n"
exit 1
fi
COUNTER=0
STEP_SIZE=1
MAX_SECONDS=${2:-10} # Wait 10 seconds if parameter not provided
MAX_RETRIES=$(( $MAX_SECONDS / $STEP_SIZE))
URL=$1
printf "Waiting URL: "$URL"\n"
until $(curl --insecure --output /dev/null --silent --fail $URL) || [ $COUNTER -eq $MAX_RETRIES ]; do
printf '.'
sleep $STEP_SIZE
COUNTER=$(($COUNTER + 1))
done
if [ $COUNTER -eq $MAX_RETRIES ]; then
printf "\nTimeout after "$(( $COUNTER * $STEP_SIZE))" second(s).\n"
exit 2
else
printf "\nUp successfully after "$(( $COUNTER * $STEP_SIZE))" second(s).\n"
fi

16
tests/test_decks.py Normal file
View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
import unittest
from unittest import TestCase
from util import callAnkiConnectEndpoint
class TestDeckNames(TestCase):
def test_deckNames(self):
response = callAnkiConnectEndpoint({'action': 'deckNames'})
self.assertEqual(['Default'], response)
class TestGetDeckConfig(TestCase):
def test_getDeckConfig(self):
response = callAnkiConnectEndpoint({'action': 'getDeckConfig', 'params': {'deck': 'Default'}})
self.assertDictContainsSubset({'name': 'Default', 'replayq': True}, response)

10
tests/test_misc.py Normal file
View File

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
import unittest
from unittest import TestCase
from util import callAnkiConnectEndpoint
class TestVersion(TestCase):
def test_version(self):
response = callAnkiConnectEndpoint({'action': 'version'})
self.assertEqual(4, response)

11
tests/util.py Normal file
View File

@ -0,0 +1,11 @@
import json
import urllib
import urllib2
def callAnkiConnectEndpoint(data):
url = 'http://docker:8888'
dumpedData = json.dumps(data)
req = urllib2.Request(url, dumpedData)
response = urllib2.urlopen(req).read()
responseData = json.loads(response)
return responseData