-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/implement-unit-testing - Implement Unit Testing (#3)
Co-authored-by: Abel Tavares <abel.tavares@ctw.bmwgroup.com>
- Loading branch information
1 parent
4958ec5
commit 7e1fa36
Showing
8 changed files
with
848 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Run Black Formatter | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: psf/black@stable | ||
|
||
- name: Add label if failure | ||
if: failure() | ||
run: | | ||
curl --request POST \ | ||
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels" \ | ||
--header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
--header "Content-Type: application/json" \ | ||
--data-raw '{"labels": ["Formatter Failed"]}' | ||
- name: Check and remove label if sucess | ||
if: success() | ||
run: | | ||
labels=$(curl -s \ | ||
--request GET \ | ||
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels" \ | ||
--header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}") | ||
if [[ $labels == *"Formatter Failed"* ]]; then | ||
curl --request DELETE \ | ||
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels/Formatter%20Failed" \ | ||
--header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Run Tests | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.10.12 | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install --upgrade pip | ||
pip install requests | ||
pip install psycopg2-binary | ||
pip install python-dotenv | ||
pip install apache-airflow==2.8.1 | ||
pip install apache-airflow[cncf.kubernetes] | ||
pip install pandas | ||
pip install Flask-Session==0.5.0 | ||
- name: Initialize Airflow database | ||
run: airflow db migrate | ||
|
||
- name: Run tests | ||
run: | | ||
python -m unittest discover tests | ||
python tests/dags_test.py | ||
- name: Add label if failure | ||
if: failure() | ||
run: | | ||
curl --request POST \ | ||
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels" \ | ||
--header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
--header "Content-Type: application/json" \ | ||
--data-raw '{"labels": ["Tests Failed"]}' | ||
- name: Check and remove label if present | ||
if: success() | ||
run: | | ||
labels=$(curl -s \ | ||
--request GET \ | ||
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels" \ | ||
--header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}") | ||
if [[ $labels == *"Tests Failed"* ]]; then | ||
curl --request DELETE \ | ||
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels/Tests%20Failed" \ | ||
--header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" | ||
fi | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: unit-tests | ||
name: Run Unit Tests | ||
entry: | | ||
python3 -c " | ||
import subprocess | ||
import sys | ||
TEST_RESULT = subprocess.call(['python3', '-m', 'unittest', 'discover', 'tests']) | ||
sys.exit(TEST_RESULT) | ||
" | ||
language: system | ||
- repo: https://github.com/psf/black | ||
rev: 22.10.0 | ||
hooks: | ||
- id: black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.