def test_nonnullFieldsEntityMatch_flatFieldsCompare(self) -> None:
        charge = schema.StateCharge(
            state_code=_STATE_CODE,
            ncic_code="1234",
            county_code=_COUNTY_CODE,
            status=ChargeStatus.PRESENT_WITHOUT_INFO,
        )
        charge_another = schema.StateCharge(
            state_code=_STATE_CODE,
            ncic_code="1234",
            status=ChargeStatus.PRESENT_WITHOUT_INFO,
        )

        # If one of the entities is merely missing a field, we still consider it a match
        self.assertTrue(
            nonnull_fields_entity_match(
                ingested_entity=EntityTree(entity=charge, ancestor_chain=[]),
                db_entity=EntityTree(entity=charge_another, ancestor_chain=[]),
            ))
        charge_another.county_code = _COUNTY_CODE_ANOTHER

        # If one of the entities has a different value, then it is not a match
        self.assertFalse(
            nonnull_fields_entity_match(
                ingested_entity=EntityTree(entity=charge, ancestor_chain=[]),
                db_entity=EntityTree(entity=charge_another, ancestor_chain=[]),
            ))
        charge_another.county_code = _COUNTY_CODE

        # All fields the same - this is a match
        self.assertTrue(
            nonnull_fields_entity_match(
                ingested_entity=EntityTree(entity=charge, ancestor_chain=[]),
                db_entity=EntityTree(entity=charge_another, ancestor_chain=[]),
            ))
 def test_isMatch_defaultCompareNoExternalIds(self):
     charge = schema.StateCharge()
     charge_another = schema.StateCharge()
     self.assertTrue(
         _is_match(ingested_entity=charge, db_entity=charge_another))
     charge.description = 'description'
     self.assertFalse(
         _is_match(ingested_entity=charge, db_entity=charge_another))
 def test_isMatch_defaultCompareExternalId(self):
     charge = schema.StateCharge(external_id=_EXTERNAL_ID,
                                 description='description')
     charge_another = schema.StateCharge(external_id=_EXTERNAL_ID,
                                         description='description_another')
     self.assertTrue(
         _is_match(ingested_entity=charge, db_entity=charge_another))
     charge.external_id = _EXTERNAL_ID_2
     self.assertFalse(
         _is_match(ingested_entity=charge, db_entity=charge_another))
 def test_nonnullFieldsEntityMatch_placeholder(self) -> None:
     charge = schema.StateCharge(state_code=_STATE_CODE,
                                 status=ChargeStatus.PRESENT_WITHOUT_INFO)
     charge_another = schema.StateCharge(
         state_code=_STATE_CODE, status=ChargeStatus.PRESENT_WITHOUT_INFO)
     self.assertFalse(
         nonnull_fields_entity_match(
             ingested_entity=EntityTree(entity=charge, ancestor_chain=[]),
             db_entity=EntityTree(entity=charge_another, ancestor_chain=[]),
         ))
Esempio n. 5
0
def generate_charge(person, **kwargs) -> schema.StateCharge:
    args = {
        "status": ChargeStatus.PRESENT_WITHOUT_INFO.value,
        "state_code": _STATE_CODE,
    }
    args.update(kwargs)
    return schema.StateCharge(person=person, **args)
 def test_nonnullFieldsEntityMatch_externalIdCompare(self) -> None:
     charge = schema.StateCharge(
         state_code=_STATE_CODE,
         status=ChargeStatus.PRESENT_WITHOUT_INFO,
         external_id=_EXTERNAL_ID,
     )
     charge_another = schema.StateCharge(
         state_code=_STATE_CODE, status=ChargeStatus.PRESENT_WITHOUT_INFO)
     self.assertFalse(
         nonnull_fields_entity_match(
             ingested_entity=EntityTree(entity=charge, ancestor_chain=[]),
             db_entity=EntityTree(entity=charge_another, ancestor_chain=[]),
         ))
     charge_another.external_id = _EXTERNAL_ID
     self.assertTrue(
         nonnull_fields_entity_match(
             ingested_entity=EntityTree(entity=charge, ancestor_chain=[]),
             db_entity=EntityTree(entity=charge_another, ancestor_chain=[]),
         ))
def generate_test_charge(person_id, charge_id, court_case=None, bond=None, state_code='us_ca') -> \
        state_schema.StateCharge:
    instance = state_schema.StateCharge(
        charge_id=charge_id,
        person_id=person_id,
        status=ChargeStatus.PENDING.value,
        state_code=state_code,
        court_case=court_case,
        bond=bond,
    )

    return instance
    def test_addChildToEntity_singular(self) -> None:
        charge = schema.StateCharge(
            state_code=_STATE_CODE,
            status=ChargeStatus.PRESENT_WITHOUT_INFO,
            charge_id=_ID,
        )
        court_case = schema.StateCourtCase(state_code=_STATE_CODE,
                                           court_case_id=_ID)

        add_child_to_entity(entity=charge,
                            child_field_name="court_case",
                            child_to_add=court_case)
        self.assertEqual(charge.court_case, court_case)
Esempio n. 9
0
def generate_test_charge(
    person_id: int,
    charge_id: int,
    court_case: Optional[state_schema.StateCourtCase] = None,
    bond: Optional[state_schema.StateBond] = None,
    state_code: str = "us_ca",
) -> state_schema.StateCharge:
    instance = state_schema.StateCharge(
        charge_id=charge_id,
        person_id=person_id,
        state_code=state_code,
        status=ChargeStatus.PRESENT_WITHOUT_INFO.value,
        court_case=court_case,
        bond=bond,
    )

    return instance