Skip to content

Commit

Permalink
Add dynamic discovery test
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenFrankel committed Feb 4, 2024
1 parent cb88fc3 commit 1f6d2f3
Show file tree
Hide file tree
Showing 3 changed files with 314 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
"""Test suite for tap-msaccess."""

from singer_sdk.testing.suites import TestSuite

from tests.test_dynamic_discovery import TapDynamicDiscoveryTest

custom_tap_tests = TestSuite(kind="tap", tests=[TapDynamicDiscoveryTest])
2 changes: 2 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from singer_sdk.testing import SuiteConfig, get_tap_test_class

from tap_msaccess.tap import TapMSAccess
from tests import custom_tap_tests

SAMPLE_CONFIG = {"database_file": "sample_db/Books.accdb"}

# Run standard built-in tap tests from the SDK:
TestTapMSAccess = get_tap_test_class(
tap_class=TapMSAccess,
config=SAMPLE_CONFIG,
custom_suites=[custom_tap_tests],
suite_config=SuiteConfig(
ignore_no_records_for_streams=[
"MSysComplexType_UnsignedByte",
Expand Down
306 changes: 306 additions & 0 deletions tests/test_dynamic_discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
# ruff: noqa: D101, D102, S101

"""Tests tap dynamic discovery."""

from itertools import zip_longest

import singer_sdk.typing as th
from singer_sdk.testing.templates import TapTestTemplate


class TapDynamicDiscoveryTest(TapTestTemplate):
name = "dynamic_discovery"

def test(self) -> None: # noqa: PLR0915
streams = iter(self.tap.discover_streams())
stream = next(streams, None)

assert stream
assert stream.name == "MSysObjects"
assert stream.primary_keys == ["Id"]

self._assert_schema_properties(
stream.schema,
th.Property("Connect", th.StringType),
th.Property("Database", th.StringType),
th.Property("DateCreate", th.DateTimeType),
th.Property("DateUpdate", th.DateTimeType),
th.Property("Flags", th.IntegerType),
th.Property("ForeignName", th.StringType),
th.Property("Id", th.IntegerType),
th.Property("Lv", th.StringType),
th.Property("LvExtra", th.StringType),
th.Property("LvModule", th.StringType),
th.Property("LvProp", th.StringType),
th.Property("Name", th.StringType),
th.Property("Owner", th.StringType),
th.Property("ParentId", th.IntegerType),
th.Property("RmtInfoLong", th.StringType),
th.Property("RmtInfoShort", th.StringType),
th.Property("Type", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysComplexType_UnsignedByte"
assert not stream.primary_keys

self._assert_schema_properties(
stream.schema,
th.Property("Value", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysComplexType_Short"
assert not stream.primary_keys

self._assert_schema_properties(
stream.schema,
th.Property("Value", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysComplexType_Long"
assert not stream.primary_keys

self._assert_schema_properties(
stream.schema,
th.Property("Value", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysComplexType_IEEESingle"
assert not stream.primary_keys

self._assert_schema_properties(
stream.schema,
th.Property("Value", th.NumberType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysComplexType_IEEEDouble"
assert not stream.primary_keys

self._assert_schema_properties(
stream.schema,
th.Property("Value", th.NumberType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysComplexType_GUID"
assert not stream.primary_keys

self._assert_schema_properties(
stream.schema,
th.Property("Value", th.StringType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysComplexType_Decimal"
assert not stream.primary_keys

self._assert_schema_properties(
stream.schema,
th.Property("Value", th.StringType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysComplexType_Text"
assert not stream.primary_keys

self._assert_schema_properties(
stream.schema,
th.Property("Value", th.StringType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysComplexType_Attachment"
assert not stream.primary_keys

self._assert_schema_properties(
stream.schema,
th.Property("FileData", th.StringType),
th.Property("FileFlags", th.IntegerType),
th.Property("FileName", th.StringType),
th.Property("FileTimeStamp", th.DateTimeType),
th.Property("FileType", th.StringType),
th.Property("FileURL", th.StringType),
)

stream = next(streams, None)

assert stream
assert stream.name == "Authors"
assert stream.primary_keys == ["Au_ID"]

self._assert_schema_properties(
stream.schema,
th.Property("Au_ID", th.IntegerType),
th.Property("Author", th.StringType),
th.Property("Year_Born", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysAccessStorage"
assert stream.primary_keys == ["Id"]

self._assert_schema_properties(
stream.schema,
th.Property("DateCreate", th.DateTimeType),
th.Property("DateUpdate", th.DateTimeType),
th.Property("Id", th.IntegerType),
th.Property("Lv", th.StringType),
th.Property("Name", th.StringType),
th.Property("ParentId", th.IntegerType),
th.Property("Type", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysNavPaneGroupCategories"
assert stream.primary_keys == ["Id"]

self._assert_schema_properties(
stream.schema,
th.Property("Filter", th.StringType),
th.Property("Flags", th.IntegerType),
th.Property("Id", th.IntegerType),
th.Property("Name", th.StringType),
th.Property("Position", th.IntegerType),
th.Property("SelectedObjectID", th.IntegerType),
th.Property("Type", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysNavPaneGroups"
assert stream.primary_keys == ["Id"]

self._assert_schema_properties(
stream.schema,
th.Property("Flags", th.IntegerType),
th.Property("GroupCategoryID", th.IntegerType),
th.Property("Id", th.IntegerType),
th.Property("Name", th.StringType),
th.Property("Object_Type_Group", th.IntegerType),
th.Property("ObjectID", th.IntegerType),
th.Property("Position", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysNavPaneGroupToObjects"
assert stream.primary_keys == ["Id"]

self._assert_schema_properties(
stream.schema,
th.Property("Flags", th.IntegerType),
th.Property("GroupID", th.IntegerType),
th.Property("Icon", th.IntegerType),
th.Property("Id", th.IntegerType),
th.Property("Name", th.StringType),
th.Property("ObjectID", th.IntegerType),
th.Property("Position", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "MSysNavPaneObjectIDs"
assert not stream.primary_keys

self._assert_schema_properties(
stream.schema,
th.Property("Id", th.IntegerType),
th.Property("Name", th.StringType),
th.Property("Type", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "Publishers"
assert stream.primary_keys == ["PubID"]

self._assert_schema_properties(
stream.schema,
th.Property("PubID", th.IntegerType),
th.Property("Name", th.StringType),
th.Property("Company_Name", th.StringType),
th.Property("Address", th.StringType),
th.Property("City", th.StringType),
th.Property("State", th.StringType),
th.Property("Zip", th.StringType),
th.Property("Telephone", th.StringType),
th.Property("Fax", th.StringType),
th.Property("Comments", th.StringType),
)

stream = next(streams, None)

assert stream
assert stream.name == "Title_Author"
assert stream.primary_keys == ["ISBN", "Au_ID"]

self._assert_schema_properties(
stream.schema,
th.Property("ISBN", th.StringType),
th.Property("Au_ID", th.IntegerType),
)

stream = next(streams, None)

assert stream
assert stream.name == "Titles"
assert stream.primary_keys == ["ISBN"]

self._assert_schema_properties(
stream.schema,
th.Property("Title", th.StringType),
th.Property("Year_Published", th.IntegerType),
th.Property("ISBN", th.StringType),
th.Property("PubID", th.IntegerType),
th.Property("Description", th.StringType),
th.Property("Notes", th.StringType),
th.Property("Subject", th.StringType),
th.Property("Comments", th.StringType),
)

stream = next(streams, None)

assert not stream

def _assert_schema_properties(
self,
schema: dict,
*expected_properties: th.Property,
) -> None:
actual_properties: dict = schema["properties"]

for actual, expected in zip_longest(
({k: v} for k, v in actual_properties.items()),
(p.to_dict() for p in expected_properties),
):
assert actual == expected

0 comments on commit 1f6d2f3

Please sign in to comment.