def test_readPeopleWithOpenBookingsBeforeDate(self): # Arrange person = Person(person_id=8, region=_REGION, jurisdiction_id=_JURISDICTION_ID) person_resolved_booking = Person(person_id=9, region=_REGION, jurisdiction_id=_JURISDICTION_ID) person_most_recent_scrape = Person(person_id=10, region=_REGION, jurisdiction_id=_JURISDICTION_ID) person_wrong_region = Person(person_id=11, region=_REGION_ANOTHER, jurisdiction_id=_JURISDICTION_ID) release_date = datetime.date(2018, 7, 20) most_recent_scrape_date = datetime.datetime(2018, 6, 20) date_in_past = most_recent_scrape_date - datetime.timedelta(days=1) first_seen_time = most_recent_scrape_date - datetime.timedelta(days=3) # Bookings that should be returned open_booking_before_last_scrape = Booking( person_id=person.person_id, custody_status=CustodyStatus.IN_CUSTODY.value, first_seen_time=first_seen_time, last_seen_time=date_in_past) # Bookings that should not be returned open_booking_incorrect_region = Booking( person_id=person_wrong_region.person_id, custody_status=CustodyStatus.IN_CUSTODY.value, first_seen_time=first_seen_time, last_seen_time=date_in_past) open_booking_most_recent_scrape = Booking( person_id=person_most_recent_scrape.person_id, custody_status=CustodyStatus.IN_CUSTODY.value, first_seen_time=first_seen_time, last_seen_time=most_recent_scrape_date) resolved_booking = Booking( person_id=person_resolved_booking.person_id, custody_status=CustodyStatus.RELEASED.value, release_date=release_date, first_seen_time=first_seen_time, last_seen_time=date_in_past) session = SessionFactory.for_schema_base(JailsBase) session.add(person) session.add(person_resolved_booking) session.add(person_most_recent_scrape) session.add(person_wrong_region) session.add(open_booking_before_last_scrape) session.add(open_booking_incorrect_region) session.add(open_booking_most_recent_scrape) session.add(resolved_booking) session.commit() # Act people = dao.read_people_with_open_bookings_scraped_before_time( session, person.region, most_recent_scrape_date) # Assert self.assertEqual(people, [converter.convert_schema_object_to_entity(person)])
def test_readPeopleWithOpenBookings(self): admission_date = datetime.datetime(2018, 6, 20) release_date = datetime.date(2018, 7, 20) open_booking = Booking( custody_status=CustodyStatus.IN_CUSTODY.value, admission_date=admission_date, first_seen_time=admission_date, last_seen_time=admission_date, ) closed_booking = Booking( custody_status=CustodyStatus.RELEASED.value, admission_date=admission_date, release_date=release_date, first_seen_time=admission_date, last_seen_time=admission_date, ) person_no_match = Person( person_id=1, region=_REGION, jurisdiction_id=_JURISDICTION_ID, bookings=[deepcopy(open_booking)], ) person_match_full_name = Person( person_id=2, region=_REGION, jurisdiction_id=_JURISDICTION_ID, bookings=[deepcopy(open_booking)], full_name=_FULL_NAME, ) person_no_open_bookings = Person( person_id=6, region=_REGION, jurisdiction_id=_JURISDICTION_ID, full_name=_FULL_NAME, bookings=[closed_booking], ) with SessionFactory.using_database(self.database_key, autocommit=False) as session: session.add(person_no_match) session.add(person_no_open_bookings) session.add(person_match_full_name) session.commit() info = IngestInfo() info.create_person(full_name=_FULL_NAME, person_id=_EXTERNAL_ID) people = dao.read_people_with_open_bookings( session, _REGION, info.people) expected_people = [ converter.convert_schema_object_to_entity(p) for p in [person_match_full_name] ] self.assertCountEqual(people, expected_people)
def test_readPeopleByExternalId(self): admission_date = datetime.datetime(2018, 6, 20) release_date = datetime.date(2018, 7, 20) closed_booking = Booking( custody_status=CustodyStatus.IN_CUSTODY.value, admission_date=admission_date, release_date=release_date, first_seen_time=admission_date, last_seen_time=admission_date) person_no_match = Person(person_id=1, region=_REGION, jurisdiction_id=_JURISDICTION_ID, bookings=[deepcopy(closed_booking)]) person_match_external_id = Person(person_id=2, region=_REGION, jurisdiction_id=_JURISDICTION_ID, bookings=[closed_booking], external_id=_EXTERNAL_ID) session = SessionFactory.for_schema_base(JailsBase) session.add(person_no_match) session.add(person_match_external_id) session.commit() ingested_person = entities.Person.new_with_defaults( external_id=_EXTERNAL_ID) people = dao.read_people_by_external_ids(session, _REGION, [ingested_person]) expected_people = [ converter.convert_schema_object_to_entity(person_match_external_id)] self.assertCountEqual(people, expected_people)