-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for Tableau dashboard extractor
Signed-off-by: Carter Landis <carter.landis@gusto.com>
- Loading branch information
1 parent
1fae563
commit d7b9bb8
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
tests/unit/extractor/dashboard/tableau/test_tableau_dashboard_extractor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright Contributors to the Amundsen project. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import logging | ||
import unittest | ||
|
||
from mock import patch | ||
from pyhocon import ConfigFactory # noqa: F401 | ||
|
||
from databuilder import Scoped | ||
from databuilder.extractor.dashboard.tableau.tableau_dashboard_extractor import TableauDashboardExtractor | ||
from databuilder.extractor.dashboard.tableau.tableau_dashboard_utils import TableauDashboardAuth, TableauDashboardUtils, TableauGraphQLApiExtractor | ||
from databuilder.models.dashboard.dashboard_last_modified import DashboardLastModifiedTimestamp | ||
from databuilder.models.dashboard.dashboard_owner import DashboardOwner | ||
from databuilder.models.dashboard.dashboard_query import DashboardQuery | ||
from databuilder.models.dashboard.dashboard_table import DashboardTable | ||
|
||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
def mock_query(*args, **kwargs): | ||
return { | ||
'workbooks': [ | ||
{ | ||
'id': 'fake-id', | ||
'name': 'Test Workbook', | ||
'createdAt': '2020-04-08T05:32:01Z', | ||
'description': '', | ||
'projectName': 'Test Project', | ||
'projectVizportalUrlId': 123, | ||
'vizportalUrlId': 456 | ||
} | ||
] | ||
} | ||
|
||
def mock_token(*args, **kwargs): | ||
return '123-abc' | ||
|
||
class TestTableauDashboardExtractor(unittest.TestCase): | ||
|
||
@patch.object(TableauDashboardAuth, '_authenticate', mock_token) | ||
@patch.object(TableauGraphQLApiExtractor, 'execute_query', mock_query) | ||
def test_dashboard_metadata_extractor(self): | ||
|
||
config = ConfigFactory.from_dict({ | ||
'extractor.tableau_dashboard_metadata.tableau_host': 'tableau_host', | ||
'extractor.tableau_dashboard_metadata.api_version': 'tableau_api_version', | ||
'extractor.tableau_dashboard_metadata.site_name': 'tableau_site_name', | ||
'extractor.tableau_dashboard_metadata.tableau_personal_access_token_name': | ||
'tableau_personal_access_token_name', | ||
'extractor.tableau_dashboard_metadata.tableau_personal_access_token_secret': | ||
'tableau_personal_access_token_secret', | ||
'extractor.tableau_dashboard_metadata.excluded_projects': [], | ||
'extractor.tableau_dashboard_metadata.cluster': 'tableau_dashboard_cluster', | ||
'extractor.tableau_dashboard_metadata.database': 'tableau_dashboard_database', | ||
'extractor.tableau_dashboard_metadata.transformer.timestamp_str_to_epoch.timestamp_format': | ||
'%Y-%m-%dT%H:%M:%SZ', | ||
|
||
}) | ||
|
||
extractor = TableauDashboardExtractor() | ||
extractor.init(Scoped.get_scoped_conf(conf=config, scope=extractor.get_scope())) | ||
record = extractor.extract() | ||
|
||
self.assertEqual(record.dashboard_id, 'Test Workbook') | ||
self.assertEqual(record.dashboard_name, 'Test Workbook') | ||
self.assertEqual(record.dashboard_group_id, 'Test Project') | ||
self.assertEqual(record.dashboard_group, 'Test Project') | ||
self.assertEqual(record.product, 'tableau') | ||
self.assertEqual(record.cluster, 'tableau_dashboard_cluster') | ||
self.assertEqual(record.created_timestamp, 1586323921) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |