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

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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