def test_script(self, execute_manager): # The test script should execute the standard Django test # command with any apps given as its arguments. test.main('cheeseshop.development', 'spamm', 'eggs') # We only care about the arguments given to execute_manager self.assertEqual(execute_manager.call_args[1], {'argv': ['test', 'test', 'spamm', 'eggs']})
def test_script(self, execute_manager): # The test script should execute the standard Django test # command with any apps given as its arguments. from djangorecipe import test test.main('cheeseshop.development', 'spamm', 'eggs') # We only care about the arguments given to execute_manager self.assertEqual(execute_manager.call_args[1], {'argv': ['test', 'test', 'spamm', 'eggs']})
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 djangorecipe given as its arguments. from djangorecipe import test test.main("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(self, mock_setdefault, execute_from_command_line): # The test script should execute the standard Django test # command with any apps given as its arguments. from djangorecipe import test test.main('cheeseshop.development', 'spamm', 'eggs') # We only care about the arguments given to execute_from_command_line self.assertEqual(execute_from_command_line.call_args[0], (['test', 'test', 'spamm', 'eggs'],)) self.assertEqual(mock_setdefault.call_args[0], ('DJANGO_SETTINGS_MODULE', 'cheeseshop.development'))
def test_script(self, mock_setdefault, execute_from_command_line): # The test script should execute the standard Django test # command with any apps given as its arguments. from djangorecipe import test test.main('cheeseshop.development', 'spamm', 'eggs') # We only care about the arguments given to execute_from_command_line self.assertEqual(execute_from_command_line.call_args[0], (['test', 'test', 'spamm', 'eggs'], )) self.assertEqual(mock_setdefault.call_args[0], ('DJANGO_SETTINGS_MODULE', 'cheeseshop.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 djangorecipe given as its arguments. from djangorecipe import test test.main('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'). from djangorecipe import test test.main('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_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'). from djangorecipe import test test.main("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, execute_manager): # 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 nce = mock.sentinel.NCE nce.development = settings sys.modules['cheeseshop'].nce = nce sys.modules['cheeseshop.nce'] = nce sys.modules['cheeseshop.nce.development'] = settings from djangorecipe import test test.main('cheeseshop.nce.development', 'tilsit', 'stilton') self.assertEqual(execute_manager.call_args[0], (settings,))
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 from djangorecipe import test test.main("cheeseshop.nce.development", "tilsit", "stilton") self.assertEqual(mock_setdefault.call_args[0], ("DJANGO_SETTINGS_MODULE", "cheeseshop.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 from djangorecipe import test test.main('cheeseshop.nce.development', 'tilsit', 'stilton') self.assertEqual(mock_setdefault.call_args[0], ('DJANGO_SETTINGS_MODULE', 'cheeseshop.nce.development'))
def test_settings_error(self, sys_exit): # When the settings file cannot be imported the test runner # wil exit with a message and a specific exit code. test.main('cheeseshop.tilsit', 'stilton') self.assertEqual(sys_exit.call_args, ((1,), {}))