Skip to content

Commit

Permalink
unit test sendgrid messages stream (#15331)
Browse files Browse the repository at this point in the history
* unit test sendgrid messages stream

* reset

* Update airbyte-integrations/connectors/source-sendgrid/unit_tests/unit_test.py

Co-authored-by: Augustin <augustin.lafanechere@gmail.com>

Co-authored-by: Augustin <augustin.lafanechere@gmail.com>
  • Loading branch information
girarda and alafanechere authored Aug 11, 2022
1 parent 158bdcf commit 2b15cd3
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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
== "query=last_event_time%20BETWEEN%20TIMESTAMP%20%222019-05-20T06%3A30%3A00Z%22%20AND%20TIMESTAMP%20%222021-12-31T16%3A00%3A00Z%22&limit=1000"
)

0 comments on commit 2b15cd3

Please sign in to comment.