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

Set Default Include Anonymous Visitors, handle None values, add unit tests #111

Merged
merged 3 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tap_pendo/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
session = requests.Session()
# timeout request after 300 seconds
REQUEST_TIMEOUT = 300
DEFAULT_INCLUDE_ANONYMOUS_VISITORS = 'false'

def get_abs_path(path):
return os.path.join(os.path.dirname(os.path.realpath(__file__)), path)
Expand Down Expand Up @@ -1000,7 +1001,8 @@ class Visitors(LazyAggregationStream):
key_properties = ["visitor_id"]

def get_body(self):
include_anonymous_visitors = bool(self.config.get('include_anonymous_visitors', 'false').lower() == 'true')
include_anonymous_visitors = self.config.get('include_anonymous_visitors') or DEFAULT_INCLUDE_ANONYMOUS_VISITORS
anons = str(include_anonymous_visitors).lower() == 'true'
return {
"response": {
"mimeType": "application/json"
Expand All @@ -1011,7 +1013,7 @@ def get_body(self):
"pipeline": [{
"source": {
"visitors": {
"identified": not include_anonymous_visitors
"identified": not anons
}
}
}],
Expand Down
3 changes: 2 additions & 1 deletion tests/tap_tester/test_start_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def name(self):
return "pendo_start_date_test"

def test_run(self):
self.run_test("2021-09-09T00:00:00Z", "2022-05-01T00:00:00Z", {"accounts", "visitors", "metadata_visitors", "metadata_accounts"})
self.run_test("2022-06-10T00:00:00Z", "2022-07-22T00:00:00Z", {"accounts"})
self.run_test("2021-09-09T00:00:00Z", "2022-05-01T00:00:00Z", {"visitors", "metadata_visitors", "metadata_accounts"})
self.run_test("2020-09-01T00:00:00Z", "2021-03-01T00:00:00Z", {"features", "feature_events", "pages", "page_events", "events"})
self.run_test("2021-09-09T00:00:00Z", "2021-09-16T00:00:00Z", {"guides", "guide_events"})
self.run_test("2021-09-13T00:00:00Z", "2021-09-15T00:00:00Z", {"track_types", "track_events"})
Expand Down
110 changes: 109 additions & 1 deletion tests/unittests/test_lazy_aggregation_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_lazzy_aggregation_with_sub_stream(self, mocked_substream, mocked_select
def test_lazzy_aggregation_without_sub_stream(self, mocked_substream, mocked_selected, mocked_request):
'''
Verify that if sub stream is not selected then also all data should be return for super stream
and sync_substream should not be called
and sync_substream should not be called
'''
expected_data = [{"id":1}, {"id":2}, {"id":3}]
records = '{"results": [{"id":1}, {"id":2}, {"id":3}]}'
Expand All @@ -77,3 +77,111 @@ def test_lazzy_aggregation_without_sub_stream(self, mocked_substream, mocked_sel

self.assertEqual(list(stream_response), expected_data)
self.assertEqual(mocked_substream.call_count, 0)

class TestConfigParsing(unittest.TestCase):

def test_reading_include_anonymous_visitors_provided_valid_input_true(self):
config = {
'include_anonymous_visitors': 'true'
}

my_visitor = Visitors(config)


return_value = my_visitor.get_body()
expected_value = True

# This is the value that matches the config
actual_value = not return_value['request']['pipeline'][0]['source']['visitors']['identified']

self.assertEqual(expected_value, actual_value)

def test_reading_include_anonymous_visitors_provided_valid_input_TRUE(self):
config = {
'include_anonymous_visitors': 'TRUE'
}

my_visitor = Visitors(config)


return_value = my_visitor.get_body()
expected_value = True

# This is the value that matches the config
actual_value = not return_value['request']['pipeline'][0]['source']['visitors']['identified']

self.assertEqual(expected_value, actual_value)

def test_reading_include_anonymous_visitors_provided_valid_input_false(self):
config = {
'include_anonymous_visitors': 'false'
}

my_visitor = Visitors(config)


return_value = my_visitor.get_body()
expected_value = False

# This is the value that matches the config
actual_value = not return_value['request']['pipeline'][0]['source']['visitors']['identified']

self.assertEqual(expected_value, actual_value)

def test_reading_include_anonymous_visitors_provided_invalid_input(self):
config = {
'include_anonymous_visitors': 'bad input'
}

my_visitor = Visitors(config)

return_value = my_visitor.get_body()
expected_value = False
actual_value = not return_value['request']['pipeline'][0]['source']['visitors']['identified']
self.assertEqual(expected_value, actual_value)

def test_reading_include_anonymous_visitors_provided_none(self):
config = {
'include_anonymous_visitors': None
}

my_visitor = Visitors(config)

return_value = my_visitor.get_body()
expected_value = False
actual_value = not return_value['request']['pipeline'][0]['source']['visitors']['identified']
self.assertEqual(expected_value, actual_value)

def test_reading_include_anonymous_visitors_no_provided_input(self):
config = {}

my_visitor = Visitors(config)

return_value = my_visitor.get_body()
expected_value = False
actual_value = not return_value['request']['pipeline'][0]['source']['visitors']['identified']
self.assertEqual(expected_value, actual_value)

def test_reading_include_anonymous_visitors_provided_boolean_true(self):
config = {
'include_anonymous_visitors': True
}

my_visitor = Visitors(config)

return_value = my_visitor.get_body()
expected_value = True
actual_value = not return_value['request']['pipeline'][0]['source']['visitors']['identified']
self.assertEqual(expected_value, actual_value)

def test_reading_include_anonymous_visitors_provided_boolean_false(self):
config = {
'include_anonymous_visitors': False
}

my_visitor = Visitors(config)

return_value = my_visitor.get_body()
expected_value = False
actual_value = not return_value['request']['pipeline'][0]['source']['visitors']['identified']
self.assertEqual(expected_value, actual_value)