Skip to content

Commit

Permalink
GitHub workflow on pr (Velir#93)
Browse files Browse the repository at this point in the history
* started testing workflow

* working local version of unit tests

* fixing working directory

* adding manual execution

* fixing keyfile location
  • Loading branch information
adamribaudo-velir authored Nov 23, 2022
1 parent 6efa9d5 commit f43277b
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 22 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/run_unit_tests_on_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Run Unit Tests on Pull Request

on: [pull_request,workflow_dispatch]
env:
BIGQUERY_PROJECT: ${{ secrets.BIGQUERY_PROJECT }}
KEYFILE_LOCATION: /dbt-service-account.json

jobs:
pytest_run_all:
name: Pytest Run All
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./unit_tests
steps:
- name: Check out
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/setup-python@v1
with:
python-version: "3.7.x"

- name: Authenticate using service account
run: 'echo "$KEYFILE" > ./dbt-service-account.json'
shell: bash
env:
KEYFILE: ${{secrets.GCP_BIGQUERY_USER_KEYFILE}}

- name: Install dependencies
run: |
pip install dbt-core
pip install dbt-bigquery
pip install pytest
- name: Run tests
run: python -m pytest .
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
target/
dbt_packages/
logs/
google-cloud-sdk/
integration_tests/.env
integration_tests/__pycache__
integration_tests/.pytest_cache

google-cloud-sdk/
unit_tests/.env
unit_tests/__pycache__
unit_tests/.pytest_cache
unit_tests/dbt-service-account.json

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GA4 DBT Package
# GA4 DBT Package

This package connects to an exported GA4 dataset and provides useful transformations as well as report-ready dimensional models that can be used to build reports or blend GA4 data with exported GA3 data.

Expand Down
16 changes: 0 additions & 16 deletions integration_tests/conftest.py

This file was deleted.

1 change: 1 addition & 0 deletions unit_tests/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BIGQUERY_PROJECT=
File renamed without changes.
25 changes: 25 additions & 0 deletions unit_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
import os

# Import the standard functional fixtures as a plugin
pytest_plugins = ["dbt.tests.fixtures.project"]

# The profile dictionary, used to write out profiles.yml
@pytest.fixture(scope="class")
def dbt_profile_target():
# Set project and keyfile for github automated tests
if os.environ.get('GITHUB_ACTIONS') is not None:
return {
'type': 'bigquery',
'method': 'service-account',
'keyfile': os.getcwd() + os.environ.get("KEYFILE_LOCATION"),
'threads': 4,
'timeout_seconds': 300,
'project': os.environ.get("BIGQUERY_PROJECT")
}
return {
'type': 'bigquery',
'method': 'oauth',
'threads': 4,
'project': os.environ.get("BIGQUERY_PROJECT")
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def models(self):

def test_mock_run_and_check(self, project):
run_dbt(["build", "--vars", "conversion_events: ['my_conversion']"])
breakpoint()
#breakpoint()
check_relations_equal(project.adapter, ["actual", "expected"])

0 comments on commit f43277b

Please sign in to comment.