def test_person_match_external_id(self): db_person = entities.Person.new_with_defaults(external_id=_EXTERNAL_ID) ingested_person = entities.Person.new_with_defaults( external_id=_EXTERNAL_ID) self.assertTrue( county_matching_utils.is_person_match( db_entity=db_person, ingested_entity=ingested_person)) ingested_person.external_id = _EXTERNAL_ID_OTHER self.assertFalse( county_matching_utils.is_person_match( db_entity=db_person, ingested_entity=ingested_person))
def test_person_match_name_and_birthdate(self): db_person = entities.Person.new_with_defaults( full_name=_FULL_NAME, birthdate=_DATE, ) ingested_person = entities.Person.new_with_defaults( full_name=_FULL_NAME, birthdate=_DATE ) self.assertTrue(county_matching_utils.is_person_match( db_entity=db_person, ingested_entity=ingested_person)) ingested_person.birthdate = _DATE_OTHER self.assertFalse(county_matching_utils.is_person_match( db_entity=db_person, ingested_entity=ingested_person))
def test_matchPeople_twoMatchingPeople_PicksMostSimilar(self): # Arrange schema_person = schema.Person( person_id=_PERSON_ID, external_id=_EXTERNAL_ID, jurisdiction_id=_JURISDICTION_ID, full_name=_FULL_NAME, birthdate=_DATE, region=_REGION, gender=Gender.MALE.value, ) schema_person_mismatch = copy.deepcopy(schema_person) schema_person_mismatch.person_id = _PERSON_ID_ANOTHER schema_person_mismatch.gender = Gender.FEMALE.value session = SessionFactory.for_schema_base(JailsBase) session.add(schema_person) session.add(schema_person_mismatch) session.commit() ingested_person = attr.evolve( converter.convert_schema_object_to_entity(schema_person), person_id=None ) expected_person = attr.evolve( ingested_person, person_id=schema_person.person_id ) # Act matched_entities = entity_matching.match(session, _REGION, [ingested_person]) # Assert both schema objects are matches, but we select the most # similar one. self.assertTrue( county_matching_utils.is_person_match( db_entity=schema_person, ingested_entity=ingested_person ) ) self.assertTrue( county_matching_utils.is_person_match( db_entity=schema_person_mismatch, ingested_entity=ingested_person ) ) self.assertEqual(matched_entities.error_count, 0) self.assertEqual(len(matched_entities.orphaned_entities), 0) self.assertEqual(ingested_person, expected_person)
def test_person_match_name(self): db_person = entities.Person.new_with_defaults( full_name=_FULL_NAME, resident_of_region=True) ingested_person = entities.Person.new_with_defaults( full_name=_FULL_NAME, resident_of_region=False) self.assertTrue(county_matching_utils.is_person_match( db_entity=db_person, ingested_entity=ingested_person))
def test_person_match_name_and_inferred_birthdate(self): date_plus_one_year = _DATE + relativedelta(years=1) date_plus_two_years = _DATE + relativedelta(years=2) db_person = entities.Person.new_with_defaults( full_name=_FULL_NAME, birthdate=_DATE, birthdate_inferred_from_age=True ) ingested_person = entities.Person.new_with_defaults( full_name=_FULL_NAME, birthdate=date_plus_one_year, birthdate_inferred_from_age=True ) self.assertTrue(county_matching_utils.is_person_match( db_entity=db_person, ingested_entity=ingested_person)) ingested_person.birthdate = date_plus_two_years self.assertFalse(county_matching_utils.is_person_match( db_entity=db_person, ingested_entity=ingested_person))