-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Amanda Eames
authored and
Amanda Eames
committed
Mar 25, 2024
1 parent
028c6df
commit 1b83112
Showing
3 changed files
with
78 additions
and
2 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 |
---|---|---|
|
@@ -12,6 +12,55 @@ on: | |
branches: ["develop"] | ||
|
||
jobs: | ||
runTests: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./global-api | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest pytest-cov | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Set up database | ||
run: | | ||
docker run --name github_action_postgresql -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust -e POSTGRES_PASSWORD="" postgres | ||
sleep 10 | ||
createuser -w -h localhost -p 5432 -U postgres citycatalyst | ||
createdb -w -h localhost -p 5432 -U postgres citycatalyst -O citycatalyst | ||
cp env.example .env | ||
- name: Build coverage file | ||
run: | | ||
pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=app tests/ | tee pytest-coverage.txt | ||
- name: Pytest coverage comment | ||
uses: MishaKav/pytest-coverage-comment@main | ||
with: | ||
pytest-coverage-path: ./pytest-coverage.txt | ||
junitxml-path: ./pytest.xml | ||
|
||
- name: Upload coverage reports to Codecov | ||
continue-on-error: true | ||
uses: codecov/[email protected] | ||
with: | ||
fail_ci_if_error: false | ||
flags: unittests | ||
name: citycatalyst-global-api | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
slug: Open-Earth-Foundation/CityCatalyst | ||
|
||
- name: Shut down database | ||
run: docker stop github_action_postgresql | ||
|
||
pushToGHCR: | ||
runs-on: ubuntu-latest | ||
|
@@ -55,4 +104,4 @@ jobs: | |
run: | | ||
kubectl create -f k8s/cc-global-api-migrate.yml -n default | ||
kubectl apply -f k8s/cc-global-api-deploy.yml -n default | ||
kubectl rollout restart deployment cc-global-api-deploy -n default | ||
kubectl rollout restart deployment cc-global-api-deploy -n default |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
from main import app | ||
|
||
# Create a TestClient instance with your FastAPI app | ||
client = TestClient(app) | ||
|
||
# Test the root endpoint | ||
def test_read_root(): | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
assert response.json() == {"message": "Welcome"} | ||
|
||
# Test Health Check Endpoint | ||
def test_health_check(): | ||
response = client.get("/health") | ||
assert response.status_code == 200 | ||
assert response.json() == {'status': 'ok'} | ||
|
||
# Test the data catalogue end point has no data | ||
def test_catalgue_no_data_available(): | ||
response = client.get("/api/v0/catalogue") | ||
assert response.status_code == 404 | ||
assert response.json() == {"detail": "No data available"} |