Skip to content

Commit

Permalink
Add integration tests to github pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
diofeher committed Nov 5, 2024
1 parent 84e4609 commit 5086ddc
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 19 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
push:
branches:
- main
- feature/pytest
pull_request:

jobs:
Expand All @@ -26,6 +27,40 @@ jobs:

- name: Run Ruff
run: ruff check backend # Lint the entire repository

- name: Run Ruff
run: ruff check backend # Lint the entire repository
backend-test:
runs-on: ubuntu-latest
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out repository code
uses: actions/checkout@v4

- uses: eifinger/setup-rye@v4
- name: Install dependencies
working-directory: backend
run: rye sync
- name: Run tests
working-directory: backend
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
run: rye run pytest
frontend-lint:
runs-on: ubuntu-latest

Expand Down
Empty file added backend/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion backend/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from app.main import app
from backend.app import app

__all__ = [app]
4 changes: 2 additions & 2 deletions backend/app/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from sqlalchemy.orm import Session
from sqlalchemy import select

from app.db import get_session
from app.users.models import User, TokenData
from .db import get_session
from .users.models import User, TokenData

# TODO: Pass as configuration, hardcoded for now
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
Expand Down
2 changes: 1 addition & 1 deletion backend/app/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sqlalchemy_utils import database_exists, create_database
from sqlmodel import Session, create_engine, SQLModel
from app.settings import settings
from .settings import settings


def get_engine(url=settings.database_url):
Expand Down
4 changes: 2 additions & 2 deletions backend/app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .app import app
from backend.app import app

__all__ = [app]
__all__ = ["app"]
6 changes: 3 additions & 3 deletions backend/app/tasks/routers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Annotated
from fastapi import Depends, Query, APIRouter
from sqlalchemy.orm import Session
from app.users.models import User
from app.auth import get_current_active_user
from app.db import get_session
from ..users.models import User
from ..auth import get_current_active_user
from ..db import get_session
from .schema import TaskInput, TaskOutput
from .service import TaskService

Expand Down
6 changes: 3 additions & 3 deletions backend/app/users/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from fastapi.security import OAuth2PasswordRequestForm
from passlib.hash import pbkdf2_sha256

from app.users.models import User, UserCreate
from app.db import get_session
from app.auth import (
from .models import User, UserCreate
from ..db import get_session
from ..auth import (
create_access_token,
get_current_active_user,
hash_password,
Expand Down
1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = [
"psycopg2>=2.9.10",
"sqlalchemy-utils>=0.41.2",
"pydantic-settings>=2.6.0",
"mypy>=1.13.0",
]
readme = "README.md"
requires-python = ">= 3.8"
Expand Down
1 change: 1 addition & 0 deletions backend/requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ markupsafe==3.0.2
mdurl==0.1.2
# via markdown-it-py
mypy==1.13.0
# via task-management
mypy-extensions==1.0.0
# via black
# via mypy
Expand Down
5 changes: 5 additions & 0 deletions backend/requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ markupsafe==3.0.2
# via jinja2
mdurl==0.1.2
# via markdown-it-py
mypy==1.13.0
# via task-management
mypy-extensions==1.0.0
# via mypy
packaging==24.1
# via pytest
passlib==1.7.4
Expand Down Expand Up @@ -125,6 +129,7 @@ typer==0.12.5
# via fastapi-cli
typing-extensions==4.12.2
# via fastapi
# via mypy
# via pydantic
# via pydantic-core
# via sqlalchemy
Expand Down
11 changes: 7 additions & 4 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import os
from fastapi.testclient import TestClient

# import sys

# sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from sqlmodel import Session

from app.main import app
from backend.app.users.models import User
from app.auth import get_current_active_user, hash_password
from app.db import (
from ..app.app import app
from ..app.users.models import User
from ..app.auth import get_current_active_user, hash_password
from ..app.db import (
get_engine,
get_session,
create_db_and_tables,
Expand Down
7 changes: 4 additions & 3 deletions backend/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient
from sqlmodel import Session
from backend.app.tasks.models import Task
from ..app.tasks.models import Task


def test_create_task(client: TestClient):
Expand Down Expand Up @@ -103,13 +103,14 @@ def test_update_task(session: Session, client: TestClient):
session.commit()

response = client.patch(
f"/tasks/{task_1.id}", json={"title": "Deadpuddle"}
f"/tasks/{task_1.id}",
json={"title": "Deadpuddle", "description": "asd"},
)
data = response.json()

assert response.status_code == 200
assert data["title"] == "Deadpuddle"
assert data["description"] == "Dive Wilson"
assert data["description"] == "asd"
assert data["id"] == task_1.id


Expand Down

0 comments on commit 5086ddc

Please sign in to comment.