test_data_tests.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.util import run_dbt
  17. from fixtures import not_null, test_materialized_view, unique
  18. class TestDataTest:
  19. @pytest.fixture(scope="class")
  20. def project_config_update(self):
  21. return {"name": "data_tests"}
  22. @pytest.fixture(scope="class")
  23. def models(self):
  24. return {
  25. "test_materialized_view.sql": test_materialized_view,
  26. }
  27. @pytest.fixture(scope="class")
  28. def tests(self):
  29. return {
  30. "unique.sql": unique,
  31. "not_null.sql": not_null,
  32. }
  33. def test_store_failures(self, project):
  34. # run models
  35. results = run_dbt(["run"])
  36. # run result length
  37. assert len(results) == 1
  38. results = run_dbt(["test"], expect_pass=False) # expect failing test
  39. assert len(results) == 2
  40. result_statuses = sorted(r.status for r in results)
  41. assert result_statuses == ["fail", "pass"]
  42. class TestDataTestCluster:
  43. @pytest.fixture(scope="class")
  44. def project_config_update(self):
  45. return {
  46. "name": "data_tests",
  47. "tests": {
  48. "test": {
  49. "+store_failures": True,
  50. "+schema": "etl_failure",
  51. "+cluster": "not_default_test",
  52. },
  53. },
  54. }
  55. @pytest.fixture(scope="class")
  56. def models(self):
  57. return {
  58. "test_materialized_view.sql": test_materialized_view,
  59. }
  60. @pytest.fixture(scope="class")
  61. def tests(self):
  62. return {
  63. "unique.sql": unique,
  64. }
  65. def test_store_failures_cluster(self, project):
  66. project.run_sql("CREATE CLUSTER not_default_test SIZE = '1'")
  67. # run models
  68. results = run_dbt(["run"])
  69. # run result length
  70. assert len(results) == 1
  71. results = run_dbt(["test"])
  72. assert len(results) == 1
  73. result_statuses = sorted(r.status for r in results)
  74. assert result_statuses == ["pass"]