test_custom_materializations.py 3.3 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 check_relations_equal, run_dbt
  17. from fixtures import (
  18. actual_indexes,
  19. expected_indexes,
  20. test_materialized_view,
  21. test_materialized_view_index,
  22. test_materialized_view_retain_history,
  23. test_relation_name_length,
  24. test_sink,
  25. test_source,
  26. test_source_index,
  27. test_source_table,
  28. test_source_table_index,
  29. test_subsources,
  30. test_table_index,
  31. test_view_index,
  32. )
  33. class TestCustomMaterializations:
  34. @pytest.fixture(scope="class")
  35. def project_config_update(self):
  36. return {"name": "custom_materializations"}
  37. @pytest.fixture(scope="class")
  38. def seeds(self):
  39. return {
  40. "expected_indexes.csv": expected_indexes,
  41. }
  42. @pytest.fixture(scope="class")
  43. def models(self):
  44. return {
  45. "actual_indexes.sql": actual_indexes,
  46. "test_materialized_view.sql": test_materialized_view,
  47. "test_materialized_view_retain_history.sql": test_materialized_view_retain_history,
  48. "test_materialized_view_index.sql": test_materialized_view_index,
  49. "test_relation_name_loooooooooooooooooonger_than_postgres_63_limit.sql": test_relation_name_length,
  50. "test_source.sql": test_source,
  51. "test_source_index.sql": test_source_index,
  52. "test_source_table.sql": test_source_table,
  53. "test_source_table_index.sql": test_source_table_index,
  54. "test_subsources.sql": test_subsources,
  55. "test_sink.sql": test_sink,
  56. "test_table_index.sql": test_table_index,
  57. "test_view_index.sql": test_view_index,
  58. }
  59. def test_custom_materializations(self, project):
  60. # seed seeds
  61. results = run_dbt(["seed"])
  62. # seed result length
  63. assert len(results) == 1
  64. # run models
  65. results = run_dbt(["run"])
  66. # run result length
  67. assert len(results) == 13
  68. # re-run models to ensure there are no lingering errors in recreating
  69. # the materializations
  70. results = run_dbt(["run"])
  71. # re-run result length
  72. assert len(results) == 13
  73. # relations_equal
  74. check_relations_equal(
  75. project.adapter,
  76. ["test_materialized_view_index", "test_table_index"],
  77. )
  78. check_relations_equal(project.adapter, ["actual_indexes", "expected_indexes"])
  79. # TODO(morsapaes): add test that ensures that the source/sink emit the
  80. # correct data once sinks land.
  81. # From benesch: Ideally we'd just ingest the sink back into Materialize
  82. # with the source and then use `relations_equal` with `test_materialized_view`.