예제 #1
0
    def test_has_active_booking(self):
        person_inactive_booking = county_entities.Person.new_with_defaults(
            bookings=[
                county_entities.Booking.new_with_defaults(
                    booking_id='1', custody_status=CustodyStatus.RELEASED)
            ])
        person_active_booking = county_entities.Person.new_with_defaults(
            bookings=[
                county_entities.Booking.new_with_defaults(booking_id='2')
            ])

        self.assertFalse(has_active_booking(person_inactive_booking))
        self.assertTrue(has_active_booking(person_active_booking))
예제 #2
0
    def _convert_person(self, ingest_person) -> entities.Person:
        """Converts an ingest_info proto Person to a persistence entity."""
        person_builder = entities.Person.builder()

        person.copy_fields_to_builder(person_builder, ingest_person,
                                      self.metadata)

        converted_bookings = [
            self._convert_booking(self.bookings[booking_id])
            for booking_id in ingest_person.booking_ids
        ]

        if len([b for b in converted_bookings if not b.release_date]) > 1:
            raise ValueError(
                f"Multiple open bookings for person with person_id"
                f" [{ingest_person}]")

        # If no bookings were ingested, create booking to house inferred data.
        if not converted_bookings:
            inferred_booking = self._convert_booking(ingest_info_pb2.Booking())
            converted_bookings = [inferred_booking]

        person_builder.bookings = converted_bookings

        converted_person = person_builder.build()

        # Scrub PII if the person either has an external id or has no open
        # bookings.
        if converted_person.external_id \
                or not persistence_utils.has_active_booking(converted_person):
            persistence_utils.remove_pii_for_person(converted_person)

        return converted_person