def test_processed_orders_request_body_data(patch_incremental_base_class, page_number): stream_slice = {"FromDate": "FromDateValue", "ToDate": "ToDateValue"} next_page_token = {"PageNumber": page_number} stream = ProcessedOrders() request_body_data = stream.request_body_data(None, stream_slice, next_page_token) data = json.loads(request_body_data["request"]) assert stream_slice.items() < data.items() assert next_page_token.items() < data.items()
def test_processed_orders_stream_slices(patch_incremental_base_class, now, stream_state, slice_count, expected_from_date, expected_to_date): start_date = date(2050, 1, 1) pendulum.set_test_now(pendulum.parse(now if now else start_date)) stream = ProcessedOrders(start_date=start_date) stream_slices = list(stream.stream_slices(stream_state)) assert len(stream_slices) == slice_count assert stream_slices[0]["FromDate"] == expected_from_date assert stream_slices[-1]["ToDate"] == expected_to_date
def test_processed_orders_parse_response(patch_incremental_base_class, requests_mock): requests_mock.get("https://dummy", json={"ProcessedOrders": {"Data": [1, 2, 3]}}) good_response = requests.get("https://dummy") requests_mock.get("https://dummy", json={"ProcessedOrders": {"OtherData": [1, 2, 3]}}) bad_response = requests.get("https://dummy") stream = ProcessedOrders() result = stream.parse_response(good_response) assert list(result) == [1, 2, 3] with pytest.raises(KeyError, match="'Data'"): list(stream.parse_response(bad_response))
def test_processed_orders_paged_result(patch_incremental_base_class, requests_mock): requests_mock.get("https://dummy", json={"ProcessedOrders": "the_orders"}) good_response = requests.get("https://dummy") requests_mock.get("https://dummy", json={"OtherData": "the_data"}) bad_response = requests.get("https://dummy") stream = ProcessedOrders() result = stream.paged_result(good_response) assert result == "the_orders" with pytest.raises(KeyError, match="'ProcessedOrders'"): stream.paged_result(bad_response)
def test_processed_orders_request_cache(patch_incremental_base_class, mocker): remove = MagicMock() use_cassette = MagicMock() mocker.patch.object(os, "remove", remove) mocker.patch.object(vcr, "use_cassette", use_cassette) stream = ProcessedOrders() stream.request_cache() remove.assert_called_with(stream.cache_filename) use_cassette.assert_called_with( stream.cache_filename, record_mode="new_episodes", serializer="yaml", match_on=["method", "scheme", "host", "port", "path", "query", "body"], )