def testParsePerson_TakesLastZipCodeMatch(self): # Arrange metadata = IngestMetadata.new_with_defaults(region='us_ky_allen') # 5-digit address could be mistaken for a zip code ingest_person = ingest_info_pb2.Person( place_of_residence='12345 Main 42164') # Act person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.Person.new_with_defaults( resident_of_region=True, residency_status=ResidencyStatus.PERMANENT, region='us_ky_allen') self.assertEqual(result, expected_result)
def testParsePerson_NotResidentOfCounty(self): # Arrange metadata = IngestMetadata.new_with_defaults(region="us_ky_allen") # 40601 is in Frankfort ingest_person = ingest_info_pb2.Person(place_of_residence="123 Main 40601") # Act person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.Person.new_with_defaults( resident_of_region=False, residency_status=ResidencyStatus.PERMANENT, region="us_ky_allen", ) self.assertEqual(result, expected_result)
def testParsePerson_NotResidentOfState(self): # Arrange metadata = IngestMetadata.new_with_defaults(region='us_ky') # 10011 is in New York ingest_person = ingest_info_pb2.Person( place_of_residence='123 Main 10011') # Act person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.Person.new_with_defaults( resident_of_region=False, residency_status=ResidencyStatus.PERMANENT, region='us_ky') self.assertEqual(result, expected_result)
def testParsePerson_ResidentOfCounty(self): # Arrange metadata = IngestMetadata.new_with_defaults(region='us_ky_allen') # 42164 is in Allen ingest_person = ingest_info_pb2.Person( place_of_residence='123 Main 42164') # Act person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.Person.new_with_defaults( resident_of_region=True, residency_status=ResidencyStatus.PERMANENT, region='us_ky_allen') self.assertEqual(result, expected_result)
def testParsePerson_NoiseInPlaceOfResidence_ParsesResidencyStatus(self): # Arrange metadata = FakeIngestMetadata.for_county( region="us_ky_allen", jurisdiction_id="JURISDICTION_ID") ingest_person = ingest_info_pb2.Person( place_of_residence="transient moves around") # Act person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.Person.new_with_defaults( residency_status=ResidencyStatus.TRANSIENT, region="us_ky_allen", jurisdiction_id="JURISDICTION_ID", ) self.assertEqual(result, expected_result)
def testParsePerson_ResidenceAndStatusCombined(self): # Arrange metadata = FakeIngestMetadata.for_county( region="us_ky_allen", jurisdiction_id="JURISDICTION_ID") ingest_person = ingest_info_pb2.Person( place_of_residence="42164 homeless") # Act person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.Person.new_with_defaults( resident_of_region=True, residency_status=ResidencyStatus.HOMELESS, region="us_ky_allen", jurisdiction_id="JURISDICTION_ID", ) self.assertEqual(result, expected_result)
def testParsePerson_InfersBirthdateFromAge(self, mock_datetime): # Arrange mock_datetime.now.return_value = _NOW metadata = FakeIngestMetadata.for_county( region="REGION", jurisdiction_id="JURISDICTION_ID") ingest_person = ingest_info_pb2.Person(age="27") # Act person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.Person.new_with_defaults( region="REGION", jurisdiction_id="JURISDICTION_ID", birthdate=datetime(year=_NOW.year - 27, month=1, day=1).date(), birthdate_inferred_from_age=True, ) self.assertEqual(result, expected_result)
def testParsePerson_NotResidentOfState(self): # Arrange metadata = FakeIngestMetadata.for_county( region="us_ky", jurisdiction_id="JURISDICTION_ID") # 10011 is in New York ingest_person = ingest_info_pb2.Person( place_of_residence="123 Main 10011") # Act person.copy_fields_to_builder(self.subject, ingest_person, metadata) result = self.subject.build() # Assert expected_result = entities.Person.new_with_defaults( resident_of_region=False, residency_status=ResidencyStatus.PERMANENT, region="us_ky", jurisdiction_id="JURISDICTION_ID", ) self.assertEqual(result, expected_result)
def testParsePerson_WithSurnameAndGivenNames_UsesFullNameAsJson(self): # Arrange metadata = IngestMetadata.new_with_defaults() ingest_person = ingest_info_pb2.Person( surname='UNESCAPED,SURNAME"WITH-CHARS"', given_names='GIVEN_NAMES', middle_names='MIDDLE_NAMES') # Act 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.Person.new_with_defaults( full_name=expected_full_name) self.assertEqual(result, expected_result)