-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source Azure Table Storage: CDK Update (#34576)
- Loading branch information
1 parent
1aaf9dc
commit 78a6047
Showing
13 changed files
with
200 additions
and
93 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
41 changes: 23 additions & 18 deletions
41
airbyte-integrations/connectors/source-azure-table/acceptance-test-config.yml
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 |
---|---|---|
@@ -1,27 +1,32 @@ | ||
# See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference) | ||
# for more information about how to configure these tests | ||
connector_image: airbyte/source-azure-table:dev | ||
tests: | ||
acceptance_tests: | ||
spec: | ||
- spec_path: "source_azure_table/spec.json" | ||
tests: | ||
- spec_path: "source_azure_table/spec.json" | ||
connection: | ||
- config_path: "secrets/config.json" | ||
status: "succeed" | ||
- config_path: "integration_tests/invalid_config.json" | ||
status: "failed" | ||
tests: | ||
- config_path: "secrets/config.json" | ||
status: "succeed" | ||
- config_path: "integration_tests/invalid_config.json" | ||
status: "failed" | ||
discovery: | ||
- config_path: "secrets/config.json" | ||
tests: | ||
- config_path: "secrets/config.json" | ||
basic_read: | ||
- config_path: "secrets/config.json" | ||
configured_catalog_path: "integration_tests/configured_catalog.json" | ||
empty_streams: [] | ||
validate_schema: False | ||
tests: | ||
- config_path: "secrets/config.json" | ||
configured_catalog_path: "integration_tests/configured_catalog.json" | ||
empty_streams: [] | ||
validate_schema: False | ||
incremental: | ||
- config_path: "secrets/config.json" | ||
configured_catalog_path: "integration_tests/configured_catalog.json" | ||
future_state_path: "integration_tests/abnormal_state.json" | ||
tests: | ||
- config_path: "secrets/config.json" | ||
configured_catalog_path: "integration_tests/configured_catalog.json" | ||
future_state: | ||
future_state_path: "integration_tests/abnormal_state.json" | ||
full_refresh: | ||
- config_path: "secrets/config.json" | ||
configured_catalog_path: "integration_tests/configured_catalog.json" | ||
ignored_fields: | ||
"AirbyteTest": ["record"] | ||
tests: | ||
- config_path: "secrets/config.json" | ||
configured_catalog_path: "integration_tests/configured_catalog.json" |
12 changes: 8 additions & 4 deletions
12
airbyte-integrations/connectors/source-azure-table/integration_tests/abnormal_state.json
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"Test": { | ||
"PartitionKey": "abcd" | ||
[ | ||
{ | ||
"type": "STREAM", | ||
"stream": { | ||
"stream_state": { "PartitionKey": "999" }, | ||
"stream_descriptor": { "name": "pokemon" } | ||
} | ||
} | ||
} | ||
] |
21 changes: 0 additions & 21 deletions
21
airbyte-integrations/connectors/source-azure-table/integration_tests/catalog.json
This file was deleted.
Oops, something went wrong.
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
5 changes: 0 additions & 5 deletions
5
airbyte-integrations/connectors/source-azure-table/integration_tests/state.json
This file was deleted.
Oops, something went wrong.
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
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
43 changes: 43 additions & 0 deletions
43
airbyte-integrations/connectors/source-azure-table/unit_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,43 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
import logging | ||
from unittest import mock | ||
|
||
import pytest | ||
from source_azure_table.azure_table import AzureTableReader | ||
from source_azure_table.source import SourceAzureTable | ||
|
||
|
||
# Fixtures | ||
@pytest.fixture | ||
def config(): | ||
return {"storage_account_name": "dummy-value", "storage_access_key": "dummy-value", "storage_endpoint_suffix": "dummy-value"} | ||
|
||
|
||
@pytest.fixture | ||
def tables(): | ||
table1 = mock.Mock() | ||
table1.name = "AzureTable1" | ||
table2 = mock.Mock() | ||
table2.name = "AzureTable2" | ||
|
||
tables = mock.MagicMock() | ||
tables.__iter__.return_value = [table1, table2] | ||
return tables | ||
|
||
|
||
@pytest.fixture | ||
def source(): | ||
return SourceAzureTable() | ||
|
||
|
||
@pytest.fixture | ||
def logger(): | ||
return logging.getLogger("airbyte") | ||
|
||
|
||
@pytest.fixture | ||
def reader(config, logger): | ||
return AzureTableReader(logger, config) |
103 changes: 103 additions & 0 deletions
103
airbyte-integrations/connectors/source-azure-table/unit_tests/test_azure_table.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,103 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
import pytest | ||
|
||
|
||
def test_get_table_service_client_return(mocker, reader): | ||
""" | ||
Test that the get_table_service_client method returns the expected Table Service Client. | ||
""" | ||
mock_client = "dummy-client" | ||
mocker.patch( | ||
"source_azure_table.azure_table.TableServiceClient.from_connection_string", | ||
return_value=mock_client, | ||
) | ||
|
||
client = reader.get_table_service_client() | ||
assert client == mock_client | ||
|
||
|
||
def test_get_table_service_client_handles_exception(mocker, reader): | ||
""" | ||
Test that get_table_service_client method handles exceptions correctly. | ||
""" | ||
mocker.patch( | ||
"source_azure_table.azure_table.TableServiceClient.from_connection_string", | ||
side_effect=Exception("Connection error") | ||
) | ||
|
||
with pytest.raises(Exception) as exc_info: | ||
reader.get_table_service_client() | ||
|
||
assert "Connection error" in str(exc_info.value) | ||
|
||
|
||
def test_get_table_client_return(mocker, reader): | ||
""" | ||
Test that the get_table_client method returns the expected Table Client. | ||
""" | ||
mock_client = "dummy-client" | ||
mocker.patch( | ||
"source_azure_table.azure_table.TableClient.from_connection_string", | ||
return_value=mock_client, | ||
) | ||
|
||
table = reader.get_table_client("dummy-table") | ||
assert table == mock_client | ||
|
||
|
||
def test_get_table_client_handles_exception(mocker, reader): | ||
""" | ||
Test that get_table_client method handles exceptions correctly. | ||
""" | ||
|
||
# The method throws its own exception for empty table names | ||
with pytest.raises(Exception) as exc_info: | ||
reader.get_table_client("") | ||
assert "table name is not valid." in str(exc_info.value) | ||
|
||
mocker.patch( | ||
"source_azure_table.azure_table.TableClient.from_connection_string", | ||
side_effect=Exception("Connection error") | ||
) | ||
|
||
with pytest.raises(Exception) as exc_info: | ||
reader.get_table_client("valid_table_name") | ||
assert "Connection error" in str(exc_info.value) | ||
|
||
|
||
def test_get_tables_return(mocker, reader, tables): | ||
""" | ||
Test that the get_tables method returns the expected tables. | ||
""" | ||
mock_client = mocker.MagicMock() | ||
mock_client.list_tables.return_value = tables.__iter__() | ||
mocker.patch( | ||
"azure.data.tables.TableServiceClient.from_connection_string", | ||
return_value=mock_client | ||
) | ||
|
||
result = reader.get_tables() | ||
result_table_names = [table.name for table in result] | ||
|
||
expected_table_names = ["AzureTable1", "AzureTable2"] | ||
assert result_table_names == expected_table_names | ||
|
||
|
||
def test_get_tables_handles_exception(mocker, reader): | ||
""" | ||
Test that get_tables method handles exceptions correctly. | ||
""" | ||
mock_client = mocker.MagicMock() | ||
mock_client.list_tables.side_effect = Exception("Failed to list tables") | ||
mocker.patch( | ||
"azure.data.tables.TableServiceClient.from_connection_string", | ||
return_value=mock_client | ||
) | ||
|
||
with pytest.raises(Exception) as exc_info: | ||
reader.get_tables() | ||
|
||
assert "Failed to list tables" in str(exc_info.value) |
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