test_model_hooks.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.tests.adapter.hooks import test_model_hooks as core_base
  17. from fixtures import model_hook, test_hooks
  18. class TestPrePostModelHooksMaterialize(core_base.TestPrePostModelHooks):
  19. @pytest.fixture(scope="class", autouse=True)
  20. def setUp(self, project):
  21. project.run_sql(f"drop table if exists { project.test_schema }.on_model_hook")
  22. project.run_sql(model_hook.format(schema=project.test_schema))
  23. @pytest.fixture(scope="class")
  24. def project_config_update(self):
  25. return test_hooks
  26. def check_hooks(self, state, project, host, count=1):
  27. self.get_ctx_vars(state, count=count, project=project)
  28. class TestPrePostModelHooksUnderscoresMaterialize(
  29. core_base.TestPrePostModelHooksUnderscores
  30. ):
  31. @pytest.fixture(scope="class", autouse=True)
  32. def setUp(self, project):
  33. project.run_sql(f"drop table if exists { project.test_schema }.on_model_hook")
  34. project.run_sql(model_hook.format(schema=project.test_schema))
  35. @pytest.fixture(scope="class")
  36. def project_config_update(self):
  37. return test_hooks
  38. def check_hooks(self, state, project, host, count=1):
  39. self.get_ctx_vars(state, count=count, project=project)
  40. class TestHookRefsMaterialize(core_base.TestHookRefs):
  41. @pytest.fixture(scope="class", autouse=True)
  42. def setUp(self, project):
  43. project.run_sql(f"drop table if exists { project.test_schema }.on_model_hook")
  44. project.run_sql(model_hook.format(schema=project.test_schema))
  45. def check_hooks(self, state, project, host, count=1):
  46. self.get_ctx_vars(state, count=count, project=project)