def testParsesStatePerson(self): # Arrange metadata = IngestMetadata.new_with_defaults( region='us_nd', jurisdiction_id='JURISDICTION_ID') ingest_person = ingest_info_pb2.StatePerson( gender='MALE', full_name='FULL_NAME', birthdate='12-31-1999', current_address='NNN\n STREET \t ZIP') # Act state_person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.StatePerson.new_with_defaults( gender=Gender.MALE, gender_raw_text='MALE', full_name='{"full_name": "FULL_NAME"}', birthdate=date(year=1999, month=12, day=31), birthdate_inferred_from_age=False, current_address='NNN STREET ZIP', residency_status=ResidencyStatus.PERMANENT, ) self.assertEqual(result, expected_result)
def testParseStatePerson_WithSurnameAndGivenNames_UsesFullNameAsJson(self): # Arrange metadata = FakeIngestMetadata.for_state(region="us_xx") ingest_person = ingest_info_pb2.StatePerson( state_code="us_xx", surname='UNESCAPED,SURNAME"WITH-CHARS"', given_names="GIVEN_NAMES", middle_names="MIDDLE_NAMES", ) # Act state_person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build(StatePersonFactory.deserialize) # Assert expected_full_name = ( '{{"given_names": "{}", "middle_names": "{}", "surname": "{}"}}'.format( "GIVEN_NAMES", "MIDDLE_NAMES", 'UNESCAPED,SURNAME\\"WITH-CHARS\\"' ) ) expected_result = entities.StatePerson.new_with_defaults( state_code="US_XX", full_name=expected_full_name ) self.assertEqual(result, expected_result)
def testParsesStatePerson(self): # Arrange metadata = FakeIngestMetadata.for_state(region="us_nd") ingest_person = ingest_info_pb2.StatePerson( gender="MALE", full_name="FULL_NAME", birthdate="12-31-1999", current_address="NNN\n STREET \t ZIP", ) # Act state_person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build(StatePersonFactory.deserialize) # Assert expected_result = entities.StatePerson.new_with_defaults( gender=Gender.MALE, gender_raw_text="MALE", full_name='{"full_name": "FULL_NAME"}', birthdate=date(year=1999, month=12, day=31), birthdate_inferred_from_age=False, current_address="NNN STREET ZIP", residency_status=ResidencyStatus.PERMANENT, state_code="US_ND", ) self.assertEqual(result, expected_result)
def testParseStatePerson_WithSurnameAndFullname_ThrowsException(self): # Arrange metadata = FakeIngestMetadata.for_state(region="us_xx") ingest_person = ingest_info_pb2.StatePerson( full_name="LAST,FIRST", surname="LAST" ) # Arrange + Act with self.assertRaises(ValueError): state_person.copy_fields_to_builder(self.subject, ingest_person, metadata)
def testParseStatePerson_WithSurnameAndFullname_ThrowsException(self): # Arrange metadata = IngestMetadata.new_with_defaults() ingest_person = ingest_info_pb2.StatePerson(full_name='LAST,FIRST', surname='LAST') # Arrange + Act with self.assertRaises(ValueError): state_person.copy_fields_to_builder(self.subject, ingest_person, metadata)
def testParseStatePerson_NoiseInPlaceOfResidence_ParsesResidency(self): # Arrange metadata = IngestMetadata.new_with_defaults(region='us_ky_allen') ingest_person = ingest_info_pb2.StatePerson( current_address='transient moves around') # Act state_person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.StatePerson.new_with_defaults( current_address='TRANSIENT MOVES AROUND', residency_status=ResidencyStatus.TRANSIENT) self.assertEqual(result, expected_result)
def testParseStatePerson_InfersBirthdateFromAge(self, mock_datetime): # Arrange mock_datetime.now.return_value = _NOW metadata = IngestMetadata.new_with_defaults() ingest_person = ingest_info_pb2.StatePerson(age='27') # Act state_person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.StatePerson.new_with_defaults( birthdate=datetime(year=_NOW.year - 27, month=1, day=1).date(), birthdate_inferred_from_age=True) self.assertEqual(result, expected_result)
def testParseStatePerson_TakesLastZipCodeMatch(self): # Arrange metadata = FakeIngestMetadata.for_state(region="us_nd") # 5-digit address could be mistaken for a zip code ingest_person = ingest_info_pb2.StatePerson(current_address="12345 Main 58503") # Act state_person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build(StatePersonFactory.deserialize) # Assert expected_result = entities.StatePerson.new_with_defaults( current_address="12345 MAIN 58503", residency_status=ResidencyStatus.PERMANENT, state_code="US_ND", ) self.assertEqual(result, expected_result)
def testParseStatePerson_TakesLastZipCodeMatch(self): # Arrange metadata = IngestMetadata.new_with_defaults(region='us_nd') # 5-digit address could be mistaken for a zip code ingest_person = ingest_info_pb2.StatePerson( current_address='12345 Main 58503') # Act state_person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.StatePerson.new_with_defaults( current_address='12345 MAIN 58503', residency_status=ResidencyStatus.PERMANENT) self.assertEqual(result, expected_result)
def testParseStatePerson_NoiseInPlaceOfResidence_ParsesResidency(self): # Arrange metadata = FakeIngestMetadata.for_state(region="us_xx") ingest_person = ingest_info_pb2.StatePerson( current_address="transient moves around" ) # Act state_person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build(StatePersonFactory.deserialize) # Assert expected_result = entities.StatePerson.new_with_defaults( current_address="TRANSIENT MOVES AROUND", residency_status=ResidencyStatus.TRANSIENT, state_code="US_XX", ) self.assertEqual(result, expected_result)
def testParseStatePerson_WithSurnameAndGivenNames_UsesFullNameAsJson(self): # Arrange metadata = IngestMetadata.new_with_defaults() ingest_person = ingest_info_pb2.StatePerson( surname='UNESCAPED,SURNAME"WITH-CHARS"', given_names='GIVEN_NAMES', middle_names='MIDDLE_NAMES') # Act state_person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_full_name = \ '{{"given_names": "{}", "middle_names": "{}", "surname": "{}"}}'\ .format('GIVEN_NAMES', 'MIDDLE_NAMES', 'UNESCAPED,SURNAME\\"WITH-CHARS\\"') expected_result = entities.StatePerson.new_with_defaults( full_name=expected_full_name) self.assertEqual(result, expected_result)