2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2012-06-30 21:24:22 +00:00
|
|
|
'''
|
|
|
|
Test the django module
|
|
|
|
'''
|
2013-06-24 22:53:59 +00:00
|
|
|
# Import Salt Testing libs
|
2013-06-24 19:06:49 +00:00
|
|
|
from salttesting import skipIf
|
2013-06-27 11:01:26 +00:00
|
|
|
from salttesting.helpers import ensure_in_syspath
|
2013-08-26 10:34:08 +00:00
|
|
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
2013-06-27 11:01:26 +00:00
|
|
|
ensure_in_syspath('../../')
|
2012-07-20 06:21:01 +00:00
|
|
|
|
2013-06-27 11:01:26 +00:00
|
|
|
# Import salt libs
|
|
|
|
import integration
|
2013-08-20 22:43:56 +00:00
|
|
|
from salt.modules import djangomod as django
|
2012-06-30 21:24:22 +00:00
|
|
|
|
2013-06-27 11:01:26 +00:00
|
|
|
django.__salt__ = {}
|
|
|
|
|
|
|
|
|
2013-08-26 10:34:08 +00:00
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2013-10-04 18:07:11 +00:00
|
|
|
@patch('salt.utils.which', lambda exe: exe)
|
2012-06-30 21:24:22 +00:00
|
|
|
class DjangoModuleTest(integration.ModuleCase):
|
|
|
|
'''
|
|
|
|
Test the django module
|
|
|
|
'''
|
|
|
|
|
|
|
|
def test_command(self):
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(django.__salt__,
|
|
|
|
{'cmd.run': mock}):
|
|
|
|
django.command('settings.py', 'runserver')
|
2012-11-30 17:13:12 +00:00
|
|
|
mock.assert_called_once_with(
|
2013-06-17 13:49:15 +00:00
|
|
|
'django-admin.py runserver --settings=settings.py',
|
2015-01-07 00:27:38 +00:00
|
|
|
python_shell=False,
|
2013-06-17 13:49:15 +00:00
|
|
|
env=None
|
2012-11-30 17:13:12 +00:00
|
|
|
)
|
2012-06-30 21:24:22 +00:00
|
|
|
|
|
|
|
def test_command_with_args(self):
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(django.__salt__,
|
|
|
|
{'cmd.run': mock}):
|
2012-11-30 17:13:12 +00:00
|
|
|
django.command(
|
|
|
|
'settings.py',
|
|
|
|
'runserver',
|
|
|
|
None,
|
|
|
|
None,
|
2013-06-17 13:49:15 +00:00
|
|
|
None,
|
2012-11-30 17:13:12 +00:00
|
|
|
'noinput',
|
|
|
|
'somethingelse'
|
|
|
|
)
|
|
|
|
mock.assert_called_once_with(
|
|
|
|
'django-admin.py runserver --settings=settings.py '
|
2013-06-17 13:49:15 +00:00
|
|
|
'--noinput --somethingelse',
|
2015-01-07 00:27:38 +00:00
|
|
|
python_shell=False,
|
2013-06-17 13:49:15 +00:00
|
|
|
env=None
|
2012-11-30 17:13:12 +00:00
|
|
|
)
|
2012-06-30 21:24:22 +00:00
|
|
|
|
|
|
|
def test_command_with_kwargs(self):
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(django.__salt__,
|
|
|
|
{'cmd.run': mock}):
|
2012-11-30 17:13:12 +00:00
|
|
|
django.command(
|
|
|
|
'settings.py',
|
|
|
|
'runserver',
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
database='something'
|
|
|
|
)
|
|
|
|
mock.assert_called_once_with(
|
|
|
|
'django-admin.py runserver --settings=settings.py '
|
2013-06-17 13:49:15 +00:00
|
|
|
'--database=something',
|
2015-01-07 00:27:38 +00:00
|
|
|
python_shell=False,
|
2013-06-17 13:49:15 +00:00
|
|
|
env=None
|
2012-11-30 17:13:12 +00:00
|
|
|
)
|
2012-06-30 21:24:22 +00:00
|
|
|
|
|
|
|
def test_command_with_kwargs_ignore_dunder(self):
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(django.__salt__,
|
|
|
|
{'cmd.run': mock}):
|
2012-11-30 17:13:12 +00:00
|
|
|
django.command(
|
|
|
|
'settings.py', 'runserver', None, None, __ignore='something'
|
|
|
|
)
|
|
|
|
mock.assert_called_once_with(
|
2013-06-17 13:49:15 +00:00
|
|
|
'django-admin.py runserver --settings=settings.py',
|
2015-01-07 00:27:38 +00:00
|
|
|
python_shell=False,
|
2013-06-17 13:49:15 +00:00
|
|
|
env=None
|
2012-11-30 17:13:12 +00:00
|
|
|
)
|
2012-06-30 21:24:22 +00:00
|
|
|
|
|
|
|
def test_syncdb(self):
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(django.__salt__,
|
|
|
|
{'cmd.run': mock}):
|
|
|
|
django.syncdb('settings.py')
|
2012-11-30 17:13:12 +00:00
|
|
|
mock.assert_called_once_with(
|
2013-06-17 13:49:15 +00:00
|
|
|
'django-admin.py syncdb --settings=settings.py --noinput',
|
2015-01-06 22:26:46 +00:00
|
|
|
python_shell=False,
|
2015-01-07 00:27:38 +00:00
|
|
|
env=None
|
2012-11-30 17:13:12 +00:00
|
|
|
)
|
2012-06-30 21:24:22 +00:00
|
|
|
|
|
|
|
def test_syncdb_migrate(self):
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(django.__salt__,
|
|
|
|
{'cmd.run': mock}):
|
|
|
|
django.syncdb('settings.py', migrate=True)
|
2012-11-30 17:13:12 +00:00
|
|
|
mock.assert_called_once_with(
|
|
|
|
'django-admin.py syncdb --settings=settings.py --migrate '
|
2013-06-17 13:49:15 +00:00
|
|
|
'--noinput',
|
2015-01-06 22:26:46 +00:00
|
|
|
python_shell=False,
|
2015-01-07 00:27:38 +00:00
|
|
|
env=None
|
2012-11-30 17:13:12 +00:00
|
|
|
)
|
2012-06-30 21:24:22 +00:00
|
|
|
|
|
|
|
def test_createsuperuser(self):
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(django.__salt__,
|
|
|
|
{'cmd.run': mock}):
|
2012-11-30 17:13:12 +00:00
|
|
|
django.createsuperuser(
|
|
|
|
'settings.py', 'testuser', 'user@example.com'
|
|
|
|
)
|
|
|
|
mock.assert_called_once_with(
|
|
|
|
'django-admin.py createsuperuser --settings=settings.py '
|
2013-06-17 13:49:15 +00:00
|
|
|
'--noinput --username=testuser --email=user@example.com',
|
2015-01-07 00:27:38 +00:00
|
|
|
python_shell=False,
|
2013-06-17 13:49:15 +00:00
|
|
|
env=None
|
2012-11-30 17:13:12 +00:00
|
|
|
)
|
2012-06-30 21:24:22 +00:00
|
|
|
|
2013-06-19 06:35:08 +00:00
|
|
|
def no_test_loaddata(self):
|
2012-06-30 21:24:22 +00:00
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(django.__salt__,
|
|
|
|
{'cmd.run': mock}):
|
|
|
|
django.loaddata('settings.py', 'app1,app2')
|
2012-11-30 17:13:12 +00:00
|
|
|
mock.assert_called_once_with(
|
2013-06-17 13:49:15 +00:00
|
|
|
'django-admin.py loaddata --settings=settings.py app1 app2',
|
2012-11-30 17:13:12 +00:00
|
|
|
)
|
2012-06-30 21:24:22 +00:00
|
|
|
|
|
|
|
def test_collectstatic(self):
|
|
|
|
mock = MagicMock()
|
|
|
|
with patch.dict(django.__salt__,
|
|
|
|
{'cmd.run': mock}):
|
2012-11-30 17:13:12 +00:00
|
|
|
django.collectstatic(
|
|
|
|
'settings.py', None, True, 'something', True, True, True, True
|
|
|
|
)
|
|
|
|
mock.assert_called_once_with(
|
|
|
|
'django-admin.py collectstatic --settings=settings.py '
|
2012-11-30 17:33:20 +00:00
|
|
|
'--noinput --no-post-process --dry-run --clear --link '
|
2015-01-06 22:26:46 +00:00
|
|
|
'--no-default-ignore --ignore=something',
|
2015-01-07 00:27:38 +00:00
|
|
|
python_shell=False,
|
|
|
|
env=None
|
2012-11-30 17:13:12 +00:00
|
|
|
)
|
2012-06-30 21:24:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-07-20 06:21:01 +00:00
|
|
|
from integration import run_tests
|
|
|
|
run_tests(DjangoModuleTest)
|