From bc3fefb45a60c71fb41de191284df3df0c9c3613 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Sat, 1 Apr 2017 18:22:16 +0000 Subject: [PATCH] Add Nose Tests --- docs/dependencies.rst | 28 ++++++++++++++++++++++++++++ docs/index.rst | 1 + docs/tests.rst | 20 +++++++++++++++++++- requirements/testing.txt | 3 +++ scent.py | 28 ++++++++++++++++++++++++++++ stagestatus/settings/base.py | 2 ++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 docs/dependencies.rst create mode 100644 scent.py diff --git a/docs/dependencies.rst b/docs/dependencies.rst new file mode 100644 index 0000000..e639d22 --- /dev/null +++ b/docs/dependencies.rst @@ -0,0 +1,28 @@ +Dependencies +============ + + +Python +~~~~~~ + + +Model Mommy +----------- + +Install: http://model-mommy.readthedocs.io/en/latest/index.html + +Model-mommy offers you a smart way to create fixtures for testing in Django. With a simple and powerful API you can create many objects with a single line of code. + +Django Nose +----------- + +https://django-nose.readthedocs.io/en/latest/usage.html + +django-nose provides all the goodness of nose in your Django tests. + +Sniffer +------- + +https://github.com/jeffh/sniffer/ + +sniffer is a autotest tool for Python using the nosetest library. diff --git a/docs/index.rst b/docs/index.rst index 56ee4bf..962e0f1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,6 +14,7 @@ Contents: install deploy tests + dependencies diff --git a/docs/tests.rst b/docs/tests.rst index ca50303..9bab073 100644 --- a/docs/tests.rst +++ b/docs/tests.rst @@ -1,4 +1,22 @@ Tests ===== -This is where you write how to test this project. + +Setup +----- + +First install the testing requirements with ``pip install -r requirements/testing.txt`` + +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. + + diff --git a/requirements/testing.txt b/requirements/testing.txt index 591513a..5e37033 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -2,3 +2,6 @@ mock model-mommy +django-nose +pyinotify +sniffer diff --git a/scent.py b/scent.py new file mode 100644 index 0000000..b3f85a5 --- /dev/null +++ b/scent.py @@ -0,0 +1,28 @@ +from sniffer.api import * # import the really small API +import os, termstyle + +# you can customize the pass/fail colors like this +pass_fg_color = termstyle.green +pass_bg_color = termstyle.bg_default +fail_fg_color = termstyle.red +fail_bg_color = termstyle.bg_default + +# All lists in this variable will be under surveillance for changes. +watch_paths = ['stagestatus/',] + +# this gets invoked on every file that gets changed in the directory. Return +# True to invoke any runnable functions, False otherwise. +# +# This fires runnables only if files ending with .py extension and not prefixed +# with a period. +@file_validator +def py_files(filename): + return filename.endswith('.py') and not os.path.basename(filename).startswith('.') + +@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 diff --git a/stagestatus/settings/base.py b/stagestatus/settings/base.py index 97c583e..84fd669 100644 --- a/stagestatus/settings/base.py +++ b/stagestatus/settings/base.py @@ -30,6 +30,7 @@ PROJECT_APPS = [ 'machines', ] THIRD_PARTY_APPS = [ + 'django_nose', 'rest_framework', ] INSTALLED_APPS += PROJECT_APPS @@ -127,6 +128,7 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] +TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' try: from .local import * # noqa