-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
unit test sendgrid messages stream #15331
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,17 @@ | |
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
import unittest | ||
from unittest.mock import MagicMock | ||
|
||
import pendulum | ||
import pytest | ||
import requests | ||
from airbyte_cdk.logger import AirbyteLogger | ||
from source_sendgrid.source import SourceSendgrid | ||
from source_sendgrid.streams import SendgridStream | ||
from source_sendgrid.streams import Messages, SendgridStream | ||
|
||
FAKE_NOW = pendulum.DateTime(2022, 1, 1, tzinfo=pendulum.timezone("utc")) | ||
|
||
|
||
@pytest.fixture(name="sendgrid_stream") | ||
|
@@ -19,6 +23,13 @@ def sendgrid_stream_fixture(mocker) -> SendgridStream: | |
return SendgridStream() # type: ignore | ||
|
||
|
||
@pytest.fixture() | ||
def mock_pendulum_now(monkeypatch): | ||
pendulum_mock = unittest.mock.MagicMock(wraps=pendulum.now) | ||
pendulum_mock.return_value = FAKE_NOW | ||
monkeypatch.setattr(pendulum, "now", pendulum_mock) | ||
|
||
|
||
def test_parse_response_gracefully_handles_nulls(mocker, sendgrid_stream: SendgridStream): | ||
response = requests.Response() | ||
mocker.patch.object(response, "json", return_value=None) | ||
|
@@ -30,3 +41,14 @@ def test_source_wrong_credentials(): | |
source = SourceSendgrid() | ||
status, error = source.check_connection(logger=AirbyteLogger(), config={"apikey": "wrong.api.key123"}) | ||
assert not status | ||
|
||
|
||
def test_messages_stream_request_params(mock_pendulum_now): | ||
start_time = 1558359837 | ||
stream = Messages(start_time) | ||
state = {"last_event_time": 1558359000} | ||
request_params = stream.request_params(state) | ||
assert ( | ||
request_params | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alafanechere do you know why this is returning a string instead of a Mapping[str, Any]? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I don't see obvious reason, the URL formatting could be a bit tricky due to the API query format, but I don't see any good reason to not use a mapping. |
||
== "query=last_event_time%20BETWEEN%20TIMESTAMP%20%222019-05-20T06%3A30%3A00Z%22%20AND%20TIMESTAMP%20%222021-12-31T16%3A00%3A00Z%22&limit=1000" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to use FreezeGun for this kind of mock :D https://github.com/spulec/freezegun