Skip to content

Commit

Permalink
make our unit tests less brittle and not compare against messages out…
Browse files Browse the repository at this point in the history
… of our control (#20009)

* make our unit tests less brittle and not compare against messages out of our control

* testing text no more!
  • Loading branch information
brianjlai committed Dec 2, 2022
1 parent 1e160b2 commit 6dee382
Showing 1 changed file with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import pytest
from airbyte_cdk.models import AirbyteLogMessage, AirbyteMessage, AirbyteRecordMessage, Level, Type
from fastapi import HTTPException

from connector_builder.generated.models.http_request import HttpRequest
from connector_builder.generated.models.http_response import HttpResponse
from connector_builder.generated.models.stream_read import StreamRead
Expand All @@ -19,6 +17,7 @@
from connector_builder.generated.models.streams_list_read_streams import StreamsListReadStreams
from connector_builder.generated.models.streams_list_request_body import StreamsListRequestBody
from connector_builder.impl.default_api import DefaultApiImpl
from fastapi import HTTPException

MANIFEST = {
"version": "0.1.0",
Expand Down Expand Up @@ -343,17 +342,13 @@ def test_invalid_manifest():
}

expected_status_code = 400
expected_detail = "Invalid connector manifest with error: 'streams' is a required property"

api = DefaultApiImpl()
loop = asyncio.get_event_loop()
with pytest.raises(HTTPException) as actual_exception:
loop.run_until_complete(
api.read_stream(StreamReadRequestBody(manifest=invalid_manifest, config={}, stream="hashiras"))
)
loop.run_until_complete(api.read_stream(StreamReadRequestBody(manifest=invalid_manifest, config={}, stream="hashiras")))

assert actual_exception.value.status_code == expected_status_code
assert expected_detail in actual_exception.value.detail


def test_read_stream_invalid_group_format():
Expand All @@ -371,27 +366,20 @@ def test_read_stream_invalid_group_format():

loop = asyncio.get_event_loop()
with pytest.raises(HTTPException) as actual_exception:
loop.run_until_complete(
api.read_stream(StreamReadRequestBody(manifest=MANIFEST, config=CONFIG, stream="hashiras"))
)
loop.run_until_complete(api.read_stream(StreamReadRequestBody(manifest=MANIFEST, config=CONFIG, stream="hashiras")))

assert actual_exception.value.status_code == 400
assert actual_exception.value.detail == "Could not perform read with with error: Every message grouping should have at least one request and response"


def test_read_stream_returns_error_if_stream_does_not_exist():
expected_status_code = 400
expected_detail = "Could not perform read with with error: \"The requested stream not_in_manifest was not found in the source. Available streams: dict_keys(['hashiras', 'breathing-techniques'])\""

api = DefaultApiImpl()
loop = asyncio.get_event_loop()
with pytest.raises(HTTPException) as actual_exception:
loop.run_until_complete(
api.read_stream(StreamReadRequestBody(manifest=MANIFEST, config={}, stream="not_in_manifest"))
)
loop.run_until_complete(api.read_stream(StreamReadRequestBody(manifest=MANIFEST, config={}, stream="not_in_manifest")))

assert actual_exception.value.status_code == expected_status_code
assert expected_detail in actual_exception.value.detail


@pytest.mark.parametrize(
Expand Down

0 comments on commit 6dee382

Please sign in to comment.