From 01b5cfa9ed00e70f5f53ad44792f3db29dd3bc2d Mon Sep 17 00:00:00 2001 From: Anna Scholtz Date: Tue, 19 Nov 2024 16:34:22 -0800 Subject: [PATCH] add test --- tests/cli/test_cli_query.py | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/cli/test_cli_query.py b/tests/cli/test_cli_query.py index 4a59e250aa..1be7ee3cd2 100644 --- a/tests/cli/test_cli_query.py +++ b/tests/cli/test_cli_query.py @@ -870,3 +870,51 @@ class TestQuery: ) mock_get_id_token.assert_called_once() mock_get_credentials.assert_called_once() + + @patch("bigquery_etl.cli.query.get_credentials") + @patch("bigquery_etl.cli.query.get_id_token") + @patch("bigquery_etl.cli.query.deploy_table") + def test_prevent_deploy_for_views( + self, mock_deploy_table, mock_get_id_token, mock_get_credentials, runner + ): + mock_deploy_table.return_value = None + mock_get_id_token.return_value = None + mock_get_credentials.return_value = None + + with runner.isolated_filesystem(): + os.makedirs("sql/moz-fx-data-shared-prod/telemetry_derived/query_v1") + with open( + "sql/moz-fx-data-shared-prod/telemetry_derived/query_v1/view.sql", "w" + ) as f: + f.write("SELECT 1") + + with open( + "sql/moz-fx-data-shared-prod/telemetry_derived/query_v1/schema.yaml", + "w", + ) as f: + f.write( + """ + fields: + - name: x + type: INTEGER + mode: NULLABLE + """ + ) + + metadata_conf = { + "friendly_name": "test", + "description": "test", + "owners": ["test@example.org"], + "scheduling": {"dag_name": "bqetl_test"}, + "labels": {"test": 123, "foo": "abc", "review_bugs": [1234, 1254]}, + } + + with open( + "sql/moz-fx-data-shared-prod/telemetry_derived/query_v1/metadata.yaml", + "w", + ) as f: + f.write(yaml.dump(metadata_conf)) + result = runner.invoke(deploy, ["telemetry_derived.query_v1"]) + + assert result.exit_code == 0 + mock_deploy_table.assert_not_called()