Exemple #1
0
 def test_request_params(self):
     stream = Events(pendulum.now().isoformat())
     now = pendulum.now().subtract(hours=6)
     slice = {
         "start": now.strftime(stream.date_template),
         "end": stream._get_end_date(now).strftime(stream.date_template)
     }
     assert slice == stream.request_params(slice)
Exemple #2
0
 def test_stream_slices(self):
     stream = Events(pendulum.now().isoformat())
     now = pendulum.now()
     expected = [{
         "start":
         now.strftime(stream.date_template),
         "end":
         stream._get_end_date(now).add(**stream.time_interval).subtract(
             hours=1).strftime(stream.date_template),
     }]
     assert expected == stream.stream_slices()
Exemple #3
0
 def test_get_date_time_items_from_schema(self):
     stream = Events(pendulum.now().isoformat())
     expected = [
         "server_received_time",
         "event_time",
         "processed_time",
         "user_creation_time",
         "client_upload_time",
         "server_upload_time",
         "client_event_time",
     ]
     result = stream._get_date_time_items_from_schema()
     assert result == expected
Exemple #4
0
def test_incremental_http_error_handler(mocker):
    stream = Events(start_date="2021-01-01T00:00:00Z")
    stream_slice = stream.stream_slices()[0]

    mock_response = MockRequest(404)
    send_request_mocker = mocker.patch.object(stream, "_send_request", side_effect=requests.HTTPError(**{"response": mock_response}))
    with pytest.raises(StopIteration):
        result = next(stream.read_records(sync_mode=SyncMode.full_refresh, stream_slice=stream_slice))
        assert result == []

    mock_response = MockRequest(403)
    send_request_mocker.side_effect = requests.HTTPError(**{"response": mock_response})
    with pytest.raises(requests.exceptions.HTTPError):
        next(stream.read_records(sync_mode=SyncMode.full_refresh, stream_slice=stream_slice))

    mock_response = MockRequest(400)
    send_request_mocker.side_effect = requests.HTTPError(**{"response": mock_response})
    with pytest.raises(StopIteration):
        result = next(stream.read_records(sync_mode=SyncMode.full_refresh, stream_slice=stream_slice))
        assert result == []

    mock_response = MockRequest(504)
    send_request_mocker.side_effect = requests.HTTPError(**{"response": mock_response})
    with pytest.raises(StopIteration):
        result = next(stream.read_records(sync_mode=SyncMode.full_refresh, stream_slice=stream_slice))
        assert result == []
Exemple #5
0
 def test_date_time_to_rfc3339(self, record, expected):
     stream = Events(pendulum.now().isoformat())
     result = stream._date_time_to_rfc3339(record)
     assert result == expected
Exemple #6
0
 def test_get_updated_state(self):
     stream = Events(pendulum.now().isoformat())
     current_state = {"event_time": ""}
     latest_record = {"event_time": "2021-05-27 11:59:53.710000"}
     result = stream.get_updated_state(current_state, latest_record)
     assert result == latest_record
Exemple #7
0
 def test_parse_zip(self):
     stream = Events(pendulum.now().isoformat())
     expected = [{"id": 123}]
     result = list(
         stream._parse_zip_file("unit_tests/api_data/zipped.json"))
     assert expected == result