"""Tests for pipelines.""" from unittest.mock import patch from tests import helpers import pipelines @patch('look_tools.update_look') @patch('look_tools.check_look_on_client_instance') @patch('query_tools.sync_query') @patch('look_tools.get_look_json') def test_sync_look_update( get_look_json, sync_query, check_look_on_client_instance, update_look): """Assert update is called when such a look exists on client instance.""" get_look_json.return_value = helpers.look_json sync_query.return_value = 15 check_look_on_client_instance.return_value = 27 update_look.return_value = True result = pipelines.sync_look(42) update_look.assert_called() assert result is True @patch('look_tools.post_look_to_client_instance') @patch('look_tools.check_look_on_client_instance') @patch('query_tools.sync_query') @patch('look_tools.get_look_json') def test_sync_look_post( get_look_json, sync_query, check_look_on_client_instance, post_look_to_client_instance): """Assert post is called when there is no such look on client instance.""" get_look_json.return_value = helpers.look_json sync_query.return_value = 15 check_look_on_client_instance.return_value = False post_look_to_client_instance.return_value = True result = pipelines.sync_look(42) post_look_to_client_instance.assert_called() assert result is True @patch('look_tools.get_look_json') def test_sync_look_negative(get_look_json): """Return False.""" get_look_json.return_value = False result = pipelines.sync_look(42) assert result is False @patch('github_tools.sync_git_model') def test_git_files_model_sync_negative(sync_git_model): """Return False.""" sync_git_model.return_value = False model = helpers.model_input filter = model.get('new_access_filter') remove = model.get('remove_access_filter_join') connect = model.get('connection') result = pipelines.git_files_model_sync( 'name', {'json': True}, filter, remove, connect) assert result is False @patch('github_tools.complete_views_sync') @patch('model_tools.get_set_of_views_for_explore') @patch('model_tools.get_set_of_explore_names') @patch('github_tools.sync_git_model') def test_git_files_model_sync_positive( sync_git_model, get_set_of_explore_names, get_set_of_views_for_explore, complete_views_sync): """Call sync_git_model, get_set_of_explore_names, get_set_of_views_for_explore, complete_views_sync. Return True""" sync_git_model.return_value = True get_set_of_explore_names.return_value = {'explore_name'} get_set_of_views_for_explore.return_value = helpers.view_names complete_views_sync.return_value = True model = helpers.model_input filter = model.get('new_access_filter') remove = model.get('remove_access_filter_join') connect = model.get('connection') result = pipelines.git_files_model_sync( 'name', {'json': True}, filter, remove, connect) sync_git_model.assert_called() get_set_of_explore_names.assert_called() get_set_of_views_for_explore.assert_called() complete_views_sync.assert_called() assert result is True @patch('model_tools.get_main_instance_model_json') def test_full_sync_model_no_model(get_main_instance_model_json): """Return False.""" get_main_instance_model_json.return_value = False model = helpers.model_input result = pipelines.full_sync_model(model) assert result is False @patch('pipelines.git_files_model_sync') @patch('model_tools.get_main_instance_model_json') def test_full_sync_model_files_not_synced( get_main_instance_model_json, git_files_model_sync): """Return False.""" get_main_instance_model_json.return_value = True git_files_model_sync.return_value = False model = helpers.model_input result = pipelines.full_sync_model(model) assert result is False @patch('model_tools.sync_lookml_model') @patch('pipelines.git_files_model_sync') @patch('model_tools.get_main_instance_model_json') def test_full_sync_model_positive( get_main_instance_model_json, git_files_model_sync, sync_lookml_model): """Return True.""" get_main_instance_model_json.return_value = True git_files_model_sync.return_value = True sync_lookml_model.return_value = True model = helpers.model_input result = pipelines.full_sync_model(model) get_main_instance_model_json.assert_called() git_files_model_sync.assert_called() sync_lookml_model.assert_called() assert result is True @patch('dashboard_tools.post_dashboard_element') @patch('dashboard_tools.adjust_dashboard_element_json') @patch('query_tools.sync_query') def test_sync_dashboard_element_query_positive( sync_query, adjust_dashboard_element_json, post_dashboard_element): """Call sync query, adjust, post.""" sync_query.return_value = 14 adjust_dashboard_element_json.return_value = True post_dashboard_element.return_value = True pipelines.sync_dashboard_element({'query_id': '15'}, 64) sync_query.assert_called() adjust_dashboard_element_json.assert_called() post_dashboard_element.assert_called() @patch('dashboard_tools.post_dashboard_element') @patch('dashboard_tools.adjust_dashboard_element_json') @patch('pipelines.sync_look') def test_sync_dashboard_element_look_positive( sync_look, adjust_dashboard_element_json, post_dashboard_element): """Call sync look, adjust, post.""" sync_look.return_value = 15 adjust_dashboard_element_json.return_value = True post_dashboard_element.return_value = True pipelines.sync_dashboard_element({'look_id': 55}, 64) sync_look.assert_called() adjust_dashboard_element_json.assert_called() post_dashboard_element.assert_called() @patch('dashboard_tools.update_layout_component') @patch('pipelines.sync_dashboard_element') @patch('dashboard_tools.get_dashboard_element_json') @patch('dashboard_tools.get_all_dashboard_layout_components') @patch('dashboard_tools.update_dashboard_layout') @patch('dashboard_tools.delete_dashboard_element') @patch('dashboard_tools.sync_dashboard_filters') @patch('dashboard_tools.get_list_of_dashboard_filters') @patch('dashboard_tools.update_client_dashboard') @patch('dashboard_tools.check_dashboard_on_client_instance') @patch('dashboard_tools.get_dashboard_json') def test_full_sync_dashboard_client_positive( get_dashboard_json, check_dashboard_on_client_instance, update_client_dashboard, get_list_of_dashboard_filters, sync_dashboard_filters, delete_dashboard_element, update_dashboard_layout, get_all_dashboard_layout_components, get_dashboard_element_json, sync_dashboard_element, update_layout_component ): """Pipeline for when client dashboard already exists.""" get_dashboard_json.return_value = helpers.dashboard_json check_dashboard_on_client_instance.return_value = 50 update_client_dashboard.return_value = helpers.dashboard_json get_list_of_dashboard_filters.return_value = True sync_dashboard_filters.return_value = True delete_dashboard_element.return_value = True update_dashboard_layout.return_value = True get_all_dashboard_layout_components.return_value =\ helpers.list_of_layout_components get_dashboard_element_json.return_value = helpers.dashboard_element sync_dashboard_element.return_value = 99 update_layout_component.return_value = True pipelines.full_sync_dashboard(5) get_dashboard_json.assert_called() check_dashboard_on_client_instance.assert_called() update_client_dashboard.assert_called() get_list_of_dashboard_filters.assert_called() sync_dashboard_filters.assert_called() delete_dashboard_element.assert_called() update_dashboard_layout.assert_called() get_all_dashboard_layout_components.assert_called() get_all_dashboard_layout_components.assert_called() get_dashboard_element_json.assert_called() sync_dashboard_element.assert_called() update_layout_component.assert_called() @patch('dashboard_tools.update_layout_component') @patch('pipelines.sync_dashboard_element') @patch('dashboard_tools.get_dashboard_element_json') @patch('dashboard_tools.get_all_dashboard_layout_components') @patch('dashboard_tools.update_dashboard_layout') @patch('dashboard_tools.delete_dashboard_element') @patch('dashboard_tools.sync_dashboard_filters') @patch('dashboard_tools.post_dashboard') @patch('dashboard_tools.check_dashboard_on_client_instance') @patch('dashboard_tools.get_dashboard_json') def test_full_sync_dashboard_client_negative( get_dashboard_json, check_dashboard_on_client_instance, post_dashboard, sync_dashboard_filters, delete_dashboard_element, update_dashboard_layout, get_all_dashboard_layout_components, get_dashboard_element_json, sync_dashboard_element, update_layout_component ): """Pipeline for when client dashboard doesn't exists beforehand.""" get_dashboard_json.return_value = helpers.dashboard_json check_dashboard_on_client_instance.return_value = False post_dashboard.return_value = helpers.dashboard_json sync_dashboard_filters.return_value = True delete_dashboard_element.return_value = True update_dashboard_layout.return_value = True get_all_dashboard_layout_components.return_value =\ helpers.list_of_layout_components get_dashboard_element_json.return_value = helpers.dashboard_element sync_dashboard_element.return_value = 99 update_layout_component.return_value = True pipelines.full_sync_dashboard(5) get_dashboard_json.assert_called() check_dashboard_on_client_instance.assert_called() post_dashboard.assert_called() sync_dashboard_filters.assert_called() delete_dashboard_element.assert_called() update_dashboard_layout.assert_called() get_all_dashboard_layout_components.assert_called() get_all_dashboard_layout_components.assert_called() get_dashboard_element_json.assert_called() sync_dashboard_element.assert_called() update_layout_component.assert_called()