Skip to content

Commit 81509aa

Browse files
authored
Adding stream url path link for dynamic schema (#7)
* Added module-path in catalog * Removed module-path, added path in sync
1 parent ba7d166 commit 81509aa

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

tap_zoho_crm/discover.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def discover(client: Client) -> Catalog:
3131
raise err
3232

3333
key_properties = metadata.to_map(mdata).get((), {}).get("table-key-properties")
34-
34+
stream_name = stream_name.lower()
3535
catalog.streams.append(
3636
CatalogEntry(
37-
stream=stream_name.lower(),
37+
stream=stream_name,
3838
tap_stream_id=stream_name,
3939
key_properties=key_properties,
4040
schema=schema,

tap_zoho_crm/sync.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from tap_zoho_crm.streams import STREAMS, abstracts
55
from tap_zoho_crm.client import Client
66
from tap_zoho_crm.streams.abstracts import IncrementalStream, FullTableStream
7+
from tap_zoho_crm.schema import get_dynamic_schema
78

89
LOGGER = singer.get_logger()
910

@@ -34,7 +35,11 @@ def write_schema(stream, client, streams_to_sync, catalog) -> None:
3435
stream.child_to_sync.append(child_obj)
3536

3637

37-
def build_dynamic_stream(client, catalog_entry: singer.CatalogEntry) -> object:
38+
def build_dynamic_stream(
39+
client,
40+
catalog_entry: singer.CatalogEntry,
41+
module_path: str
42+
) -> object:
3843
"""Create a dynamic stream instance based on stream_catalog."""
3944
catalog_metadata = metadata.to_map(catalog_entry.metadata)
4045

@@ -49,7 +54,7 @@ def build_dynamic_stream(client, catalog_entry: singer.CatalogEntry) -> object:
4954
"key_properties": property(lambda self: key_properties),
5055
"replication_method": property(lambda self: replication_method),
5156
"replication_keys": property(lambda self: replication_keys),
52-
"path": tap_stream_id,
57+
"path": module_path,
5358
"data_key": "data",
5459
"is_dynamic": True
5560
}
@@ -86,7 +91,8 @@ def sync(client: Client, config: Dict, catalog: singer.Catalog, state) -> None:
8691
"""
8792
Sync selected streams from catalog
8893
"""
89-
94+
dynamic_schemas, _ = get_dynamic_schema(client)
95+
dynamic_schema_path = {item.lower(): item for item in dynamic_schemas.keys()}
9096
streams_to_sync = []
9197
for stream in catalog.get_selected_streams(state):
9298
catalog_entry = catalog.get_stream(stream.tap_stream_id)
@@ -104,7 +110,11 @@ def sync(client: Client, config: Dict, catalog: singer.Catalog, state) -> None:
104110
if stream_name in STREAMS:
105111
stream = STREAMS[stream_name](client, catalog.get_stream(stream_name))
106112
else:
107-
stream = build_dynamic_stream(client, catalog.get_stream(stream_name))
113+
stream = build_dynamic_stream(
114+
client,
115+
catalog.get_stream(stream_name),
116+
dynamic_schema_path.get(stream_name)
117+
)
108118

109119
parent_name = getattr(stream, "parent", None)
110120
if parent_name:

tests/unittests/test_sync.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,26 @@ def test_build_dynamic_stream_full_table(self):
8686
"""Test build_dynamic_stream returns FullTableStream subclass when method is FULL_TABLE."""
8787
catalog_entry = MagicMock()
8888
catalog_entry.stream = "accounts"
89-
catalog_entry.tap_stream_id = "Accounts"
89+
catalog_entry.tap_stream_id = "accounts"
9090
catalog_entry.key_properties = ["id"]
9191

9292
# Here's the mocked metadata (as a raw dict)
9393
catalog_entry.metadata = [
9494
{
9595
"breadcrumb": [],
9696
"metadata": {
97-
"tap_stream_id": "Accounts",
97+
"tap_stream_id": "accounts",
9898
"forced-replication-method": "FULL_TABLE",
9999
"valid-replication-keys": ["id"]
100100
}
101101
}
102102
]
103103

104104
mock_client = MagicMock()
105-
stream_instance = build_dynamic_stream(mock_client, catalog_entry)
105+
stream_instance = build_dynamic_stream(mock_client, catalog_entry, "Accounts")
106106

107107
self.assertIsInstance(stream_instance, FullTableStream)
108-
self.assertEqual(stream_instance.tap_stream_id, "Accounts")
108+
self.assertEqual(stream_instance.tap_stream_id, "accounts")
109109
self.assertEqual(stream_instance.key_properties, ["id"])
110110
self.assertEqual(stream_instance.replication_method, "FULL_TABLE")
111111
self.assertEqual(stream_instance.replication_keys, ["id"])
@@ -117,24 +117,24 @@ def test_build_dynamic_stream_incremental(self):
117117
"""Test build_dynamic_stream returns IncrementalStream subclass when method is INCREMENTAL."""
118118
catalog_entry = MagicMock()
119119
catalog_entry.stream = "contacts"
120-
catalog_entry.tap_stream_id = "Contacts"
120+
catalog_entry.tap_stream_id = "contacts"
121121
catalog_entry.key_properties = ["id"]
122122
catalog_entry.metadata = [
123123
{
124124
"breadcrumb": [],
125125
"metadata": {
126-
"tap_stream_id": "Contacts",
126+
"tap_stream_id": "contacts",
127127
"forced-replication-method": "INCREMENTAL",
128128
"valid-replication-keys": ["updated_at"]
129129
}
130130
}
131131
]
132132

133133
mock_client = MagicMock()
134-
stream_instance = build_dynamic_stream(mock_client, catalog_entry)
134+
stream_instance = build_dynamic_stream(mock_client, catalog_entry, "Contacts")
135135

136136
self.assertIsInstance(stream_instance, IncrementalStream)
137-
self.assertEqual(stream_instance.tap_stream_id, "Contacts")
137+
self.assertEqual(stream_instance.tap_stream_id, "contacts")
138138
self.assertEqual(stream_instance.replication_method, "INCREMENTAL")
139139
self.assertEqual(stream_instance.replication_keys, ["updated_at"])
140140
self.assertEqual(stream_instance.path, "Contacts")

0 commit comments

Comments
 (0)