Skip to content

Commit

Permalink
setup test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Jul 12, 2024
1 parent 1193a79 commit 8249543
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/functional/adapter/python_model_tests/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
27 changes: 27 additions & 0 deletions tests/functional/adapter/python_model_tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit 8249543

Please sign in to comment.