Skip to content

Commit

Permalink
Merge pull request #24 from aclowes/managment-tests
Browse files Browse the repository at this point in the history
add management command tests
  • Loading branch information
aclowes authored Aug 26, 2017
2 parents 0a236f5 + 3c7c8c4 commit a341b5d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions yawn/management/tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions yawn/management/tests/test_webserver.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions yawn/management/tests/test_worker.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a341b5d

Please sign in to comment.