-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
import json | ||
import pandas | ||
import pytest | ||
import sqlite3 | ||
from dbt.tests.util import ( | ||
check_relations_equal, | ||
run_dbt, | ||
) | ||
|
||
model_sql = """ | ||
{{ config(materialized='incremental', database='satest') }} | ||
select * from satest.tt1 | ||
""" | ||
|
||
|
||
class TestSQLitePlugin: | ||
|
||
@pytest.fixture(scope="class") | ||
def sqlite_test_db(self): | ||
path = '/tmp/satest.db' | ||
os.unlink(path) | ||
db = sqlite3.connect(path) | ||
cursor = db.cursor() | ||
cursor.execute("CREATE TABLE tt1 (id int, name text)") | ||
cursor.execute("INSERT INTO tt1 VALUES (1, 'John Doe')") | ||
cursor.execute("INSERT INTO tt1 VALUES (2, 'Jane Smith')") | ||
cursor.execute("CREATE TABLE test_table2 (a int, b int, c int)") | ||
cursor.execute("INSERT INTO test_table2 VALUES (1, 2, 3), (4, 5, 6)") | ||
cursor.close() | ||
db.commit() | ||
db.close() | ||
|
||
yield path | ||
|
||
@pytest.fixture(scope="class") | ||
def profiles_config_update(self, dbt_profile_target, sqlite_test_db): | ||
return { | ||
"test": { | ||
"outputs": { | ||
"dev": { | ||
"type": "duckdb", | ||
"path": dbt_profile_target.get("path", ":memory:"), | ||
"attach": [ | ||
{'path': sqlite_test_db} | ||
] | ||
} | ||
}, | ||
"target": "dev", | ||
} | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self, test_data_path): | ||
return { | ||
"read_write.sql": model_sql, | ||
|
||
} | ||
|
||
def test_sqlite_plugin(self, project): | ||
results = run_dbt() | ||
assert len(results) == 1 | ||
|
||
res = project.run_sql("SELECT COUNT(1) FROM satest.read_write", fetch="one") | ||
assert res[0] == 2 | ||
|
||
|