-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from aclowes/managment-tests
add management command tests
- Loading branch information
Showing
5 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |