def test_script(self, mock_setdefault, execute_from_command_line): with mock.patch.object(sys, 'argv', ['bin/test']): binscripts.test('testpanel.development', '', 'spamm', 'eggs') self.assertTrue(execute_from_command_line.called) self.assertEqual(execute_from_command_line.call_args[0], (['bin/test', 'test', 'spamm', 'eggs'],)) self.assertEqual(mock_setdefault.call_args[0], ('DJANGO_SETTINGS_MODULE', 'testpanel.development'))
def test_script(self, mock_setdefault, execute_from_command_line): with mock.patch.object(sys, 'argv', ['bin/test']): # The test script should execute the standard Django test command # with any apps configured in xabber_recipe given as its arguments. binscripts.test('cheeseshop.development', '', 'spamm', 'eggs') self.assertTrue(execute_from_command_line.called) self.assertEqual(execute_from_command_line.call_args[0], (['bin/test', 'test', 'spamm', 'eggs'],)) self.assertEqual(mock_setdefault.call_args[0], ('DJANGO_SETTINGS_MODULE', 'cheeseshop.development'))
def test_script_with_args(self, mock_setdefault, execute_from_command_line): with mock.patch.object(sys, 'argv', ['bin/test', '--verbose']): # The test script should execute the standard Django test command # with any apps given as its arguments. It should also pass along # command line arguments so that the actual test machinery can # pick them up (like '--verbose' or '--tests=xyz'). binscripts.test('cheeseshop.development', '', 'spamm', 'eggs') self.assertEqual( execute_from_command_line.call_args[0], (['bin/test', 'test', 'spamm', 'eggs', '--verbose'],)) self.assertEqual( mock_setdefault.call_args[0], ('DJANGO_SETTINGS_MODULE', 'cheeseshop.development'))
def test_deeply_nested_settings(self, mock_setdefault, execute_from_command_line): settings = mock.sentinel.SettingsModule settings.SECRET_KEY = 'Not super secret key' nce = mock.sentinel.NCE nce.development = settings sys.modules['testpanel'].nce = nce sys.modules['testpanel.nce'] = nce sys.modules['testpanel.nce.development'] = settings binscripts.test('testpanel.nce.development', '', 'tilsit', 'stilton') self.assertEqual( mock_setdefault.call_args[0], ('DJANGO_SETTINGS_MODULE', 'testpanel.nce.development'))
def test_deeply_nested_settings(self, mock_setdefault, execute_from_command_line): # Settings files can be more than two levels deep. We need to # make sure the test script can properly import those. To # demonstrate this we need to add another level to our # sys.modules entries. settings = mock.sentinel.SettingsModule settings.SECRET_KEY = 'I mock your secret key' nce = mock.sentinel.NCE nce.development = settings sys.modules['cheeseshop'].nce = nce sys.modules['cheeseshop.nce'] = nce sys.modules['cheeseshop.nce.development'] = settings binscripts.test('cheeseshop.nce.development', '', 'tilsit', 'stilton') self.assertEqual( mock_setdefault.call_args[0], ('DJANGO_SETTINGS_MODULE', 'cheeseshop.nce.development'))