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 1 commit
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 @@ -348,9 +347,7 @@ def test_invalid_manifest():
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
Expand All @@ -371,24 +368,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"
assert "Could not perform read with with error" in actual_exception.value.detail
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could even do away with checking any error text at all since text is often changing and error code tends to be more important

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to not testing the error message



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'])\""
expected_detail = "Could not perform read with with error"

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
Expand Down