-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
109 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
airbyte-integrations/connectors/destination-deepset/integration_tests/conftest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
||
from __future__ import annotations | ||
|
||
import secrets | ||
from collections.abc import Mapping | ||
from logging import Logger | ||
from pathlib import Path | ||
from typing import Any | ||
from unittest.mock import Mock | ||
from uuid import uuid4 | ||
|
||
import pytest | ||
from airbyte_cdk.models import AirbyteMessage, AirbyteRecordMessage, ConfiguredAirbyteCatalog, Type | ||
from destination_deepset.api import DeepsetCloudApi | ||
from destination_deepset.models import DeepsetCloudConfig | ||
from destination_deepset.writer import DeepsetCloudFileWriter | ||
from pytest import MonkeyPatch | ||
|
||
|
||
@pytest.fixture() | ||
def config() -> Mapping[str, Any]: | ||
return { | ||
"api_key": secrets.token_urlsafe(16), | ||
"base_url": "https://api.dev.cloud.dpst.dev", | ||
"workspace": "airbyte-test", | ||
"retries": 5, | ||
} | ||
|
||
|
||
@pytest.fixture() | ||
def configured_catalog() -> ConfiguredAirbyteCatalog: | ||
path = Path("./sample_files/configured_catalog.json") | ||
return ConfiguredAirbyteCatalog.parse_file(path) | ||
|
||
|
||
@pytest.fixture() | ||
def input_messages() -> list[AirbyteMessage]: | ||
with Path("./sample_files/messages.jsonl").open() as f: | ||
return [AirbyteMessage(type=Type.RECORD, record=AirbyteRecordMessage.parse_raw(line)) for line in f] | ||
|
||
|
||
@pytest.fixture() | ||
def logger() -> Logger: | ||
return Mock(spec=Logger) | ||
|
||
|
||
@pytest.fixture() | ||
def api_client(monkeypatch: MonkeyPatch, config: Mapping[str, Any]) -> DeepsetCloudApi: | ||
cloud_config = DeepsetCloudConfig.parse_obj(config) | ||
patched = DeepsetCloudApi(cloud_config) | ||
|
||
monkeypatch.setattr(patched, "health_check", lambda *_: None) | ||
monkeypatch.setattr(patched, "upload", lambda *_: uuid4()) | ||
|
||
return patched | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def _ensure_mock_api(monkeypatch: MonkeyPatch, api_client: DeepsetCloudApi) -> None: | ||
def factory(*args) -> DeepsetCloudFileWriter: | ||
return DeepsetCloudFileWriter(api_client) | ||
|
||
monkeypatch.setattr("destination_deepset.destination.DeepsetCloudFileWriter.factory", factory) |
9 changes: 0 additions & 9 deletions
9
airbyte-integrations/connectors/destination-deepset/integration_tests/integration_test.py
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
airbyte-integrations/connectors/destination-deepset/integration_tests/test_destination.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
# | ||
from __future__ import annotations | ||
|
||
from collections.abc import Mapping | ||
from logging import Logger | ||
from typing import Any | ||
|
||
from airbyte_cdk.models import AirbyteMessage, ConfiguredAirbyteCatalog, Level, Status, Type | ||
from destination_deepset.destination import DestinationDeepset | ||
|
||
|
||
def test_write( | ||
config: Mapping[str, Any], configured_catalog: ConfiguredAirbyteCatalog, input_messages: list[AirbyteMessage] | ||
) -> None: | ||
batch_size = len(input_messages) | ||
assert batch_size > 0, "Number of messages should match lines in ./sample_files/messages.jsonl" | ||
|
||
destination = DestinationDeepset() | ||
|
||
results = list(destination.write(config, configured_catalog, iter(input_messages))) | ||
assert len(results) == batch_size | ||
for result in results: | ||
assert isinstance(result, AirbyteMessage) | ||
assert result.type == Type.LOG | ||
assert result.log.level == Level.INFO | ||
assert result.log.stack_trace is None | ||
|
||
|
||
def test_check(logger: Logger, config: Mapping[str, Any]) -> None: | ||
destination = DestinationDeepset() | ||
outcome = destination.check(logger, config) | ||
assert outcome.status == Status.SUCCEEDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.