Skip to content

Commit

Permalink
Tests: Add test case using a CSV data seed
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Dec 21, 2024
1 parent 4a5d3b2 commit c6f3a95
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/functional/adapter/test_cratedb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pprint import pprint

import pytest
from dbt.tests.adapter.simple_snapshot import common

Expand Down Expand Up @@ -39,6 +41,13 @@
SELECT TRUE
"""

seed_mini = """
id,name,some_date
1,Easton,1981-05-20T06:46:51
2,Lillian,1978-09-03T18:10:33
3,Jeremiah,1982-03-11T03:59:51
"""


reset_csv_table = """
{# Create a random table. #}
Expand All @@ -59,19 +68,29 @@
SELECT TRUE
"""

select_from_seed = """
{% set seed_mini = ref('seed_mini') %}
SELECT * FROM {{ seed_mini }}
"""


class TestCrateDB:
"""
A few test cases for specifically validating concerns of CrateDB.
"""

@pytest.fixture(scope="class")
def seeds(self):
return {"seed_mini.csv": seed_mini}

@pytest.fixture(scope="class")
def models(self):
return {
"basic.sql": basic_sql,
"rename_table.sql": rename_table_sql,
"rename_view.sql": rename_view_sql,
"reset_csv_table.sql": reset_csv_table,
"select_from_seed.sql": select_from_seed,
}

@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -134,3 +153,23 @@ def test_reset_csv(self, project):

records = common.get_records(project, "reset_csv_table")
assert records == [(True,)]

def test_seed(self, project):
"""
Verify seeding works well, even when called twice.
"""

result = run_dbt(["seed", "--select", "seed_mini"])
assert len(result) == 1
result = run_dbt(["seed", "--select", "seed_mini"])
assert len(result) == 1

result = run_dbt(["run", "--select", "select_from_seed"])
assert len(result) == 1

records = common.get_records(project, "select_from_seed")
# TODO: Is it really correct to receive four records here,
# where the header definition is apparently included?
assert len(records) == 4
assert ("id", "name", "some_date") in records
assert ("1", "Easton", "1981-05-20T06:46:51") in records

0 comments on commit c6f3a95

Please sign in to comment.