Skip to content

Commit

Permalink
Add unit test for default.vw_pin_value stage names
Browse files Browse the repository at this point in the history
  • Loading branch information
jeancochrane committed Jan 27, 2025
1 parent 0a9164e commit 83826a1
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dbt/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ models:
+write_compression: zstd
+format: parquet
+ha: true
ccao:
+schema: ccao
census:
+schema: census
default:
Expand Down
4 changes: 4 additions & 0 deletions dbt/models/ccao/ccao.vw_time_util.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- View that supplies dynamic datetime values in a way that we can mock for
-- unit tests. See:
-- https://discourse.getdbt.com/t/dynamic-dates-in-unit-tests/16883/2
SELECT CURRENT_DATE AS date_today
9 changes: 9 additions & 0 deletions dbt/models/ccao/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ Collected yearly from Valuations via spreadsheets.

**Primary Key**: `pin`, `year`
{% enddocs %}

# vw_time_util

{% docs view_vw_time_util %}
View that supplies dynamic datetime values in a way that we can mock for unit
tests.

See: <https://discourse.getdbt.com/t/dynamic-dates-in-unit-tests/16883/2?>
{% enddocs %}
4 changes: 4 additions & 0 deletions dbt/models/ccao/schema.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
models:
- name: ccao.vw_time_util
description: '{{ doc("view_vw_time_util") }}'

sources:
- name: ccao
tags:
Expand Down
5 changes: 4 additions & 1 deletion dbt/models/default/default.vw_pin_value.sql
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ stage_values AS (
-- stages, it is most likely a provisional value for a PIN
-- that has not mailed yet
CARDINALITY(stages.procnames) != 0
OR asmt.taxyr = DATE_FORMAT(NOW(), '%Y')
OR asmt.taxyr = DATE_FORMAT(
(SELECT date_today FROM {{ ref("ccao.vw_time_util") }}),
'%Y'
)
)
)
)
Expand Down
46 changes: 46 additions & 0 deletions dbt/models/default/schema/default.vw_pin_value.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,58 @@ unit_tests:
# provided to ensure proper joins when creating the dummy table
rows:
- {parid: "123", taxyr: "2024", procname: "CCAOVALUE", rolltype: "RP", valasm3: 10, class: "2.1-1)A"}
# The input tables below are not important, and are only included for the
# sake of completing the joins that construct the view
- input: source("iasworld", "aprval")
rows:
- {parid: "123", taxyr: "2024", procname: "CCAOVALUE", reascd: "28"}
- input: ref("ccao.aprval_reascd")
rows:
- {reascd: "28"}
- input: ref("ccao.vw_time_util")
rows:
- {date_today: "2024-01-01"}
expect:
rows:
- {mailed_class: "211A"}
- name: default_vw_pin_value_stage_name_matches_procname
description: stage_name should match the set of procnames for a PIN
model: default.vw_pin_value
given:
- input: source("iasworld", "asmt_all")
rows:
# `cur` and `procname` are the important fields that determine the
# stage, everything else in these inputs is just for joins
- {parid: "pre-mailed", taxyr: "2024", cur: "Y", procname: null, rolltype: "RP", valasm3: 10}
- {parid: "mailed", taxyr: "2024", procname: "CCAOVALUE", rolltype: "RP", valasm3: 10}
# Pre-certified needs an extra row so that the history filter can see
# that there has already been a mailed value
- {parid: "pre-certified", taxyr: "2024", procname: "CCAOVALUE", rolltype: "RP", valasm3: 10}
- {parid: "pre-certified", taxyr: "2024", cur: "Y", procname: null, rolltype: "RP", valasm3: 10}
- {parid: "ccao-certified", taxyr: "2024", procname: "CCAOFINAL", rolltype: "RP", valasm3: 10}
- {parid: "bor-certified", taxyr: "2024", procname: "BORVALUE", rolltype: "RP", valasm3: 10}
# Reason codes are not important, and we only include them to complete
# the joins that are required to construct the view
- input: source("iasworld", "aprval")
rows:
- {parid: "pre-mailed", taxyr: "2024", procname: null, reascd: "28"}
- {parid: "mailed", taxyr: "2024", procname: "CCAOVALUE", reascd: "28"}
- {parid: "pre-certified", taxyr: "2024", procname: null, reascd: "28"}
- {parid: "ccao-certified", taxyr: "2024", procname: "CCAOFINAL", reascd: "28"}
- {parid: "bor-certified", taxyr: "2024", procname: "BORVALUE", reascd: "28"}
- input: ref("ccao.aprval_reascd")
rows:
- {reascd: "28"}
- input: ref("ccao.vw_time_util")
rows:
# This mock is important, since otherwise the view's dynamic
# reference to the current year could become out of date with this
# test
- {date_today: "2024-01-01"}
expect:
rows:
- {stage_name: "PRE-MAILED"}
- {stage_name: "MAILED"}
- {stage_name: "ASSESSOR PRE-CERTIFIED"}
- {stage_name: "ASSESSOR CERTIFIED"}
- {stage_name: "BOARD CERTIFIED"}

0 comments on commit 83826a1

Please sign in to comment.