Skip to content

Commit

Permalink
updated workflows (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nneji123 authored Jan 8, 2024
2 parents 8036afc + 1a56a2a commit 7817de0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
with:
python-version: '3.11'
- name: Install requirements
run: pip install -r api/requirements.txt
run: pip install -r api/requirements.txt && python api/init_db.py

- name: Run tests and collect coverage
run: pytest --cov=api.public.towns.routes tests/test_towns.py --cov-report=xml
- name: Upload coverage reports to Codecov
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
- name: Run Tests
run: |
echo "${{ secrets.ENV_FILE }}" > .env
pip install -r api/requirements.txt
pytest test/test_towns.py
pip install -r api/requirements.txt && python api/init_db.py
pytest tests/test_towns.py
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# SQLModel FastAPI Project
[![codecov](https://codecov.io/gh/Nneji123/fastapi-webscraper/graph/badge.svg?token=UsIESnIqm6)](https://codecov.io/gh/Nneji123/fastapi-webscraper)

[![Python Tests](https://github.com/Nneji123/fastapi-webscraper/actions/workflows/test.yml/badge.svg)](https://github.com/Nneji123/fastapi-webscraper/actions/workflows/test.yml)

[![Python Tests](https://github.com/Nneji123/fastapi-webscraper/actions/workflows/test.yml/badge.svg)](https://github.com/Nneji123/fastapi-webscraper/actions/workflows/test.yml)


## Overview
This project utilizes FastAPI along with SQLModel, Asyncpg, SQLAlchemy, FastAPI-Limiter, FastAPI-Pagination, Docker, Docker Compose, Makefile, and Pytest for automated testing. It's deployed on Render using Docker.
Expand Down
4 changes: 2 additions & 2 deletions api/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def create_town_and_people(db: Session):

# Create people
people_data = [
{"name": "Alice", "age": 30, "town_id": created_towns[0].id},
{"name": "Bob", "age": 25, "town_id": created_towns[1].id},
{"name": "Alice", "age": 30, "gender": "female", "town_id": created_towns[0].id},
{"name": "Bob", "age": 25, "gender": "male", "town_id": created_towns[1].id},
# Assign people to towns created above, adjust town_id as needed
]

Expand Down
30 changes: 30 additions & 0 deletions api/init_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from sqlmodel import Session, SQLModel, create_engine
from sqlmodel.ext.asyncio import session
from sqlalchemy.exc import IntegrityError

import sys
from pathlib import Path

# Get the absolute path of the directory containing this script
current_file = Path(__file__).resolve()
parent_directory = current_file.parent
project_directory = parent_directory.parent

sys.path.insert(0, str(project_directory))

from api.database import create_db_and_tables, create_town_and_people, get_db


def create_database_for_tests():
db = next(get_db()) # Fetching the database session
create_db_and_tables()
try:
create_town_and_people(db)
except (IntegrityError, Exception) as e:
# Perform any cleanup or teardown operations if needed
print(e)
pass

create_database_for_tests()
4 changes: 2 additions & 2 deletions tests/test_towns.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_update_existing_town(test_app):
"country": "Updated Country",
}
response = client.put("/towns/1", json=town_update_data)
assert response.status_code == 404
assert response.status_code == 200
assert isinstance(response.json(), TownRead) == False


Expand All @@ -114,4 +114,4 @@ def test_delete_existing_town(test_app):

# Assuming town with ID=1 exists in the database
response = client.delete("/towns/1")
assert response.status_code == 500
assert response.status_code == 200

0 comments on commit 7817de0

Please sign in to comment.