Пример #1
0
 def test_same_record_returned_in_two_fetches(self, mocker):
     """
     Given:
         - Same record returned in 2 fetch queries
     When:
         - Fetching incidents (2 iterations)
     Then:
         Check that the new next fetch is greater than last_fetch on both calls.
         Check the wanted next_fetch is equals to the date in the incident in both calls.
         Assert occurred time
     """
     client = Client(BASE_URL, '', '', '', '')
     mocker.patch.object(
         client, 'search_records', side_effect=[
             ([INCIDENT_RECORD_US_TZ], {}),
             ([INCIDENT_RECORD_US_TZ], {})
         ]
     )
     params = {
         'applicationId': '75',
         'applicationDateField': 'created date'
     }
     field_time_id = '53075'
     first_fetch = parser('2021-02-24T08:45:55Z')
     incidents, first_next_fetch = fetch_incidents(client, params, first_fetch, field_time_id)
     assert first_fetch < first_next_fetch
     assert first_next_fetch == datetime(2021, 2, 25, 8, 45, 55, 977000, tzinfo=timezone.utc)
     assert incidents[0]['occurred'] == '2021-02-25T08:45:55.977Z'
     # first_next_fetch_dt simulates the set to last_run done in fetch-incidents
     first_next_fetch_dt = parser(first_next_fetch.strftime(OCCURRED_FORMAT))
     incidents, second_next_fetch = fetch_incidents(client, params, first_next_fetch_dt, field_time_id)
     assert first_next_fetch == datetime(2021, 2, 25, 8, 45, 55, 977000, tzinfo=timezone.utc)
     assert not incidents
Пример #2
0
    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.'
Пример #3
0
    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
Пример #4
0
    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'
Пример #5
0
    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
Пример #6
0
    def test_two_fetches(self, mocker):
        """
        Given:
            2 incident with date/time reported
            running two fetches.
        When:
            Fetching incidents

        Then:
            Check that the new next fetch is greater than last_fetch on both calls.
            Check the wanted next_fetch is equals to the date in the incident in both calls.
            Assert occurred time
        """
        client = Client(BASE_URL, '', '', '', '')
        params = {
            'applicationId': '75',
            'applicationDateField': 'Date/Time Reported'
        }
        record1, record2 = copy.deepcopy(INCIDENT_RECORD), copy.deepcopy(
            INCIDENT_RECORD)
        record1['record']['Date/Time Reported'] = '18/03/2020 10:30 AM'
        record2['record']['Date/Time Reported'] = '18/03/2020 03:30 PM'
        record1['raw']['Field'][1][
            '@xmlConvertedValue'] = '2020-03-18T10:30:00.000Z'
        record2['raw']['Field'][1][
            '@xmlConvertedValue'] = '2020-03-18T15:30:00.000Z'
        last_fetch = parser('2020-18-03T09:00:00Z')
        mocker.patch.object(client,
                            'search_records',
                            side_effect=[([record1], {}), ([record2], {})])
        incidents, next_fetch = fetch_incidents(client, params, last_fetch,
                                                '305')
        assert last_fetch < next_fetch
        assert next_fetch == datetime(2020, 3, 18, 10, 30, tzinfo=timezone.utc)
        assert incidents[0]['occurred'] == '2020-03-18T10:30:00.000Z'
        incidents, next_fetch = fetch_incidents(client, params, next_fetch,
                                                '305')
        assert last_fetch < next_fetch
        assert next_fetch == datetime(2020, 3, 18, 15, 30, tzinfo=timezone.utc)
        assert incidents[0]['occurred'] == '2020-03-18T15:30:00.000Z'