def test_readPersons_unexpectedRoot_raises(self): ingested_supervision_sentence = \ schema.StateSupervisionSentence( external_id=_EXTERNAL_ID) ingested_sentence_group = schema.StateSentenceGroup( supervision_sentences=[ingested_supervision_sentence]) ingested_person = schema.StatePerson( sentence_groups=[ingested_sentence_group]) with pytest.raises(ValueError): session = SessionFactory.for_schema_base(StateBase) read_persons_by_root_entity_cls( session, 'us_nd', [ingested_person], allowed_root_entity_classes=[schema.StateSentenceGroup])
def test_readPersons_unexpectedRoot_raises(self) -> None: ingested_supervision_sentence = schema.StateSupervisionSentence( external_id=_EXTERNAL_ID) ingested_sentence_group = schema.StateSentenceGroup( supervision_sentences=[ingested_supervision_sentence]) ingested_person = schema.StatePerson( sentence_groups=[ingested_sentence_group]) with pytest.raises(ValueError): with SessionFactory.using_database(self.database_key, autocommit=False) as session: read_persons_by_root_entity_cls( session, "us_nd", [ingested_person], allowed_root_entity_classes=[schema.StateSentenceGroup], )
def test_readPersonsByRootEntityCls(self) -> None: schema_person_with_root_entity = schema.StatePerson( person_id=1, state_code=_STATE_CODE) schema_sentence_group = schema.StateSentenceGroup( sentence_group_id=_ID, external_id=_EXTERNAL_ID, status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value, state_code=_STATE_CODE, ) schema_sentence_group_2 = schema.StateSentenceGroup( sentence_group_id=_ID_2, external_id=_EXTERNAL_ID_2, status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value, state_code=_STATE_CODE, ) schema_person_with_root_entity.sentence_groups = [ schema_sentence_group, schema_sentence_group_2, ] placeholder_schema_person = schema.StatePerson(person_id=_ID_2, state_code=_STATE_CODE) schema_person_other_state = schema.StatePerson(person_id=_ID_3, state_code=_STATE_CODE) schema_external_id_other_state = schema.StatePersonExternalId( person_external_id_id=_ID_2, external_id=_ID, id_type=_ID_TYPE, state_code=_STATE_CODE, ) schema_person_other_state.external_ids = [ schema_external_id_other_state ] with SessionFactory.using_database(self.database_key, autocommit=False) as session: session.add(schema_person_with_root_entity) session.add(placeholder_schema_person) session.add(schema_person_other_state) session.commit() ingested_sentence_group = schema.StateSentenceGroup( state_code=_STATE_CODE, external_id=_EXTERNAL_ID) ingested_person = schema.StatePerson( sentence_groups=[ingested_sentence_group]) expected_people = [ schema_person_with_root_entity, placeholder_schema_person, ] people = read_persons_by_root_entity_cls( session, _STATE_CODE, [ingested_person], allowed_root_entity_classes=[schema.StateSentenceGroup], ) self.assert_schema_object_lists_equal(expected_people, people)
def read_potential_match_db_persons( self, session: Session, ingested_persons: List[schema.StatePerson] ) -> List[schema.StatePerson]: """Reads and returns all persons from the DB that are needed for entity matching in this state, given the |ingested_persons|. """ allowed_root_entity_classes: List[Type[DatabaseEntity]] = [schema.StatePerson] db_persons = read_persons_by_root_entity_cls( session, self.region_code, ingested_persons, allowed_root_entity_classes) return db_persons
def test_readPersonsByRootEntityCls(self): schema_person_with_root_entity = schema.StatePerson( person_id=1, state_code=_STATE_CODE) schema_sentence_group = schema.StateSentenceGroup( sentence_group_id=_ID, external_id=_EXTERNAL_ID, status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value, state_code='US_ND') schema_sentence_group_2 = schema.StateSentenceGroup( sentence_group_id=_ID_2, external_id=_EXTERNAL_ID_2, status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value, state_code='US_ND') schema_person_with_root_entity.sentence_groups = [ schema_sentence_group, schema_sentence_group_2 ] placeholder_schema_person = schema.StatePerson(person_id=_ID_2, state_code=_STATE_CODE) schema_person_other_state = schema.StatePerson(person_id=_ID_3, state_code=_STATE_CODE) schema_external_id_other_state = schema.StatePersonExternalId( person_external_id_id=_ID_2, external_id=_ID, id_type=_ID_TYPE, state_code=_STATE_CODE) schema_person_other_state.external_ids = [ schema_external_id_other_state ] session = SessionFactory.for_schema_base(StateBase) session.add(schema_person_with_root_entity) session.add(placeholder_schema_person) session.add(schema_person_other_state) session.commit() ingested_sentence_group = schema.StateSentenceGroup( state_code='us_nd', external_id=_EXTERNAL_ID) ingested_person = schema.StatePerson( sentence_groups=[ingested_sentence_group]) expected_people = [ schema_person_with_root_entity, placeholder_schema_person ] people = read_persons_by_root_entity_cls( session, 'us_nd', [ingested_person], allowed_root_entity_classes=[schema.StateSentenceGroup]) self.assert_schema_object_lists_equal(expected_people, people)