def test_given_input_is_blank_string_then_popen_has_standard_input_set_to_pipe_and_communicate_called_with_input(self): mock_process = MagicMock(returncode=1) # Subprocess typically returns byte strings. mock_process.communicate.return_value = (b"test_out", b"test_err") self.mock_popen.return_value = mock_process st_obj = st.SystemTest("test_script", "test_name") st_obj.load_settings( { 'arguments': "--area python test_server_repo_path", 'input': "", } ) st_obj.call_script() self.mock_popen.assert_called_once_with(["test_script", "--area", "python", "test_server_repo_path"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) mock_process.communicate.assert_called_once_with("") self.assertEqual(st_obj._std_out, "test_out") self.assertEqual(st_obj._std_err, "test_err") self.assertEqual(st_obj._return_code, 1)
def test_given_ends_with_string_is_none_then_function_returns(self): st_obj = st.SystemTest("test_script", "test_name") st_obj._std_out_ends_with_string = None st_obj._std_out = "I definitely exist." st_obj.check_std_out_ends_with_string()
def test_given_comparison_string_is_none_then_function_returns(self): st_obj = st.SystemTest("test_script", "test_name") st_obj._std_out_compare_string = None st_obj._std_out = "I definitely exist." st_obj.compare_std_out_to_string()
def setUp(self): self.repo_mock = MagicMock(working_tree_dir='root/dir/of/repo') self.server_mock = MagicMock() self.server_mock.temp_clone.return_value.repo = self.repo_mock self.st_obj = st.SystemTest("test_script", "test_name") self.st_obj.server = self.server_mock self.mock_checkout_remote_branch = set_up_mock(self, 'system_testing.vcs_git.checkout_remote_branch')
def setUp(self): self.mock_vcs_git = set_up_mock(self, 'system_testing.vcs_git') self.mock_is_server_repo = set_up_mock(self, 'dls_ade.Server.is_server_repo') self.mock_clone = set_up_mock(self, 'dls_ade.Server.temp_clone') st.Server.url = "ssh://GIT_SSH_ROOT" self.st_obj = st.SystemTest("test_script", "test_name")
def test_given_std_out_equal_to_comparison_string_then_test_passes(self): st_obj = st.SystemTest("test_script", "test_name") st_obj._std_out = "String to test for." st_obj.load_settings({ 'std_out_compare_string': "String to test for." }) st_obj.compare_std_out_to_string()
def test_given_std_out_ends_with_comparison_string_then_test_passes(self): st_obj = st.SystemTest("test_script", "test_name") st_obj._std_out = "String to test for." st_obj.load_settings({ 'std_out_ends_with_string': "to test for.", }) st_obj.check_std_out_ends_with_string()
def test_given_std_out_does_not_end_with_comparison_string_then_test_fails(self): st_obj = st.SystemTest("test_script", "test_name") st_obj._std_out = "String to test for." st_obj.load_settings({ 'std_out_ends_with_string': "test_for.", }) with self.assertRaises(AssertionError): st_obj.check_std_out_ends_with_string()
def test_given_std_out_not_equal_to_comparison_string_then_test_fails(self): st_obj = st.SystemTest("test_script", "test_name") st_obj._std_out = "String to test for." st_obj.load_settings({ 'std_out_compare_string': "A different string." }) with self.assertRaises(AssertionError): st_obj.compare_std_out_to_string()
def test_given_exception_raised_in_script_then_test_passes(self): st_obj = st.SystemTest("test_script", "test_name") st_obj._return_code = 1 st_obj._std_err = "\ntest_exception_type: test exception string\n" st_obj.load_settings({ 'exception_type': "test_exception_type", 'exception_string': "test exception string" }) st_obj.check_std_out_for_exception_string()
def test_given_return_code_0_then_assertion_failed(self): st_obj = st.SystemTest("test_script", "test_name") st_obj._return_code = 0 st_obj.load_settings({ 'exception_type': "test_exception_type", 'exception_string': "test exception string" }) with self.assertRaises(AssertionError): st_obj.check_std_out_for_exception_string()
def setUp(self): self.st_obj = st.SystemTest("test_script", "test_name") self.mock_check_remote_repo_exists = set_up_mock( self, "system_testing.SystemTest.check_remote_repo_exists" ) self.mock_clone_server_repo = set_up_mock( self, "system_testing.SystemTest.clone_server_repo" )
def test_given_exception_not_raised_in_script_then_test_fails(self): st_obj = st.SystemTest("test_script", "test_name") st_obj._return_code = 1 st_obj._std_err = "\nother_exception_type: other exception string\n" st_obj.load_settings({ 'exception_type': "test_exception_type", 'exception_string': "test exception string" }) with self.assertRaises(AssertionError): st_obj.check_std_out_for_exception_string()
def test_given_dictionary_contains_only_items_in_settings_list_then_dict_updated_with_all(self): settings = { 'arguments': "--area python test_module_name", 'std_out_compare_string': "test_output" } st_obj = st.SystemTest("test_script.py", "test_name") st_obj.load_settings(settings) self.assertEqual(st_obj._arguments, "--area python test_module_name") self.assertEqual(st_obj._std_out_compare_string, "test_output")
def test_given_message_provided_but_no_type_then_exception_raised_with_correct_message(self): comp_message = ("Both exception_type and exception_string must be provided.") st_obj = st.SystemTest("test_script", "test_name") st_obj.load_settings({ 'exception_string': "test exception string" }) with self.assertRaises(st.SystemTestingError) as e: st_obj.check_std_out_for_exception_string() self.assertEqual(str(e.exception), comp_message)
def test_given_dictionary_contains_items_that_do_not_exist_in_settings_list_then_dict_only_updated_with_those_that_are(self): settings = { 'arguments': "--area python test_module_name", 'std_out_compare_string': "test_output", 'std_out': "this should not get updated" } st_obj = st.SystemTest("test_script.py", "test_name") st_obj.load_settings(settings) self.assertEqual(st_obj._arguments, "--area python test_module_name") self.assertEqual(st_obj._std_out_compare_string, "test_output") self.assertNotEqual(st_obj._std_out, "this should not get updated")
def setUp(self): self.st_obj = st.SystemTest("test_script", "test_name")
def setUp(self): self.st_obj = st.SystemTest("test_script", "test_name") self.mock_delete_temp_repo = set_up_mock(self, "system_testing.delete_temp_repo")
def setUp(self): self.mock_check_folders_equal = set_up_mock(self, 'system_testing.check_if_repos_equal') self.st_obj = st.SystemTest("test_script", "test_name")
def setUp(self): self.mock_check_git_attributes = set_up_mock(self, 'system_testing.vcs_git.check_git_attributes') self.st_obj = st.SystemTest("test_script", "test_name")
def setUp(self): self.mock_get_active_branch = set_up_mock(self, 'system_testing.vcs_git.get_active_branch') self.st_obj = st.SystemTest("test_script", "test_name")
def test_given_neither_exception_type_nor_message_then_test_passes(self): st_obj = st.SystemTest("test_script", "test_name") st_obj.check_std_out_for_exception_string()
def setUp(self): self.st_obj = st.SystemTest("test_script", "test_name") self.st_obj._server_repo_path = "test_repo_path"