Skip to content

Commit

Permalink
Add tests for @setup_django and opal serve
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmiller committed Jun 20, 2018
1 parent 7289828 commit 754c377
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion opal/core/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ def setup(*a, **k):

import django
django.setup()
return fn(*a, **k)
return fn(*a, **k)

return setup


def startproject(args):
scaffold_utils.start_project(args.name, USERLAND_HERE)
return
Expand Down
46 changes: 46 additions & 0 deletions opal/tests/test_core_commandline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Unittests for opal.core.commandline
"""
import os
import sys

from mock import patch, MagicMock
Expand Down Expand Up @@ -37,6 +38,37 @@ def test_not_found(self):
exiter.assert_called_with(1)


@patch('django.setup')
@patch.object(commandline, 'find_application_name')
@patch.dict(commandline.os.environ,{'mytemp':'mytemp'}, clear=True)
class SetupDjangoTestCase(OpalTestCase):

def test_settings_module(self, name, setup):

name.return_value = 'testapp'
@commandline.setup_django
def go():
pass

go()

self.assertEqual(
commandline.os.environ['DJANGO_SETTINGS_MODULE'],
'testapp.settings'
)

def test_setup_called(self, name, setup):

name.return_value = 'testapp'
@commandline.setup_django
def go():
pass

go()

setup.assert_called_once_with()


class StartprojectTestCase(OpalTestCase):

def test_startproject(self):
Expand Down Expand Up @@ -138,6 +170,20 @@ def test_checkout_with_uncommitted(self, ls, os, check_call, check_output):
writer.assert_any_call('Abandonning attempt to check out to requirements.txt')



class ServeTestCase(OpalTestCase):

def test_serve(self):
with patch.object(commandline.management, 'call_command') as call:
with patch.object(commandline, 'find_application_name') as name:
name.return_value = 'testapp'

mock_args = MagicMock(name='Mock args')
mock_args.addrport=['localhost:8000']
commandline.serve(mock_args)
call.assert_called_once_with('runserver', 'localhost:8000', '--traceback')


class ParseArgsTestCase(OpalTestCase):

def test_parse_args(self):
Expand Down

0 comments on commit 754c377

Please sign in to comment.