test_source_freshness.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License in the LICENSE file at the
  6. # root of this repository, or online at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import pytest
  16. from dbt.cli.main import dbtRunner
  17. freshness_via_metadata_schema_yml = """version: 2
  18. sources:
  19. - name: test_source
  20. loader: custom
  21. freshness:
  22. warn_after: {count: 10, period: hour}
  23. error_after: {count: 1, period: day}
  24. schema: my_schema
  25. quoting:
  26. identifier: True
  27. tables:
  28. - name: test_table
  29. identifier: source
  30. """
  31. class TestMetadataFreshnessFails:
  32. @pytest.fixture(scope="class")
  33. def models(self):
  34. return {"schema.yml": freshness_via_metadata_schema_yml}
  35. # We mark TableLastModifiedMetadata as not implemented, so trying to use metadata-based source freshness checks should result in a parse-time warning.
  36. def test_metadata_freshness_fails(self, project):
  37. got_warning = False
  38. def warning_probe(e):
  39. nonlocal got_warning
  40. if e.info.name == "FreshnessConfigProblem" and e.info.level == "warn":
  41. got_warning = True
  42. runner = dbtRunner(callbacks=[warning_probe])
  43. runner.invoke(["parse"])
  44. assert got_warning