Skip to content

Commit

Permalink
move the job label test into its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Aug 10, 2023
1 parent 562a33b commit da3f530
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
46 changes: 46 additions & 0 deletions tests/functional/adapter/query_comment_test/test_job_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest

from google.cloud.bigquery.client import Client

from dbt.tests.util import run_dbt_and_capture


_MACRO__BQ_LABELS = """
{% macro bq_labels() %}{
"system": "{{ env_var('LABEL_SYSTEM', 'my_system') }}",
"env_type": "{{ env_var('LABEL_ENV', 'dev') }}",
}{% endmacro %}
"""
_MODEL__MY_TABLE = """
{{ config(materialized= "table") }}
select 1 as id
"""


class TestQueryCommentJobLabel:
@pytest.fixture(scope="class")
def models(self):
return {"my_table.sql": _MODEL__MY_TABLE}

@pytest.fixture(scope="class")
def macros(self):
return {"bq_labels.sql": _MACRO__BQ_LABELS}

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"query-comment": {
"comment": "{{ bq_labels() }}",
"job-label": True,
"append": True,
}
}

def test_query_comments_displays_as_job_labels(self, project):
results, logs = run_dbt_and_capture(["--debug", "run"])
job_id = results.results[0].adapter_response.get("job_id")
with project.adapter.connection_named("_test"):
client: Client = project.adapter.connections.get_thread_connection().handle
job = client.get_job(job_id=job_id)
assert job.labels.get("system") == "my_system"
assert job.labels.get("env_type") == "dev"
46 changes: 0 additions & 46 deletions tests/functional/adapter/query_comment_test/test_query_comment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import pytest

from google.cloud.bigquery.client import Client

from dbt.tests.adapter.query_comment.test_query_comment import (
BaseQueryComments,
BaseMacroQueryComments,
Expand All @@ -10,7 +6,6 @@
BaseNullQueryComments,
BaseEmptyQueryComments,
)
from dbt.tests.util import run_dbt_and_capture


class TestQueryCommentsBigQuery(BaseQueryComments):
Expand All @@ -35,44 +30,3 @@ class TestNullQueryCommentsBigQuery(BaseNullQueryComments):

class TestEmptyQueryCommentsBigQuery(BaseEmptyQueryComments):
pass


_MACRO__BQ_LABELS = """
{% macro bq_labels() %}{
"system": "{{ env_var('LABEL_SYSTEM', 'my_system') }}",
"env_type": "{{ env_var('LABEL_ENV', 'dev') }}",
}{% endmacro %}
"""
_MODEL__MY_TABLE = """
{{ config(materialized= "table") }}
select 1 as id
"""


class TestQueryCommentJobLabel:
@pytest.fixture(scope="class")
def models(self):
return {"my_table.sql": _MODEL__MY_TABLE}

@pytest.fixture(scope="class")
def macros(self):
return {"bq_labels.sql": _MACRO__BQ_LABELS}

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"query-comment": {
"comment": "{{ bq_labels() }}",
"job-label": True,
"append": True,
}
}

def test_query_comments_displays_as_job_labels(self, project):
results, logs = run_dbt_and_capture(["--debug", "run"])
job_id = results.results[0].adapter_response.get("job_id")
with project.adapter.connection_named("_test"):
client: Client = project.adapter.connections.get_thread_connection().handle
job = client.get_job(job_id=job_id)
assert job.labels.get("system") == "my_system"
assert job.labels.get("env_type") == "dev"

0 comments on commit da3f530

Please sign in to comment.