Skip to content

Ft/actions #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
push:
pull_request:

jobs:
build-fastapi:
name: FastAPI CI

runs-on: ubuntu-latest

env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
ACCESS_SECRET_KEY: ${{ secrets.ACCESS_SECRET_KEY }}
RESET_PASSWORD_SECRET_KEY: ${{ secrets.RESET_PASSWORD_SECRET_KEY }}
VERIFICATION_SECRET_KEY: ${{ secrets.VERIFICATION_SECRET_KEY }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Poetry with pip
run: pip install poetry

- name: Configure Poetry
working-directory: ./fastapi_backend
run: poetry config virtualenvs.create false

- name: Install dependencies
working-directory: ./fastapi_backend
run: poetry install

- name: Run tests
working-directory: ./fastapi_backend
run: poetry run pytest
2 changes: 1 addition & 1 deletion .pre-commit-config.docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:
hooks:
- id: generate-openapi-schema
name: generate OpenAPI schema
entry: sh -c 'docker compose run --rm --no-deps -T backend poetry run python -m commands.generate_openapi_schema'
entry: sh -c 'docker compose run --rm --no-deps -T backend poetry run python -m app.commands.generate_openapi_schema'
language: system
pass_filenames: false
- id: generate-frontend-client
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:
hooks:
- id: generate-openapi-schema
name: generate OpenAPI schema
entry: sh -c 'cd fastapi_backend && poetry run python -m commands.generate_openapi_schema'
entry: sh -c 'cd fastapi_backend && poetry run python -m app.commands.generate_openapi_schema'
language: system
pass_filenames: false
- id: generate-frontend-client
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sqlalchemy.ext.asyncio import async_engine_from_config

from alembic import context
from src.models import Base
from app.src.models import Base

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from pathlib import Path
from src.main import app
from app.src.main import app
import os

from dotenv import load_dotenv
Expand All @@ -14,13 +14,13 @@ def generate_openapi_schema(output_file):
schema = app.openapi()
output_path = Path(output_file)

updated_schema = _remove_operation_id_tag(schema)
updated_schema = remove_operation_id_tag(schema)

output_path.write_text(json.dumps(updated_schema, indent=2))
print(f"OpenAPI schema saved to {output_file}")


def _remove_operation_id_tag(schema):
def remove_operation_id_tag(schema):
"""
Removes the tag prefix from the operation IDs in the OpenAPI schema.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import pytest
from pathlib import Path

from commands.generate_openapi_schema import (
_remove_operation_id_tag,
from app.commands.generate_openapi_schema import (
generate_openapi_schema,
remove_operation_id_tag,
)


Expand All @@ -27,13 +27,13 @@ def expected_output_schema():


def test_remove_operation_id_tag(sample_openapi_schema, expected_output_schema):
cleaned_schema = _remove_operation_id_tag(sample_openapi_schema)
cleaned_schema = remove_operation_id_tag(sample_openapi_schema)
assert cleaned_schema == expected_output_schema


@pytest.fixture
def mock_app(mocker):
app = mocker.patch("commands.generate_openapi_schema.app")
app = mocker.patch("app.commands.generate_openapi_schema.app")
app.openapi.return_value = {
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
Expand All @@ -44,7 +44,7 @@ def mock_app(mocker):

def test_generate_openapi_schema(mocker, mock_app):
mock_remove_operation_id_tag = mocker.patch(
"commands.generate_openapi_schema._remove_operation_id_tag"
"app.commands.generate_openapi_schema.remove_operation_id_tag"
)
mock_remove_operation_id_tag.return_value = {"mocked_schema": True}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from fastapi import status
from fastapi.testclient import TestClient
from fastapi_users.router import ErrorCode
from src.main import app
from app.src.main import app


class TestPasswordValidation:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fastapi.routing import APIRoute
from src.utils import simple_generate_unique_route_id
from app.src.utils import simple_generate_unique_route_id


def test_simple_generate_unique_route_id(mocker):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from threading import Timer

WATCHER_REGEX_PATTERN = re.compile(r"(main|schemas)\.py$")
APP_PATH = "src"
APP_PATH = "app/src"


class MyHandler(FileSystemEventHandler):
Expand Down
8 changes: 4 additions & 4 deletions fastapi_backend/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

if [ -f /.dockerenv ]; then
echo "Running in Docker"
fastapi dev src/main.py --host 0.0.0.0 --port 8000 --reload &
python watcher.py
fastapi dev app/src/main.py --host 0.0.0.0 --port 8000 --reload &
python app/watcher.py
else
echo "Running locally with Poetry"
poetry run fastapi dev src/main.py --host 0.0.0.0 --port 8000 --reload &
poetry run python watcher.py
poetry run fastapi dev app/src/main.py --host 0.0.0.0 --port 8000 --reload &
poetry run python app/watcher.py
fi

wait