Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Marketo: Increase test coverage, update QL #33075

Merged
merged 8 commits into from
Jan 11, 2024
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
data:
ab_internal:
ql: 400
ql: 200
sl: 200
allowedHosts:
hosts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import tracemalloc
from functools import partial
from unittest.mock import ANY, Mock, patch
from unittest.mock import ANY, MagicMock, Mock, patch

import pendulum
import pytest
Expand All @@ -21,6 +21,7 @@
MarketoExportCreate,
MarketoStream,
Programs,
Segmentations,
SourceMarketo,
)

Expand Down Expand Up @@ -317,10 +318,40 @@ def test_check_connection(config, requests_mock, status_code, response, is_conne
("2020-08-01", "%Y-%m-%dT%H:%M:%SZ%z", "2020-08-01"),
),
)
def test_normalize_datetime(config, input, format, expected_result):
def test_programs_normalize_datetime(config, input, format, expected_result):
stream = Programs(config)
assert stream.normalize_datetime(input, format) == expected_result

def test_programs_next_page_token(config):
mock_json = MagicMock()
mock_json.return_value = {"result": [{"test": 'testValue'}]}
mocked_response = MagicMock()
mocked_response.json = mock_json
stream = Programs(config)
result = stream.next_page_token(mocked_response)
assert result == {"offset": 201}

@pytest.mark.parametrize("input, stream_state, expected_result",[(
{"result": [{"id": "1", "createdAt": "2020-07-01T00:00:00Z+0000", "updatedAt": "2020-07-01T00:00:00Z+0000"}]},
{"updatedAt": "2020-06-01T00:00:00Z"},
[{"id": "1", "createdAt": "2020-07-01T00:00:00Z", "updatedAt": "2020-07-01T00:00:00Z"}],
)],
)
def test_programs_parse_response(mocker, config, input, stream_state, expected_result):
response = requests.Response()
mocker.patch.object(response, "json", return_value=input)
stream = Programs(config)
result = stream.parse_response(response, stream_state)
assert list(result) == expected_result

def test_segmentations_next_page_token(config):
mock_json = MagicMock()
mock_json.return_value = {"result": [{"test": 'testValue'}]}
mocked_response = MagicMock()
mocked_response.json = mock_json
stream = Segmentations(config)
result = stream.next_page_token(mocked_response)
assert result == {"offset": 201}

today = pendulum.now()
yesterday = pendulum.now().subtract(days=1).strftime("%Y-%m-%dT%H:%M:%SZ")
Expand Down
Loading