def test_should_create_simple_view(self, temp_dir: Path, delete_views_or_tables_mock: MagicMock): view_config_path = temp_dir / 'views.yml' view_config_path.write_text('\n'.join(['- view1'])) main([ 'delete-views', '--dataset=dataset1', '--view-list-config=%s' % view_config_path ]) delete_views_or_tables_mock.assert_called()
def test_should_materialize_simple_view(self, temp_dir: Path, materialize_views_mock: MagicMock): view_config_path = temp_dir / 'views.yml' view_config_path.write_text('\n'.join( ['- view1:', ' materialize: true'])) main([ 'materialize-views', '--dataset=dataset1', '--view-list-config=%s' % view_config_path ]) materialize_views_mock.assert_called()
def test_should_delete_materialized_tables( self, temp_dir: Path, delete_views_or_tables_mock: MagicMock): view_config_path = temp_dir / 'views.yml' view_config_path.write_text('\n'.join( ['- view1:', ' materialize: true'])) main([ 'delete-materialized-tables', '--dataset=dataset1', '--view-list-config=%s' % view_config_path ]) delete_views_or_tables_mock.assert_called()
def test_should_sort_view_list(self, temp_dir: Path): view_config_path = temp_dir / 'views.yml' view_config_path.write_text('\n'.join( ['- view1', '- view2:', ' materialize: true'])) (temp_dir / 'view1.sql').write_text('SELECT * FROM `{project}.{dataset}.mview2`') (temp_dir / 'view2.sql').write_text('SELECT 1') main([ 'sort-view-list', '--dataset=dataset1', '--view-list-config=%s' % view_config_path ]) assert load_view_list_config(view_config_path).view_names == [ 'view2', 'view1' ]
import logging from bigquery_views_manager.cli import main if __name__ == "__main__": logging.basicConfig(level="INFO") main()