Including travis tests.

This commit is contained in:
tomasgodoi 2017-08-29 01:21:32 -03:00
parent 0c9cd00b9c
commit 86d6ff8b63
5 changed files with 45 additions and 19 deletions

View File

@ -7,7 +7,6 @@ python:
install: install:
- docker build -f tests/docker/Dockerfile -t txgio/anki-connect . - docker build -f tests/docker/Dockerfile -t txgio/anki-connect .
script: script:
- docker run -ti -d --rm -p 8765:8765 txgio/anki-connect - docker run -ti -d --rm -p 8888:8765 -e ANKICONNECT_BIND_ADDRESS=0.0.0.0 txgio/anki-connect
- sleep 5 - sleep 5
- > - python -m unittest discover -v
curl localhost:8765 -X POST -s -d '{"action": "version"}'

View File

@ -1,24 +1,14 @@
FROM txgio/anki FROM txgio/anki:2.0.45
USER root RUN apt-get update && \
RUN apt-get update apt-get install -y xvfb
RUN apt-get install -y xvfb
USER anki-user
RUN mkdir -p /home/anki-user/Documents/Anki/addons COPY AnkiConnect.py /data/addons/AnkiConnect.py
COPY AnkiConnect.py /home/anki-user/Documents/Anki/addons COPY tests/docker/prefs.db /data/prefs.db
ENV ANKICONNECT_BIND_ADDRESS 0.0.0.0
COPY tests/docker/prefs.db /home/anki-user/Documents/Anki/prefs.db
ADD tests/docker/entrypoint.sh /entrypoint.sh ADD tests/docker/entrypoint.sh /entrypoint.sh
USER root
RUN chmod +x /entrypoint.sh
USER anki-user
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD /bin/bash -c "(/usr/bin/ibus-daemon -xd; /usr/bin/anki;)" CMD ["anki", "-b", "/data"]

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