def test_parse_valid_data(self): """ Test that valid json data is parsed as expected """ # Arrange mock_json = { 'function_type': 'prospect_create', 'p.cm': { 'Name': 'Bob Test', 'Addr1': '3 Test Rd', 'Pcode': 'TT1 TT2', 'Tel': '1234567890', 'Dob': '23/07/1986', 'Exec': '£$%' }, 'Ptype': 'YT' } expected_result = ET.tostring( ET.parse('templates\\test_xml\\prospect_create.xml').getroot(), encoding='unicode') # Act result = SoapService._parse_create(mock_json, self.mock_xml_template) # Assert self.assertTrue(result.success) self.assertEqual(self.strip(result.data), self.strip(expected_result)) self.assertEquals(str, type(result.data))
def test_p_type_required(self, mock_logger: mock.MagicMock): """ Test invalid json due to no Ptype being provided is handled and logged """ # Arrange mock_json = { 'function_type': 'prospect_create', 'p.cm': { 'Name': 'Bob Test', 'Addr1': '3 Test Rd', 'Pcode': 'TT1 TT2', 'Tel': '1234567890', 'Dob': '23/07/1986', 'Exec': '£$%' }, } # Act result = SoapService._parse_create(mock_json, self.mock_xml_template) # Assert self.assertFalse(result.success) self.assertEquals(result.message, "Failed to _parse_create, error: 'Ptype'") mock_logger.assert_called_once_with( "Failed to _parse_create, error: 'Ptype'")
def test_p_cm_required(self, mock_logger: mock.MagicMock): """ Test invalid json due to no p.cm being provided is handled and logged """ # Arrange mock_json = {'function_type': 'prospect_create', 'Ptype': 'YT'} # Act result = SoapService._parse_create(mock_json, self.mock_xml_template) # Assert self.assertFalse(result.success) self.assertEquals(result.message, "Failed to _parse_create, error: 'p.cm'") mock_logger.assert_called_once_with( "Failed to _parse_create, error: 'p.cm'")