diff --git a/yawn/management/tests/static/favicon.ico b/yawn/management/tests/static/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/yawn/management/tests/static/index.html b/yawn/management/tests/static/index.html new file mode 100644 index 0000000..e69de29 diff --git a/yawn/management/tests/test_examples.py b/yawn/management/tests/test_examples.py new file mode 100644 index 0000000..863833c --- /dev/null +++ b/yawn/management/tests/test_examples.py @@ -0,0 +1,8 @@ +from django.core import management + +from yawn.workflow.models import Workflow + + +def test_examples(): + management.call_command('examples') + assert Workflow.objects.count() == 3 diff --git a/yawn/management/tests/test_webserver.py b/yawn/management/tests/test_webserver.py new file mode 100644 index 0000000..a7852e4 --- /dev/null +++ b/yawn/management/tests/test_webserver.py @@ -0,0 +1,38 @@ +import os +import sys + +from unittest import mock + +from django.conf import settings +from django.core import management + +from yawn.management.commands import webserver + + +@mock.patch.object(webserver.WSGIApplication, 'run') +def test_webserver(mock_run): + # pytest with coverage arguments causes gunicorn's argparse to fail + with mock.patch.object(sys, 'argv', ['worker']): + management.call_command('webserver') + assert mock_run.call_count == 1 + + +def test_static_files(): + root = os.path.join(settings.BASE_DIR, 'management/tests/static') + with mock.patch.object(settings, 'WHITENOISE_ROOT', root): + app = webserver.get_wsgi_application() + whitenoise = webserver.DefaultFileServer(app, settings) + whitenoise.application = mock.Mock() + + # an API request + whitenoise({'PATH_INFO': '/api/'}, None) + assert whitenoise.application.call_count == 1 + + # an unmatched file, goes to homepage + start_response = mock.Mock() + response = whitenoise({'PATH_INFO': '/', 'REQUEST_METHOD': 'GET'}, start_response) + assert 'index.html' in response.filelike.name + + # a real static file + response = whitenoise({'PATH_INFO': '/favicon.ico', 'REQUEST_METHOD': 'GET'}, start_response) + assert 'favicon.ico' in response.filelike.name diff --git a/yawn/management/tests/test_worker.py b/yawn/management/tests/test_worker.py new file mode 100644 index 0000000..d5f8200 --- /dev/null +++ b/yawn/management/tests/test_worker.py @@ -0,0 +1,11 @@ +from unittest import mock + +from django.core import management + +from yawn.management.commands import worker + + +@mock.patch.object(worker.Main, 'run') +def test_worker(mock_run): + management.call_command('worker') + assert mock_run.called