test_seed.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.simple_seed.test_seed import (
  17. SeedConfigBase,
  18. )
  19. from dbt.tests.adapter.simple_seed.test_seed_type_override import (
  20. BaseSimpleSeedColumnOverride,
  21. )
  22. from dbt.tests.util import run_dbt
  23. _SCHEMA_YML = """
  24. version: 2
  25. seeds:
  26. - name: seed_enabled
  27. columns:
  28. - name: birthday
  29. tests:
  30. - column_type:
  31. type: text
  32. - name: seed_id
  33. tests:
  34. - column_type:
  35. type: integer
  36. - name: seed_tricky
  37. columns:
  38. - name: seed_id
  39. tests:
  40. - column_type:
  41. type: integer
  42. - name: seed_id_str
  43. tests:
  44. - column_type:
  45. type: text
  46. - name: a_bool
  47. tests:
  48. - column_type:
  49. type: boolean
  50. - name: looks_like_a_bool
  51. tests:
  52. - column_type:
  53. type: text
  54. - name: a_date
  55. tests:
  56. - column_type:
  57. type: timestamp without time zone
  58. - name: looks_like_a_date
  59. tests:
  60. - column_type:
  61. type: text
  62. - name: relative
  63. tests:
  64. - column_type:
  65. type: text
  66. - name: weekday
  67. tests:
  68. - column_type:
  69. type: text
  70. """.lstrip()
  71. class TestSimpleBigSeedBatched(SeedConfigBase):
  72. @pytest.fixture(scope="class")
  73. def seeds(self):
  74. seed_data = ["seed_id"]
  75. seed_data.extend([str(i) for i in range(20_000)])
  76. return {"big_batched_seed.csv": "\n".join(seed_data)}
  77. def test_big_batched_seed(self, project):
  78. seed_results = run_dbt(["seed"])
  79. assert len(seed_results) == 1
  80. class TestSimpleSeedColumnOverride(BaseSimpleSeedColumnOverride):
  81. @pytest.fixture(scope="class")
  82. def schema(self):
  83. return "simple_seed"
  84. @pytest.fixture(scope="class")
  85. def models(self):
  86. return {"models-materialize.yml": _SCHEMA_YML}
  87. @staticmethod
  88. def seed_enabled_types():
  89. return {
  90. "birthday": "text",
  91. "seed_id": "integer",
  92. }
  93. def test_materialize_simple_seed_with_column_override_materialize(self, project):
  94. seed_results = run_dbt(["seed"])
  95. assert len(seed_results) == 2
  96. test_results = run_dbt(["test"])
  97. assert len(test_results) == 10