Skip to content

Commit

Permalink
basic global-api testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanda Eames authored and Amanda Eames committed Mar 25, 2024
1 parent 028c6df commit 1b83112
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
51 changes: 50 additions & 1 deletion .github/workflows/global-api-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion global-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ openclimate==0.1.*
nest_asyncio==1.6.*
xlrd==2.0.*
dns-cache==0.3.*
openpyxl==3.1.*
openpyxl==3.1.*
pytest==8.1.1
pytest-cov==4.1.0
httpx==0.27.0
24 changes: 24 additions & 0 deletions global-api/tests/test_main.py
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"}

0 comments on commit 1b83112

Please sign in to comment.