Merge branch 'test_systems' into 'master'

Test systems using tox

See merge request !16
This commit is contained in:
Tyrel Souza 2017-04-02 15:24:48 +00:00
commit 0f9b5d90a5
10 changed files with 70 additions and 18 deletions

28
.coveragerc Normal file
View File

@ -0,0 +1,28 @@
# .coveragerc to control coverage.py
[run]
branch = True
include=stagestatus/*.*
omit = ../*migrations*
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain about missing debug-only code:
def __repr__
if self\.debug
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
ignore_errors = True
[html]
directory = cover

1
.gitignore vendored
View File

@ -24,6 +24,7 @@ pip-log.txt
# Unit test / coverage reports
.coverage
cover
.tox
nosetests.xml

View File

@ -13,10 +13,7 @@ This will install the fake model factory generator, and test runners.
Running
-------
To run tests, simply use ``python manage.py test`` this will invoke Nose and pickup all the tests.
To start the auto testing, just run ``sniffer`` from the root project directory, this will watch all files in ``stagestatus/`` for changes, and if any ``.py`` files are changed it will re-run the tests.
You can pass ``-x appname`` to ``sniffer`` and it will run the appropriate tests for that app, but as of this writing, there is only one app.
To run tests, simply use ``tox`` this will instal all deps, and run the ``manage.py test`` command, invoke Nose and pickup all the tests.
To start the auto testing, just run ``sniffer`` from the root project directory, this will watch all files in ``stagestatus/`` for changes, and if any ``.py`` files are changed it will re-run the tests with ``tox``.

View File

@ -6,7 +6,8 @@ Django
django-model-utils
mysql-python
mysql-python; python_version < '2'
mysqlclient; python_version > '3'
djangorestframework
markdown # Markdown support for the browsable API.

View File

@ -5,3 +5,5 @@ model-mommy
django-nose
pyinotify
sniffer
coverage
tox

View File

@ -22,7 +22,4 @@ def py_files(filename):
@runnable
def execute_nose(*args):
from subprocess import call
if len(args) > 1:
return call('python manage.py test %s' % args[1], shell=True) == 0
else:
return call('python manage.py test', shell=True) == 0
return call('tox', shell=True) == 0

View File

@ -1,6 +1,6 @@
from __future__ import print_function
from django.test import TestCase
from django.test import TransactionTestCase
from model_mommy import mommy
@ -9,7 +9,8 @@ from django.contrib.auth.models import User
from machines.models import Machine, MachineStatus, MachineReservation
class ModelsTest(TestCase):
class ModelsTest(TransactionTestCase):
cleans_up_after_itself = True
def setUp(self):
self.user = mommy.make(User)

View File

@ -1,6 +1,7 @@
from __future__ import print_function
import json
from django.test import TestCase
from django.test import TransactionTestCase
from model_mommy import mommy
from rest_framework.renderers import JSONRenderer
@ -13,7 +14,8 @@ from machines.models import Machine, MachineStatus, MachineReservation
from machines.api.serializers import MachineSerializer
class SerializerTest(TestCase):
class SerializerTest(TransactionTestCase):
cleans_up_after_itself = True
def setUp(self):
self.user = mommy.make(User)
@ -28,8 +30,14 @@ class SerializerTest(TestCase):
def test_serializer(self):
"""
Test to make sure the serializer returns data in proper format
Test to make sure the api returns data in proper format,
not just the hostname and db_server
"""
ms = MachineSerializer(self.machine)
ms_json = JSONRenderer().render(ms)
self.assertEqual("", ms_json)
machine = MachineSerializer(self.machine)
machine_json = JSONRenderer().render(machine.data)
machine_dict = json.loads(machine_json)
keys = set(machine_dict.keys())
assumed_keys = set((u'db_server', u'hostname', u'is_reserved',
u'reservation', u'status'))
self.assertEqual(assumed_keys, keys)

View File

@ -121,6 +121,11 @@ AUTH_PASSWORD_VALIDATORS = [
]
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = [
'--with-coverage',
'--cover-html',
'--cover-erase',
]
try:
from .local import * # noqa

12
tox.ini Normal file
View File

@ -0,0 +1,12 @@
[tox]
;don't require setup.py
skipsdist=true
envlist=py27
[testenv:py27]
commands=
python manage.py test
setenv=
DJANGO_SETTINGS_MODULE=stagestatus.settings
deps=
-rrequirements/testing.txt