diff --git a/.travis.yml b/.travis.yml index 4fbe112..9e530e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,4 @@ install: script: - ./itests/install-chronos.sh - ./itests/start-chronos.sh - - make itests + - make test && make itests diff --git a/Makefile b/Makefile index 1399e77..1cfb509 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +.PHONY: test +test: + tox + .PHONY: itests itests: tox -e itests diff --git a/tests/test_chronos_init.py b/tests/test_chronos_init.py new file mode 100644 index 0000000..85d5113 --- /dev/null +++ b/tests/test_chronos_init.py @@ -0,0 +1,23 @@ +import json + +import mock + +import chronos + + +def test_check_accepts_json(): + client = chronos.ChronosClient(hostname="localhost") + fake_response = mock.Mock() + fake_response.status = 200 + fake_content = '{ "foo": "bar" }' + actual = client._check(fake_response, fake_content) + assert actual == json.loads(fake_content) + + +def test_check_returns_raw_response_when_not_json(): + client = chronos.ChronosClient(hostname="localhost") + fake_response = mock.Mock() + fake_response.status = 401 + fake_content = 'UNAUTHORIZED' + actual = client._check(fake_response, fake_content) + assert actual == fake_content diff --git a/tox.ini b/tox.ini index 16eee32..aa87623 100644 --- a/tox.ini +++ b/tox.ini @@ -4,6 +4,24 @@ usedevelop=True basepython = python2.7 envlist = py + +[flake8] +max-line-length = 120 + + +[testenv:py] +basepython = python2.7 +deps = + -rrequirements.txt + pep8==1.5.7 + flake8 + pytest + mock +commands = + flake8 chronos tests + py.test -s {posargs:tests} + + [testenv:itests] passenv = TRAVIS basepython = python2.7