예제 #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_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'