def test_query_on_a_stat_holiday(monkeypatch): iso = "%Y-%m-%d" first_date = vips.next_business_date(datetime.strptime("2020-12-28", iso)) end_date = vips.next_business_date(datetime.strptime("2020-12-28", iso)) from python.ingestor.config import Config as IngestorConfig def mock_schedule_get(*args) -> tuple: return True, dict({"time_slots": [], "number_review_days_offered": 0}) monkeypatch.setattr(vips, "schedule_get", mock_schedule_get) is_success, args = middleware.query_for_additional_review_times( correlation_id="abcde", number_review_days_offered=1, presentation_type="ORAL", max_review_date=end_date, min_review_date=first_date, config=IngestorConfig, vips_data={"noticeTypeCd": "IRP"}, time_slots=list([])) logging.info(json.dumps(args.get('time_slots'))) assert args['number_review_days_offered'] == 1 assert args['time_slots'] == []
def test_query_for_additional_review_times(min_review_date, max_review_date, initial_days_offered, expected_days, expected_time_slots, monkeypatch): iso = "%Y-%m-%d" first_date = vips.next_business_date( datetime.strptime(max_review_date, iso)) end_date = vips.next_business_date(datetime.strptime(min_review_date, iso)) class MockConfig: MIN_REVIEW_DAYS_OFFERED = 3 ADDITIONAL_DAYS_TO_QUERY = 4 def mock_schedule_get(*args) -> tuple: return True, dict({ "time_slots": [{ "reviewStartDtm": end_date.strftime(iso) + " 09:00:00 -08:00", "reviewEndDtm": end_date.strftime(iso) + " 09:30:00 -08:00", }], "number_review_days_offered": 1 }) monkeypatch.setattr(vips, "schedule_get", mock_schedule_get) is_success, args = middleware.query_for_additional_review_times( correlation_id="abcde", number_review_days_offered=initial_days_offered, presentation_type="ORAL", max_review_date=end_date, min_review_date=first_date, config=MockConfig, vips_data={"noticeTypeCd": "IRP"}, time_slots=list([{ "reviewStartDtm": first_date.strftime(iso) + " 11:00:00 -08:00", "reviewEndDtm": first_date.strftime(iso) + " 11:30:00 -08:00", }, { "reviewStartDtm": first_date.strftime(iso) + " 10:00:00 -08:00", "reviewEndDtm": first_date.strftime(iso) + " 10:30:00 -08:00", }])) logging.info(json.dumps(args.get('time_slots'))) assert args['number_review_days_offered'] == expected_days assert len(args['time_slots']) == expected_time_slots for slot in args.get('time_slots'): assert isinstance(slot, dict) assert "reviewStartDtm" in slot assert "reviewEndDtm" in slot
def query_for_additional_review_times(**args) -> tuple: query_count = 0 correlation_id = args.get('correlation_id') config = args.get('config') number_review_days_offered = args.get('number_review_days_offered') vips_data = args.get('vips_data') time_slots = args.get('time_slots') last_date = args.get('max_review_date') review_type = args.get('presentation_type') while number_review_days_offered < config.MIN_REVIEW_DAYS_OFFERED and query_count <= config.ADDITIONAL_DAYS_TO_QUERY: logging.info( "Querying for additional review dates. Number offered so far: {}". format(number_review_days_offered)) datetime_to_query = vips.next_business_date(last_date) query_count += 1 is_successful, data = vips.schedule_get(vips_data['noticeTypeCd'], review_type, datetime_to_query, datetime_to_query, config, correlation_id) if not is_successful: return False, args number_review_days_offered += 1 time_slots.append(data['time_slots']) args['time_slots'] = time_slots args['number_review_days_offered'] = number_review_days_offered return True, args
def test_next_business_date(date_under_test, next_business_date): iso = "%Y-%m-%d" date_time = datetime.strptime(date_under_test, iso) expected = datetime.strptime(next_business_date, iso) assert vips.next_business_date(date_time) == expected