From 824954322095dc3b6be6c03a441d16eb0bb0df7a Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Fri, 12 Jul 2024 14:43:57 -0400 Subject: [PATCH] setup test --- .../adapter/python_model_tests/_files.py | 21 +++++++++++++++ .../python_model_tests/test_logging.py | 27 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/functional/adapter/python_model_tests/test_logging.py diff --git a/tests/functional/adapter/python_model_tests/_files.py b/tests/functional/adapter/python_model_tests/_files.py index dd69f37fa..fe19edbb4 100644 --- a/tests/functional/adapter/python_model_tests/_files.py +++ b/tests/functional/adapter/python_model_tests/_files.py @@ -46,3 +46,24 @@ def model(dbt, session): {% do return(_table) %} {% endmacro %} """ + + +MODEL__LOGGING = """ +import logging + +import snowflake.snowpark as snowpark +import snowflake.snowpark.functions as f +from snowflake.snowpark.functions import * + + +logger = logging.getLogger("dbt_logger") +logger.info("******Inside Logging module.******") + + +def model(dbt, session): + session.sql(f"ALTER SESSION SET LOG_LEVEL = INFO").collect() + logger.info("******Logging start.******") + df=session.sql(f"select current_user() as session_user, current_role() as session_role") + logger.info("******Logging End.******") + return df +""" diff --git a/tests/functional/adapter/python_model_tests/test_logging.py b/tests/functional/adapter/python_model_tests/test_logging.py new file mode 100644 index 000000000..461eebd47 --- /dev/null +++ b/tests/functional/adapter/python_model_tests/test_logging.py @@ -0,0 +1,27 @@ +from dbt.tests.util import run_dbt +import pytest + +from tests.functional.adapter.python_model_tests._files import MODEL__LOGGING + +EVENT_TABLE_SQL = """ +SELECT + RECORD['severity_text']::STRING AS log_level, + VALUE::STRING AS message, + RESOURCE_ATTRIBUTES['snow.query.id']::STRING AS query_id +FROM + DXRX_OPERATIONS.LOGGING.EVENTS +WHERE + SCOPE['name']::STRING = 'dbt_logger' +ORDER BY + 'TIMESTAMP' DESC +; +""" + + +class TestPythonModelLogging: + @pytest.fixture(scope="class") + def models(self): + return {"logging_model.py": MODEL__LOGGING} + + def test_logging(self, project): + run_dbt(["run"])