Skip to content

Commit 39ebdae

Browse files
authored
Add more integration tests (#23)
* Create tests for secondary calc aliases * Add first count of orders by year test * Remove trailing line in csv * Add test breaking down by payment type, handle null dims * Auto update table of contents * sort seed lines * Add uniqueness tests * Add week test * hardcode dependencies * Customise calendar - custom first day of week for BQ * Fix for redshift being a baby can't cast a bool to a string idk why * Forgot the namespacing * maybe weeks work now? * only aggregate relevant data! * switch join to be a = b or a is null and b is null * Abandon plan to precisely respect start date flag on weeks I was doing all sorts of gymnastics to give you what you probably meant, not precisely what you asked for. But it was creating chaos in other areas so I'm backing out Co-authored-by: joellabes <joellabes@users.noreply.github.com>
1 parent ebab03e commit 39ebdae

20 files changed

Lines changed: 1389 additions & 3 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* [Experimental behaviour](#-experimental-behaviour)
2222
* [Dimensions on calendar tables](#dimensions-on-calendar-tables)
2323

24-
<!-- Added by: runner, at: Mon Feb 28 20:38:53 UTC 2022 -->
24+
<!-- Added by: runner, at: Tue Mar 8 00:53:06 UTC 2022 -->
2525

2626
<!--te-->
2727

integration_tests/analyses/.gitkeep

Whitespace-only changes.

integration_tests/dbt_project.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ clean-targets:
2020
- "target"
2121
- "dbt_packages"
2222
- "logs"
23+
24+
vars:
25+
dbt_metrics_calendar_model: ref('custom_calendar')
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
version: 2
2+
3+
models:
4+
- name: input_count_orders_by_week_bounded
5+
tests:
6+
- dbt_utils.equality:
7+
compare_model: ref('expected_count_orders_by_week_bounded')
8+
columns:
9+
- name: period
10+
tests:
11+
- unique
12+
- name: count_orders
13+
tests:
14+
- dbt_expectations.expect_column_sum_to_be_between:
15+
min_value: 980
16+
max_value: 980
17+
18+
- name: input_count_orders_by_week
19+
tests:
20+
- dbt_utils.equality:
21+
compare_model: ref('expected_count_orders_by_week')
22+
columns:
23+
- name: period
24+
tests:
25+
- unique
26+
- name: count_orders
27+
tests:
28+
- dbt_expectations.expect_column_sum_to_be_between:
29+
min_value: 1000
30+
max_value: 1000
31+
32+
- name: input_count_orders_by_year
33+
tests:
34+
- dbt_utils.equality:
35+
compare_model: ref('expected_count_orders_by_year')
36+
columns:
37+
- name: period
38+
tests:
39+
- unique
40+
- name: count_orders
41+
tests:
42+
- dbt_expectations.expect_column_sum_to_be_between:
43+
min_value: 1000
44+
max_value: 1000
45+
46+
- name: input_count_orders_by_year_and_payment_type
47+
tests:
48+
- dbt_utils.equality:
49+
compare_model: ref('expected_count_orders_by_year_and_payment_type')
50+
- dbt_utils.unique_combination_of_columns:
51+
combination_of_columns:
52+
- period
53+
- payment_type
54+
columns:
55+
- name: count_orders
56+
tests:
57+
- dbt_expectations.expect_column_sum_to_be_between:
58+
min_value: 1000
59+
max_value: 1000
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- depends on: {{ ref('mock_purchase_data') }}
2+
3+
select * from {{
4+
metrics.metric(
5+
'count_orders',
6+
'week'
7+
)
8+
}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- depends on: {{ ref('mock_purchase_data') }}
2+
3+
select * from {{
4+
metrics.metric(
5+
'count_orders',
6+
'week',
7+
start_date='2021-02-17',
8+
end_date='2023-01-01'
9+
)
10+
}}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- depends on: {{ ref('mock_purchase_data') }}
2+
3+
select * from {{
4+
metrics.metric(
5+
'count_orders',
6+
'year'
7+
)
8+
}}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- depends on: {{ ref('mock_purchase_data') }}
2+
3+
select * from {{
4+
metrics.metric(
5+
'count_orders',
6+
'year',
7+
dimensions=['payment_type']
8+
)
9+
}}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{{ config(materialized='table') }}
2+
3+
with days as (
4+
{{ dbt_utils.date_spine(
5+
datepart="day",
6+
start_date="cast('2010-01-01' as date)",
7+
end_date="cast('2030-01-01' as date)"
8+
)
9+
}}
10+
),
11+
12+
final as (
13+
select
14+
cast(date_day as date) as date_day,
15+
{% if target.type == 'bigquery' %}
16+
--BQ starts its weeks on Sunday. I don't actually care which day it runs on for auto testing purposes, just want it to be consistent with the other seeds
17+
cast({{ dbt_utils.date_trunc('week(MONDAY)', 'date_day') }} as date) as date_week,
18+
{% else %}
19+
cast({{ dbt_utils.date_trunc('week', 'date_day') }} as date) as date_week,
20+
{% endif %}
21+
cast({{ dbt_utils.date_trunc('month', 'date_day') }} as date) as date_month,
22+
cast({{ dbt_utils.date_trunc('quarter', 'date_day') }} as date) as date_quarter,
23+
cast({{ dbt_utils.date_trunc('year', 'date_day') }} as date) as date_year
24+
from days
25+
)
26+
27+
select * from final
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: 2
2+
metrics:
3+
- name: count_orders
4+
label: Count orders
5+
model: ref('mock_purchase_data')
6+
7+
type: count
8+
sql: "*"
9+
timestamp: purchased_at
10+
time_grains: [day, week, month, quarter, year]
11+
12+
dimensions:
13+
- payment_type
14+
15+
- name: sum_order_revenue
16+
label: Total order revenue
17+
model: ref('mock_purchase_data')
18+
19+
type: sum
20+
sql: "payment_total"
21+
timestamp: purchased_at
22+
time_grains: [day, week, month, quarter, year]
23+
24+
dimensions:
25+
- payment_type

0 commit comments

Comments
 (0)