Skip to content

Commit

Permalink
setup tests for autorefresh; demonstrate current state works and futu…
Browse files Browse the repository at this point in the history
…re state doesn't work
  • Loading branch information
mikealfare committed Oct 25, 2023
1 parent db51b6e commit a92538a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/functional/adapter/materialized_view_tests/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,21 @@
record_valid_date
from {{ ref('my_seed') }}
"""


MY_MATERIALIZED_VIEW_AUTOREFRESH_ON = """
{{ config(
materialized='materialized_view',
enable_refresh=True,
) }}
select * from {{ ref('my_seed') }}
"""


MY_MATERIALIZED_VIEW_AUTOREFRESH_OFF = """
{{ config(
materialized='materialized_view',
enable_refresh=False,
) }}
select * from {{ ref('my_seed') }}
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from datetime import datetime

import pytest
from dbt.contracts.relation import RelationType
from dbt.tests.adapter.materialized_view.auto_refresh import (
MaterializedViewAutoRefreshNoChanges,
)

from dbt.adapters.bigquery.relation import BigQueryRelation

from tests.functional.adapter.materialized_view_tests import files


class TestMaterializedViewAutoRefreshNoChanges(MaterializedViewAutoRefreshNoChanges):
@pytest.fixture(scope="class", autouse=True)
def seeds(self):
yield {"my_seed.csv": files.MY_SEED}

@pytest.fixture(scope="class", autouse=True)
def models(self):
yield {
"auto_refresh_on.sql": files.MY_MATERIALIZED_VIEW_AUTOREFRESH_ON,
"auto_refresh_off.sql": files.MY_MATERIALIZED_VIEW_AUTOREFRESH_OFF,
}

def last_refreshed(self, project, materialized_view: str) -> datetime:
relation = BigQueryRelation.create(
database=project.database,
schema=project.test_schema,
identifier=materialized_view,
type=RelationType.MaterializedView,
)
with project.adapter.connection_named("__test"):
last_refresh_results = project.adapter.get_bq_table(relation)
return last_refresh_results.mview_last_refresh_time or last_refresh_results.created

0 comments on commit a92538a

Please sign in to comment.