From 346eb73f5cd7b240c67b73fc6c3f6daa688db6fa Mon Sep 17 00:00:00 2001 From: Jayesh Kariya Date: Tue, 20 Jan 2015 15:21:21 +0530 Subject: [PATCH] adding djangomod unit test case --- tests/unit/modules/djangomod_test.py | 97 ++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/unit/modules/djangomod_test.py diff --git a/tests/unit/modules/djangomod_test.py b/tests/unit/modules/djangomod_test.py new file mode 100644 index 0000000000..af4a374e62 --- /dev/null +++ b/tests/unit/modules/djangomod_test.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- +''' + :codeauthor: :email:`Jayesh Kariya ` +''' + +# Import Salt Testing Libs +from salttesting import TestCase, skipIf +from salttesting.mock import ( + MagicMock, + patch, + NO_MOCK, + NO_MOCK_REASON +) + +# Import Salt Libs +from salt.modules import djangomod + +# Globals +djangomod.__grains__ = {} +djangomod.__salt__ = {} +djangomod.__context__ = {} + + +@skipIf(NO_MOCK, NO_MOCK_REASON) +class DjangomodTestCase(TestCase): + ''' + Test cases for salt.modules.djangomod + ''' + # 'command' function tests: 1 + + @patch('salt.modules.djangomod._get_django_admin', + MagicMock(return_value=True)) + def test_command(self): + ''' + Test if it runs arbitrary django management command + ''' + mock = MagicMock(return_value=True) + with patch.dict(djangomod.__salt__, {'cmd.run': mock}): + self.assertTrue(djangomod.command('DJANGO_SETTINGS_MODULE', + 'validate')) + + # 'syncdb' function tests: 1 + + @patch('salt.modules.djangomod._get_django_admin', + MagicMock(return_value=True)) + def test_syncdb(self): + ''' + Test if it runs the Django-Admin syncdb command + ''' + mock = MagicMock(return_value=True) + with patch.dict(djangomod.__salt__, {'cmd.run': mock}): + self.assertTrue(djangomod.syncdb('DJANGO_SETTINGS_MODULE')) + + # 'createsuperuser' function tests: 1 + + @patch('salt.modules.djangomod._get_django_admin', + MagicMock(return_value=True)) + def test_createsuperuser(self): + ''' + Test if it create a super user for the database. + ''' + mock = MagicMock(return_value=True) + with patch.dict(djangomod.__salt__, {'cmd.run': mock}): + self.assertTrue(djangomod.createsuperuser('DJANGO_SETTINGS_MODULE', + 'SALT', + 'salt@slatstack.com')) + + # 'loaddata' function tests: 1 + + @patch('salt.modules.djangomod._get_django_admin', + MagicMock(return_value=True)) + def test_loaddata(self): + ''' + Test if it loads fixture data + ''' + mock = MagicMock(return_value=True) + with patch.dict(djangomod.__salt__, {'cmd.run': mock}): + self.assertTrue(djangomod.loaddata('DJANGO_SETTINGS_MODULE', + 'mydata')) + + # 'collectstatic' function tests: 1 + + @patch('salt.modules.djangomod._get_django_admin', + MagicMock(return_value=True)) + def test_collectstatic(self): + ''' + Test if it collect static files from each of your applications + into a single location + ''' + mock = MagicMock(return_value=True) + with patch.dict(djangomod.__salt__, {'cmd.run': mock}): + self.assertTrue(djangomod.collectstatic('DJANGO_SETTINGS_MODULE')) + + +if __name__ == '__main__': + from integration import run_tests + run_tests(DjangomodTestCase, needs_daemon=False)