def test_fetch_got_exact_same_time(self, mocker): """ Given: last_fetch is in the exact same time as the incident When: Fetching incidents Then: Check that the next fetch is equals last fetch (no new incident) Check that no incidents brought back """ client = Client(BASE_URL, '', '', '', '') date_time_reported = '2018-03-01T10:02:00.000Z' params = { 'applicationId': '75', 'applicationDateField': 'Date/Time Reported' } record = copy.deepcopy(INCIDENT_RECORD) record['record']['Date/Time Reported'] = date_time_reported record['raw']['Field'][1]['@xmlConvertedValue'] = date_time_reported last_fetch = get_fetch_time( {'last_fetch': date_time_reported}, params.get('fetch_time', '3 days') ) mocker.patch.object(client, 'search_records', return_value=([record], {})) incidents, next_fetch = fetch_incidents(client, params, last_fetch, '305') assert last_fetch == next_fetch assert not incidents, 'Should not get new incidents.'
def test_fetch_time_change_with_offset(self, mocker): """ Given: offset of -120 (2 hours) When: Fetching incidents Then: Check that the new last fetch is equals to record reported time (no delta) and is after the last_fetch Assert occurred time """ client = Client(BASE_URL, '', '', '', '') record = copy.deepcopy(INCIDENT_RECORD) record['record']['Date/Time Reported'] = '03/04/2018 10:03 AM' params = { 'applicationId': '75', 'applicationDateField': 'Date/Time Reported', 'time_zone': -120, 'useEuropeanTime': 'true' } last_fetch = get_fetch_time({'last_fetch': '2018-03-24T10:03:00Z'}, params.get('fetch_time', '3 days'), 0) mocker.patch.object(client, 'search_records', return_value=([record], {})) incidents, next_fetch = fetch_incidents(client, params, last_fetch) assert last_fetch < next_fetch assert next_fetch == datetime(2018, 4, 3, 10, 3, tzinfo=timezone.utc) assert incidents[0]['occurred'] == '2018-04-03T12:03:00Z'
def test_fetch_time_change(self, mocker): """ Given: incident with date/time reported european time (day first) - True or false When: Fetching incidents Then: Check that the new next fetch is greater than last_fetch Check the wanted next_fetch is true Assert occurred time """ client = Client(BASE_URL, '', '', '', '') date_time_reported = '2018-04-03T10:03:00.000Z' params = { 'applicationId': '75', 'applicationDateField': 'Date/Time Reported' } record = copy.deepcopy(INCIDENT_RECORD) record['record']['Date/Time Reported'] = date_time_reported record['raw']['Field'][1]['@xmlConvertedValue'] = date_time_reported last_fetch = get_fetch_time( {'last_fetch': '2018-03-01T10:03:00Z'}, params.get('fetch_time', '3 days') ) mocker.patch.object(client, 'search_records', return_value=([record], {})) incidents, next_fetch = fetch_incidents(client, params, last_fetch, '305') assert last_fetch < next_fetch assert next_fetch == datetime(2018, 4, 3, 10, 3, tzinfo=timezone.utc) assert incidents[0]['occurred'] == date_time_reported
def test_fetch_times_with_impossible_date(self, mocker, date_time_reported: str, use_european_time: bool, occurred: str): """ Given: incident with date/time reported. The day/months can't be misplaced (29-11, 11-29) european time (day first) - True or false When: Fetching incidents Then: Check that the new next fetch is greater than last_fetch Check the wanted next_fetch is true Assert occurred time """ client = Client(BASE_URL, '', '', '', '') params = { 'applicationId': '75', 'applicationDateField': 'Date/Time Reported', 'time_zone': 0, 'useEuropeanTime': use_european_time } record = copy.deepcopy(INCIDENT_RECORD) record['record']['Date/Time Reported'] = date_time_reported last_fetch = get_fetch_time({'last_fetch': '2018-03-01T10:03:00Z'}, params.get('fetch_time', '3 days'), 0) mocker.patch.object(client, 'search_records', return_value=([record], {})) incidents, next_fetch = fetch_incidents(client, params, last_fetch) assert last_fetch < next_fetch assert next_fetch == datetime(2018, 11, 29, 10, 3, tzinfo=timezone.utc) assert incidents[0]['occurred'] == occurred