Skip to content

Commit

Permalink
This is a combination of 16 commits.
Browse files Browse the repository at this point in the history
feat: new unit tests for dbt models and macros
  • Loading branch information
saraburns1 committed Aug 2, 2024
1 parent f8ba41c commit ab617c5
Show file tree
Hide file tree
Showing 102 changed files with 70,578 additions and 1,426 deletions.
Binary file added .DS_Store
Binary file not shown.
9 changes: 5 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Check documentation coverage

name: dbt Docs Coverage
name: dbt Tests & Coverage

on:
push:
Expand All @@ -17,7 +17,7 @@ env:

jobs:
build:
name: Build docs and check coverage
name: Check coverage & run tests
runs-on: ubuntu-latest
permissions:
contents: "read"
Expand Down Expand Up @@ -46,8 +46,9 @@ jobs:
tutor local do load-xapi-test-data
- name: Check dbt tests
run: |
dbt run
dbt test
mv unit-test-seeds ci-seeds
dbt build --full-refresh --selector all_tests
mv ci-seeds unit-test-seeds
- name: Check docs coverage
run: |
dbt run
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ target/
dbt_packages/
logs/
coverage.json

*.DS_Store
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ Running dbt

``dbt run`` will compile and create the models defined in the "aspects" dbt project. By default, dbt will look in the ``xapi`` schema to find source tables. The ``XAPI_SCHEMA`` environment variable can be used to specify a different schema.

Testing
*******

``dbt test`` will run all data tests and any tests in the 'tests' directory (generic tests).
``dbt test --selector ci_unit_tests`` will run all unit tests tagged with 'ci'.
- These require tables to be seeded first. To do this, add 'unit-test-seeds' to ``seed-paths:`` in ``dbt_project.yml`` and run ``dbt seed --full-refresh``.
``dbt test --selector all_tests`` will run all data/generic/unit tests.


More Help
=========

Expand Down
29 changes: 27 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ profile: "aspects"
# These configurations specify where dbt should look for different types of files.
# The `model-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
model-paths: ["models"]
model-paths: ["models",'ci-models']
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
seed-paths: ["seeds","ci-seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

Expand All @@ -34,3 +34,28 @@ models:
# Config indicated by + and applies to all files under models/example/
enrollment:
+materialized: view

# These are for unit test seeds. They will be used when 'unit-test-seeds' is added
# to seed-paths above or when CI tests run
seeds:
aspects:
macros:
items_per_subsection_expected:
+column_types:
item_count: UInt64
base:
xapi_events_all_parsed_expected:
+column_types:
emission_time: DateTime64(6)
instance:
fact_instance_enrollments_expected:
+column_types:
course_enrollment_mode_status_cnt: UInt64
navigation:
fact_navigation_completion_expected:
+column_types:
page_count: UInt64
problems:
responses_expected:
+column_types:
first_success_at: Nullable(DateTime)
7 changes: 7 additions & 0 deletions macros/format_float_value.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% macro format_float_value(value) %}

{% if target.name != "prod" %} CAST({{ value }} as Float32)
{% else %} {{ value }}
{% endif %}

{% endmacro %}
2 changes: 1 addition & 1 deletion macros/get_problem_id.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
-- or is followed by '/answer' or '/hint'
{% macro get_problem_id(object_id) %}
regexpExtract(
object_id, 'xblock/([\w\d-\+:@]*@problem\+block@[\w\d][^_]*)(_\d_\d)?', 1
object_id, 'xblock/([\w\d-\+:@]*@problem\+block@[\w\d][^_\/]*)(_\d_\d)?', 1
)
{% endmacro %}
7 changes: 7 additions & 0 deletions macros/source_for_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% macro source_for_test(schema, table) %}

{% if target.name != "prod" %} {{ source(target.schema, table) }}
{% else %} {{ source(schema, table) }}
{% endif %}

{% endmacro %}
18 changes: 9 additions & 9 deletions models/base/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ models:
description: "A materialized view for xAPI events"
columns:
- name: event_id
data_type: uuid
data_type: UUID
description: "The unique identifier for the event"
- name: verb_id
data_type: string
data_type: String
description: "The xAPI verb identifier"
- name: actor_id
data_type: string
data_type: String
description: "The xAPI actor identifier"
- name: object_id
data_type: string
data_type: String
description: "The xAPI object identifier"
- name: course_id
data_type: string
data_type: String
description: "The fully-qualified course identifier URL"
- name: course_key
data_type: String
description: "The course key for the course"
- name: org
data_type: string
data_type: String
description: "The organization that the course belongs to"
- name: emission_time
data_type: datetime64(6)
data_type: DateTime64(6)
description: "The time the event was emitted"
- name: event
data_type: string
description: "The xAPI event as a string"
data_type: String
description: "The xAPI event as a String"
8 changes: 8 additions & 0 deletions models/base/sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ sources:
- name: event_id
- name: emission_time
- name: event
- name: reporting
database: "reporting"
tables:
- name: xapi_events_all
columns:
- name: event_id
- name: emission_time
- name: event
14 changes: 14 additions & 0 deletions models/base/unit_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
unit_tests:
- name: test_xapi_events_all_parsed
model: xapi_events_all_parsed
config:
tags: 'ci'
given:
- input: source("{{target.schema}}", "xapi_events_all")
format: sql
rows: |
select * from xapi_events_all
expect:
format: sql
rows: |
select * from xapi_events_all_parsed_expected
2 changes: 1 addition & 1 deletion models/base/xapi_events_all_parsed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ select
) as org,
emission_time as emission_time,
event::String as event
from {{ source("xapi", "xapi_events_all") }}
from {{ source_for_test("xapi", "xapi_events_all") }}
26 changes: 0 additions & 26 deletions models/completion/completion_events.sql

This file was deleted.

61 changes: 0 additions & 61 deletions models/completion/fact_completions.sql

This file was deleted.

77 changes: 0 additions & 77 deletions models/completion/schema.yml

This file was deleted.

Loading

0 comments on commit ab617c5

Please sign in to comment.