diff --git a/CHANGELOG.md b/CHANGELOG.md index 704b946..849c498 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 2.3.0 + * Adds parent-tap-stream-id field to catalog for child streams [#84](https://github.com/singer-io/tap-intercom/pull/84) + ## 2.2.3 * Fix pylint errors [#83](https://github.com/singer-io/tap-intercom/pull/83) diff --git a/setup.py b/setup.py index a202b71..2fc8438 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup(name='tap-intercom', - version='2.2.3', + version='2.3.0', description='Singer.io tap for extracting data from the Intercom API', author='jeff.huth@bytecode.io', classifiers=['Programming Language :: Python :: 3 :: Only'], diff --git a/tap_intercom/schema.py b/tap_intercom/schema.py index 3fb3a1c..be610da 100644 --- a/tap_intercom/schema.py +++ b/tap_intercom/schema.py @@ -40,6 +40,11 @@ def get_schemas(): ) mdata = metadata.to_map(mdata) + # Check if the stream has any parent attribute + parent_class = getattr(stream_object, 'parent', None) + if parent_class and hasattr(parent_class, 'tap_stream_id'): + parent_tap_stream_id = parent_class.tap_stream_id + mdata = metadata.write(mdata, (), 'parent-tap-stream-id', parent_tap_stream_id) if stream_object.replication_key: mdata = metadata.write( diff --git a/tests/base.py b/tests/base.py index f7ac3e0..ffbf0d2 100644 --- a/tests/base.py +++ b/tests/base.py @@ -27,6 +27,8 @@ class IntercomBaseTest(unittest.TestCase): PRIMARY_KEYS = "table-key-properties" FOREIGN_KEYS = "table-foreign-key-properties" REPLICATION_METHOD = "forced-replication-method" + PARENT_TAP_STREAM_ID = "parent-tap-stream-id" + EXPECTED_PARENT_STREAM = "expected-parent-stream" OBEYS_START_DATE = "obeys-start-date" API_LIMIT = "max-row-limit" INCREMENTAL = "INCREMENTAL" @@ -80,6 +82,7 @@ def expected_metadata(self): "admins": { self.PRIMARY_KEYS: {"id"}, self.REPLICATION_METHOD: self.FULL_TABLE, + self.EXPECTED_PARENT_STREAM: "admin_list", self.OBEYS_START_DATE : False }, "companies": { @@ -109,6 +112,7 @@ def expected_metadata(self): self.PRIMARY_KEYS: {"id"}, self.REPLICATION_METHOD: self.INCREMENTAL, self.REPLICATION_KEYS: {"updated_at"}, + self.EXPECTED_PARENT_STREAM: "conversations", self.OBEYS_START_DATE : True }, "contact_attributes": { diff --git a/tests/test_intercom_discovery.py b/tests/test_intercom_discovery.py index ad3476a..05a7bb6 100644 --- a/tests/test_intercom_discovery.py +++ b/tests/test_intercom_discovery.py @@ -54,6 +54,8 @@ def test_run(self): expected_primary_keys = self.expected_primary_keys()[stream] expected_replication_keys = self.expected_replication_keys()[stream] expected_automatic_fields = expected_primary_keys | expected_replication_keys + expected_replication_method = self.expected_metadata()[stream].get(self.REPLICATION_METHOD) + expected_parent_stream = self.expected_metadata()[stream].get(self.EXPECTED_PARENT_STREAM) # Collecting actual values... schema_and_metadata = menagerie.get_annotated_schema(conn_id, catalog['stream_id']) @@ -72,6 +74,12 @@ def test_run(self): stream_properties[0].get( "metadata", {self.REPLICATION_KEYS: []}).get(self.REPLICATION_KEYS, []) ) + + actual_replication_method = stream_properties[0].get( + "metadata", {self.REPLICATION_METHOD: None}).get(self.REPLICATION_METHOD) + + actual_parent_stream_id = stream_properties[0].get( + "metadata", {}).get(self.PARENT_TAP_STREAM_ID) ########################################################################## ### metadata assertions ########################################################################## @@ -99,6 +107,12 @@ def test_run(self): # are given the inclusion of automatic in metadata. self.assertSetEqual(expected_automatic_fields, actual_automatic_fields) + # verify the replication method matches our expectations + self.assertEqual(expected_replication_method, actual_replication_method) + + # verify parent-tap-stream-id for child streams + self.assertEqual(expected_parent_stream, actual_parent_stream_id) + # Verify that all other fields have an inclusion of available # This assumes there are no unsupported fields for SaaS sources self.assertTrue(