def test_application_service_11_debug(mock_debug): """ Action : Test the main server script loop. Expected Results : Test finished with status "Passed". Returns: N/A. """ set_parser('XML', sys.argv[2]) signal_interpreter_app.test_client().post('/', data=json.dumps( dict({'service': '11'})), content_type='application/json') mock_debug.assert_has_calls([ call( 'Available Services : %s ', { 'services': [{ 'title': 'ECU Reset', 'id': '11' }, { 'title': 'Security Access', 'id': '27' }] }), call('Requested Id : "%s"', '11'), call('Service : "%s"', 'ECU Reset'), call('Answer : "%s"', 'ECU Reset') ])
def test_application_wrong_xml_data_error(mock_error): """ Action : Test the server correct error check Expected Results : Test finished with status "Passed". Returns: N/A. """ set_parser('XML', sys.argv[2]) signal_interpreter_app.test_client().post('/', data=json.dumps( dict({'xxxxx': '27'})), content_type='application/json') mock_error.assert_has_calls([call('Exception %s occurred', "'service'")])
def test_application_wrong_json_file_content_error(): """ Action : Test the server correct error check. Expected Results : Test finished with status "Passed". Returns: N/A. """ with pytest.raises(ParserErrorDecodeError): set_parser('XML', sys.argv[2]) signal_interpreter_app.test_client().post('/', data=json.dumps (dict({'service': '27'})), content_type='application' '/json')
def test_application_service_27_info(mock_info): """ Action : Test the main server script loop. Expected Results : Test finished with status "Passed". Returns: N/A. """ set_parser('XML', sys.argv[2]) signal_interpreter_app.test_client().post('/', data=json.dumps( dict({'service': '27'})), content_type='application/json') mock_info.assert_has_calls( [call("Processing Request..."), call("Sending data to client...")])
def test_application_wrong_id_info(mock_warning): """ Action : Test the server correct error check Expected Results : Test finished with status "Passed". Returns: N/A. """ set_parser('XML', sys.argv[2]) signal_interpreter_app.test_client().post('/', data=json.dumps( dict({'service': '1876871'})), content_type='application/json') mock_warning.assert_has_calls([ call('Service %s not suported!', '1876871'), call("The Requested Id is Not Avaiable") ])
def test_correct_data(): """ Action : Test mocking server answer. Expected Results : No difference from normal application usage. Returns: N/A. """ set_parser('YAML', sys.argv[2]) signal_interpreter_app.testing = True signal_interpreter_app_instance = signal_interpreter_app.test_client() with patch.object( LoadAndParseYaml, "return_signal_by_title", return_value="Security Access")\ as mock_return_signal_by_title: with signal_interpreter_app_instance as client: payload = {"service": "27"} response = client.post("/", json=payload) mock_return_signal_by_title.assert_called_with("27") assert response.get_json() == "Security Access"