def test_required_field_missing(self): # Arrange # Required field missing mock_json = { 'function_type': 'prospect_create', 'Ptype': 'YT', 'p.cm': { 'Name': 'Bob Test', 'Addr1': '3 Test Rd', 'Pcode': 'TT1 TT2', 'Tel': '1234567890', # 'Email': '*****@*****.**', } } # Act result = SoapService._validate_json(mock_json) # Assert self.assertFalse(result.success) self.assertIn("error: Key 'p.cm'", result.message, msg='p.cm error message') self.assertIn("Missing keys: 'Email'", result.message, msg='email error message')
def test_prospect_create_valid(self): """ Rules - * Ptype required and always 2 characters * p.cm required * Name required * Addr1 required max30 * Addr2 max30 optional * Addr3 max30 optional * Addr4 max30 optional * Pcode required max10 * Tel required max20 * Exec required default ABA1 * Agent required default 0000 * Cust.class required default Consumer * Cust.class.mf required default Consumer ???????????????????????? todo ask Graeme * Char1 required default TBC todo get this confirmed * Email required max50 """ # Arrange mock_json = { 'function_type': 'prospect_create', 'Ptype': 'YT', 'p.cm': { 'Name': 'Bob Test', 'Addr1': '3 Test Rd', 'Pcode': 'TT1 TT2', 'Tel': '1234567890', 'Email': '*****@*****.**', } } expected_result = { 'Ptype': 'YT', 'p.cm': { 'Name': 'Bob Test', 'Addr1': '3 Test Rd', 'Addr2': None, 'Addr3': None, 'Addr4': None, 'Pcode': 'TT1 TT2', 'Tel': '1234567890', 'Email': '*****@*****.**', 'Exec': 'ABA1', 'Agent': '0000', 'Cust.class': 'Consumer', 'Cust.class.mf': 'Consumer', 'Char1': 'TBC' } } # Act result = SoapService._validate_json(mock_json) self.assertTrue(result.success) self.assertEqual(result.data, expected_result) print(result.data)
def test_string_length_too_large(self): # Arrange # Required field missing mock_json = { 'function_type': 'prospect_create', 'Ptype': 'Too, many, characters', 'p.cm': { 'Name': 'Bob Test', 'Addr1': '3 Test Rd', 'Pcode': 'TT1 TT2', 'Tel': '1234567890', 'Email': '*****@*****.**', } } # Act result = SoapService._validate_json(mock_json) # Assert self.assertFalse(result.success) self.assertIn("Invalid Ptype length", result.message, msg='p.cm error message')