Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDL-15318: PK for track_events stream #50

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
16 changes: 8 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ jobs:
name: 'Unit Tests'
command: |
source /usr/local/share/virtualenvs/tap-pendo/bin/activate
pip install coverage
pip install nose coverage
nosetests --with-coverage --cover-erase --cover-package=tap_pendo --cover-html-dir=htmlcov tests/unittests
coverage html
- store_test_results:
path: test_output/report.xml
- store_artifacts:
path: htmlcov
- add_ssh_keys
- run:
name: 'Integration Tests'
command: |
aws s3 cp s3://com-stitchdata-dev-deployment-assets/environments/tap-tester/tap_tester_sandbox dev_env.sh
source dev_env.sh
source /usr/local/share/virtualenvs/tap-tester/bin/activate
run-test --tap=tap-pendo tests/tap_tester
# - run:
# name: 'Integration Tests'
# command: |
# aws s3 cp s3://com-stitchdata-dev-deployment-assets/environments/tap-tester/tap_tester_sandbox dev_env.sh
# source dev_env.sh
# source /usr/local/share/virtualenvs/tap-tester/bin/activate
# run-test --tap=tap-pendo tests/tap_tester
workflows:
version: 2
commit:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ This tap:
**[feature_events](https://developers.pendo.io/docs/?bash#get-an-account-by-id)**

- Endpoint: [https://api/v1/aggregation](https://app.pendo.io/api/v1/aggregation)
- Primary key fields: `visitor_id`, `account_id`, `server`, `remote_ip`
- Primary key fields: `feature_id`, `visitor_id`, `account_id`, `server`, `remote_ip`, `user_agent`, `day` or `hour`
- Replication strategy: INCREMENTAL (query filtered)
- Bookmark: `day` or `hour`
- Transformations: Camel to snake case.
Expand Down Expand Up @@ -135,7 +135,7 @@ This tap:
**[track_events](https://developers.pendo.io/docs/?bash#get-an-account-by-id)**

- Endpoint: [https://api/v1/aggregation](https://app.pendo.io/api/v1/aggregation)
- Primary key fields: `visitor_id`, `account_id`, `server`, `remote_ip`
- Primary key fields: `track_type_id`, `visitor_id`, `account_id`, `server`, `remote_ip`, `user_agent`, `day` or `hour`
- Replication strategy: INCREMENTAL (query filtered)
- Bookmark: `day` or `hour`
- Transformations: Camel to snake case.
Expand Down
11 changes: 9 additions & 2 deletions tap_pendo/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,11 @@ def get_body(self):
class FeatureEvents(EventsBase):
name = "feature_events"
replication_method = "INCREMENTAL"
key_properties = ['visitor_id', 'account_id', 'server', 'remote_ip']
key_properties = ['feature_id', 'visitor_id', 'account_id', 'server', 'remote_ip', 'user_agent']

def __init__(self, config):
super().__init__(config=config)
self.key_properties.append("day" if self.period == 'dayRange' else "hour")

def get_body(self, key_id, period, first):
return {
Expand Down Expand Up @@ -689,8 +693,11 @@ def sync(self, state, start_date=None, key_id=None):
class TrackEvents(EventsBase):
replication_method = "INCREMENTAL"
name = "track_events"
key_properties = ['visitor_id', 'account_id', 'server', 'remote_ip']
key_properties = ['track_type_id', 'visitor_id', 'account_id', 'server', 'remote_ip', 'user_agent']

def __init__(self, config):
super().__init__(config=config)
self.key_properties.append("day" if self.period == 'dayRange' else "hour")
hpatel41 marked this conversation as resolved.
Show resolved Hide resolved

def get_body(self, key_id, period, first):
return {
Expand Down
16 changes: 9 additions & 7 deletions tests/tap_tester/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TestPendoBase(unittest.TestCase):
START_DATE_FORMAT = "%Y-%m-%dT00:00:00Z"
BOOKMARK_COMPARISON_FORMAT = "%Y-%m-%dT%H:%M%S%z"
start_date = ""
is_day_range = True

@staticmethod
def name():
Expand All @@ -39,6 +40,7 @@ def get_type():

def expected_metadata(self):
"""The expected streams and metadata about the streams"""
event_replication_key = 'day' if self.is_day_range else 'hour'
return {
"accounts": {
self.PRIMARY_KEYS: {'account_id'},
Expand Down Expand Up @@ -79,19 +81,19 @@ def expected_metadata(self):
self.REPLICATION_KEYS: {'last_updated_at'}
},
"feature_events":{
self.PRIMARY_KEYS: {"visitor_id", "account_id", "server", "remote_ip"},
self.PRIMARY_KEYS: {"feature_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent", event_replication_key},
self.REPLICATION_METHOD: self.INCREMENTAL,
self.REPLICATION_KEYS: {'day'}
self.REPLICATION_KEYS: {event_replication_key}
},
"events": {
self.PRIMARY_KEYS: {"visitor_id", "account_id", "server", "remote_ip"},
self.REPLICATION_METHOD: self.INCREMENTAL,
self.REPLICATION_KEYS: {'day'}
self.REPLICATION_KEYS: {event_replication_key}
},
"page_events": {
self.PRIMARY_KEYS: {"visitor_id", "account_id", "server", "remote_ip"},
self.REPLICATION_METHOD: self.INCREMENTAL,
self.REPLICATION_KEYS: {'day'}
self.REPLICATION_KEYS: {event_replication_key}
},
"guide_events": {
self.PRIMARY_KEYS: {"visitor_id", "account_id", "server_name", "remote_ip"},
Expand All @@ -104,9 +106,9 @@ def expected_metadata(self):
self.REPLICATION_KEYS: {'browser_time'}
},
"track_events": {
self.PRIMARY_KEYS: {"visitor_id", "account_id", "server", "remote_ip"},
self.PRIMARY_KEYS: {"track_type_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent", event_replication_key},
self.REPLICATION_METHOD: self.INCREMENTAL,
self.REPLICATION_KEYS: {'day'}
self.REPLICATION_KEYS: {event_replication_key}
},
"metadata_accounts": {
self.REPLICATION_METHOD: self.FULL_TABLE,
Expand Down Expand Up @@ -136,7 +138,7 @@ def get_properties(self, original: bool = True):
return_value = {
"start_date": "2020-09-10T00:00:00Z",
"lookback_window": "1",
"period": "dayRange",
"period": "dayRange" if self.is_day_range else "hourRange",
}
if original:
return return_value
Expand Down
13 changes: 11 additions & 2 deletions tests/tap_tester/test_bookmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PendoBookMarkTest(TestPendoBase):
def name(self):
return "pendo_bookmark_test"

def test_run(self):
def run_test(self):
"""
Verify that for each stream you can do a sync which records bookmarks.
That the bookmark is the maximum value sent to the target for the replication key.
Expand Down Expand Up @@ -191,4 +191,13 @@ def test_run(self):

# Verify at least 1 record was replicated in the second sync
self.assertGreater(
second_sync_count, 0, msg="We are not fully testing bookmarking for {}".format(stream))
second_sync_count, 0, msg="We are not fully testing bookmarking for {}".format(stream))

def test_run(self):
# test for hourRange period
self.is_day_range = False
self.run_test()

# test for dayRange period
self.is_day_range = True
self.run_test()
12 changes: 11 additions & 1 deletion tests/tap_tester/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PendoDiscoverTest(TestPendoBase):
def name(self):
return "pendo_discover_test"

def test_run(self):
def discovery_test_run(self):
streams_to_test = self.expected_streams()

conn_id = connections.ensure_connection(self, payload_hook=None)
Expand Down Expand Up @@ -123,3 +123,13 @@ def test_run(self):
and item.get("breadcrumb", ["properties", None])[1]
not in actual_automatic_fields}),
msg="Not all non key properties are set to available in metadata")

def test_run(self):

#Discovery test for hourRange period
self.is_day_range = False
self.discovery_test_run()

#Discovery test for dayRange period
self.is_day_range = True
self.discovery_test_run()
30 changes: 30 additions & 0 deletions tests/unittests/test_feature_events_primary_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import unittest
from tap_pendo.streams import FeatureEvents

class TestFeatureEventsPrimaryKeys(unittest.TestCase):

def test_feature_event_primary_key_with_hourRange(self):
'''
Verify that primary keys should have expected fields with 'hour' field when period is hourRange
'''
# Reset key properties to default value
FeatureEvents.key_properties = ['feature_id', 'visitor_id', 'account_id', 'server', 'remote_ip', 'user_agent']
config = {"period": "hourRange"} # set hourRange as a period
expected_primary_keys = ["feature_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent", "hour"]

feature_event_stream1 = FeatureEvents(config) # Initialize FeatuereEvents object which sets primary keys

self.assertEqual(feature_event_stream1.key_properties, expected_primary_keys)

def test_feature_event_primary_key_with_dayRange(self):
'''
Verify that primary keys should have expected fields with 'day' field when period is dayRange
'''
# Reset key properties to default value
FeatureEvents.key_properties = ['feature_id', 'visitor_id', 'account_id', 'server', 'remote_ip', 'user_agent']
config = {"period": "dayRange"} # set dayRange as a period
expected_primary_keys = ["feature_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent", "day"]

feature_event_stream2 = FeatureEvents(config) # Initialize Events object which sets primary keys

self.assertEqual(feature_event_stream2.key_properties, expected_primary_keys)
34 changes: 34 additions & 0 deletions tests/unittests/test_track_events_primary_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
from tap_pendo.streams import TrackEvents

class TestTrackEventsPrimaryKey(unittest.TestCase):

def test_track_events_primary_key_with_hourRange(self):
'''
Verify that primary keys should have expected fields with 'hour' field when period is hourRange
'''
# Reset key properties to default value
TrackEvents.key_properties = ["track_type_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent"]
config = {"period": "hourRange"} # set hourRange as a period

expected_primary_keys = ["track_type_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent", "hour"]

event_stream1 = TrackEvents(config) # Initialize TrackEvents object which sets primary keys

# verify if the key properties macthes the expectation
self.assertEqual(event_stream1.key_properties, expected_primary_keys)

def test_track_events_primary_key_with_dayRange(self):
'''
Verify that primary keys should have expected fields with 'day' field when period is dayRange
'''
# Reset key properties to default value
TrackEvents.key_properties = ["track_type_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent"]
config = {"period": "dayRange"} # set dayRange as a period

expected_primary_keys = ["track_type_id", "visitor_id", "account_id", "server", "remote_ip", "user_agent", "day"]

event_stream2 = TrackEvents(config) # Initialize TrackEvents object which sets primary keys

# verify if the key properties macthes the expectation
self.assertEqual(event_stream2.key_properties, expected_primary_keys)