Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional testing #588

Merged
merged 36 commits into from
May 13, 2022
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
962f5ae
Initial functional testing
jtcohen6 May 3, 2022
b5b23f9
Skip BigQuery dateadd for now
dbeatty10 May 7, 2022
551c1c8
Split into one fixture and test per cross-database macro
dbeatty10 May 8, 2022
d59dac1
Move the skip decorator
dbeatty10 May 8, 2022
da58f27
Scaffolding for fixtures and tests
dbeatty10 May 8, 2022
3860605
Functional tests for any_value macro
dbeatty10 May 8, 2022
7bdaa49
Remove TODO
dbeatty10 May 8, 2022
2f17185
Functional tests for bool_or macro
dbeatty10 May 8, 2022
171a8e6
Functional tests for concat macro
dbeatty10 May 8, 2022
ce3bff2
Functional tests for date_trunc macro
dbeatty10 May 8, 2022
8a9cb50
Functional tests for hash macro
dbeatty10 May 8, 2022
10c845e
Functional tests for last_day macro
dbeatty10 May 8, 2022
6f3320c
Functional tests for length macro
dbeatty10 May 8, 2022
c3f6235
Functional tests for listagg macro
dbeatty10 May 8, 2022
7204519
Functional tests for position macro
dbeatty10 May 8, 2022
d421350
Functional tests for replace macro
dbeatty10 May 8, 2022
1bac8c8
Functional tests for right macro
dbeatty10 May 8, 2022
2521a6b
Functional tests for safe_cast macro
dbeatty10 May 8, 2022
0c3d208
Functional tests for split_part macro
dbeatty10 May 8, 2022
e11ccf0
Missing newline
dbeatty10 May 8, 2022
71375c4
Conform bool_or macro to actual/expected test pattern
dbeatty10 May 8, 2022
d4cbc0d
Conform any_value macro to actual/expected test pattern
dbeatty10 May 8, 2022
7e2ea34
Functional tests for current_timestamp macro
dbeatty10 May 8, 2022
de6e223
Remove extraneous newline
dbeatty10 May 8, 2022
1820d76
Functional tests for current_timestamp_in_utc macro
dbeatty10 May 8, 2022
e702f28
Functional tests for cast_bool_to_text macro
dbeatty10 May 8, 2022
ade997b
Functional tests for string_literal macro
dbeatty10 May 8, 2022
6b78b23
Functional tests for escape_single_quotes macro
dbeatty10 May 9, 2022
1618379
Functional tests for except macro
dbeatty10 May 9, 2022
2d386a2
Functional tests for intersect macro
dbeatty10 May 9, 2022
1161066
Fix scaffolded SQL so that tests can pass
dbeatty10 May 9, 2022
83af300
Postgres does not treat integers as booleans without casting
dbeatty10 May 9, 2022
fb8b406
Refactor test case override into the base class
dbeatty10 May 10, 2022
e565c9c
Refactor the two variants for escaping single quotes into two differe…
dbeatty10 May 10, 2022
3cbe0e6
Fix functional tests for dateadd macro for BigQuery
dbeatty10 May 10, 2022
10a935d
Merge branch 'main' into dbeatty/add-pytest-functional
dbeatty10 May 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Functional tests for except macro
  • Loading branch information
dbeatty10 committed May 9, 2022
commit 1618379e9f831249f8717549a9e9dd1a3e900a1f
71 changes: 50 additions & 21 deletions tests/functional/cross_db_utils/fixture_except.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,65 @@


# except

# TODO - implement expected results here
seeds__data_except_csv = """todo,result
TODO,1
seeds__data_except_a_csv = """id
1
2
3
"""

seeds__data_except_b_csv = """id
3
4
5
"""

models__test_except_sql = """
with data as (
seeds__data_except_a_minus_b_csv = """id
1
2
"""

seeds__data_except_b_minus_a_csv = """id
4
5
"""

select * from {{ ref('data_except') }}
models__data_except_empty_sql = """
select * from {{ ref('data_except_a') }}
where 0=1
"""

)
models__test_except_a_minus_b_sql = """
select * from {{ ref('data_except_a') }}
{{ dbt_utils.except() }}
select * from {{ ref('data_except_b') }}
"""

# TODO - implement actual logic here
select
models__test_except_b_minus_a_sql = """
select * from {{ ref('data_except_b') }}
{{ dbt_utils.except() }}
select * from {{ ref('data_except_a') }}
"""

1 actual,
result as expected
models__test_except_a_minus_a_sql = """
select * from {{ ref('data_except_a') }}
{{ dbt_utils.except() }}
select * from {{ ref('data_except_a') }}
"""

from data
models__test_except_a_minus_empty_sql = """
select * from {{ ref('data_except_a') }}
{{ dbt_utils.except() }}
select * from {{ ref('data_except_empty') }}
"""

models__test_except_empty_minus_a_sql = """
select * from {{ ref('data_except_empty') }}
{{ dbt_utils.except() }}
select * from {{ ref('data_except_a') }}
"""

models__test_except_yml = """
version: 2
models:
- name: test_except
tests:
- assert_equal:
actual: actual
expected: expected
models__test_except_empty_minus_empty_sql = """
select * from {{ ref('data_except_empty') }}
{{ dbt_utils.except() }}
select * from {{ ref('data_except_empty') }}
"""
61 changes: 53 additions & 8 deletions tests/functional/cross_db_utils/test_except.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,70 @@
import pytest
from dbt.tests.util import run_dbt, check_relations_equal
from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro
from tests.functional.cross_db_utils.fixture_except import (
seeds__data_except_csv,
models__test_except_sql,
models__test_except_yml,
seeds__data_except_a_csv,
seeds__data_except_b_csv,
seeds__data_except_a_minus_b_csv,
seeds__data_except_b_minus_a_csv,
models__data_except_empty_sql,
models__test_except_a_minus_b_sql,
models__test_except_b_minus_a_sql,
models__test_except_a_minus_a_sql,
models__test_except_a_minus_empty_sql,
models__test_except_empty_minus_a_sql,
models__test_except_empty_minus_empty_sql,
)


class BaseExcept(BaseCrossDbMacro):
@pytest.fixture(scope="class")
def seeds(self):
return {"data_except.csv": seeds__data_except_csv}
return {
"data_except_a.csv": seeds__data_except_a_csv,
"data_except_b.csv": seeds__data_except_b_csv,
"data_except_a_minus_b.csv": seeds__data_except_a_minus_b_csv,
"data_except_b_minus_a.csv": seeds__data_except_b_minus_a_csv,
}

@pytest.fixture(scope="class")
def models(self):
return {
"test_except.yml": models__test_except_yml,
"test_except.sql": models__test_except_sql,
"data_except_empty.sql": models__data_except_empty_sql,
"test_except_a_minus_b.sql": models__test_except_a_minus_b_sql,
"test_except_b_minus_a.sql": models__test_except_b_minus_a_sql,
"test_except_a_minus_a.sql": models__test_except_a_minus_a_sql,
"test_except_a_minus_empty.sql": models__test_except_a_minus_empty_sql,
"test_except_empty_minus_a.sql": models__test_except_empty_minus_a_sql,
"test_except_empty_minus_empty.sql": models__test_except_empty_minus_empty_sql,
}


@pytest.mark.skip(reason="TODO - implement this test")
class TestExcept(BaseExcept):
pass
def test_build_assert_equal(self, project):
run_dbt(['deps'])
run_dbt(['build'])

check_relations_equal(
project.adapter,
["test_except_a_minus_b", "data_except_a_minus_b"],
)
check_relations_equal(
project.adapter,
["test_except_b_minus_a", "data_except_b_minus_a"],
)
check_relations_equal(
project.adapter,
["test_except_a_minus_a", "data_except_empty"],
)
check_relations_equal(
project.adapter,
["test_except_a_minus_empty", "data_except_a"],
)
check_relations_equal(
project.adapter,
["test_except_empty_minus_a", "data_except_empty"],
)
check_relations_equal(
project.adapter,
["test_except_empty_minus_empty", "data_except_empty"],
)