Skip to content

Commit

Permalink
fix: dict lookup and add Tests to verify things work properly (#40)
Browse files Browse the repository at this point in the history
* Fix dict lookup and add Tests to verify things work properly

* Don't need extra request

* Only need to sync the stream once to prove it works
  • Loading branch information
visch authored Apr 26, 2023
1 parent 766bb18 commit ce91173
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 43 deletions.
117 changes: 77 additions & 40 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fs-s3fs = { version = "^1.1.1", optional = true}

[tool.poetry.dev-dependencies]
pytest = "^7.3.1"
responses = "0.23.1"

[tool.poetry.extras]
s3 = ["fs-s3fs"]
Expand Down
6 changes: 3 additions & 3 deletions tap_messagebird/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ def validate_response(self, response: requests.Response) -> None:
f"{response.reason} for url: {response.url}"
)
response_json: dict = response.json()
error: dict = response_json["error"]
if response.status_code == 410 and error[0]["code"] == 21:
errmsg = f"{msg} {error=}"
errors: dict = response_json["errors"]
if response.status_code == 410 and errors[0]["code"] == 21:
errmsg = f"{msg} {errors=}"
raise ConversationArchivedWarning(errmsg)
super().validate_response(response)

Expand Down
34 changes: 34 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
"""Tests standard tap features using the built-in SDK tests library."""

import os
import typing

import responses
from singer_sdk.testing import get_standard_tap_tests

from tap_messagebird.tap import TapMessagebird

if typing.TYPE_CHECKING:
from tap_messagebird.streams import ConversationMessagesStream


SAMPLE_CONFIG = {
"api_key": os.getenv("TAP_MESSAGEBIRD_API_KEY"),
}
Expand All @@ -17,3 +23,31 @@ def test_standard_tap_tests():
tests = get_standard_tap_tests(TapMessagebird, config=SAMPLE_CONFIG)
for test in tests:
test()


@responses.activate
def test_missing_conversation():
"""Sometimes conversations are missing."""
responses.get(
"https://conversations.messagebird.com/v1/conversations/123456/messages",
json={
"errors": [
{
"code": 21,
"description": "The conversation is deleted",
},
],
},
status=410,
content_type="application/json",
)
# Don't need ENV variables here
tap: TapMessagebird = TapMessagebird(
config=SAMPLE_CONFIG,
parse_env_config=False,
)
conversation_message_stream: ConversationMessagesStream = tap.streams[
"conversation_message"
]
context = {"_sdc_conversations_id": "123456"}
conversation_message_stream.sync(context)

0 comments on commit ce91173

Please sign in to comment.