Skip to content

Commit

Permalink
Merge pull request #223 from seapagan/renenable-gh-actions
Browse files Browse the repository at this point in the history
Re-enable gh actions
  • Loading branch information
seapagan authored Sep 22, 2023
2 parents 0fa1b47 + fb29d08 commit b1a91a3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@ on:

jobs:
test:
# disable this job temporarily
if: false
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

services:
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: fastapi-template-test
ports:
- 5432:5432
options:
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
--health-retries 5

steps:
# ---------------------------------------------------------------------- #
# checkout repo and setup Python #
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,4 @@ cython_debug/
openapi.json
test.db
docs/CNAME
.python-version
13 changes: 10 additions & 3 deletions app/database/helpers.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
"""Define some database helper functions."""
from __future__ import annotations

from typing import TYPE_CHECKING, Union

from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

from app.models.user import User

if TYPE_CHECKING:
from sqlalchemy.ext.asyncio import AsyncSession

Check warning on line 11 in app/database/helpers.py

View check run for this annotation

Codecov / codecov/patch

app/database/helpers.py#L11

Added line #L11 was not covered by tests


async def get_all_users_(session: AsyncSession):
"""Return all Users in the database."""
result = await session.execute(select(User))
return result.scalars().all()


async def get_user_by_email_(email, session: AsyncSession) -> User | None:
async def get_user_by_email_(email, session: AsyncSession) -> Union[User, None]:
"""Return a specific user by their email address."""
result = await session.execute(select(User).where(User.email == email))
return result.scalars().first()


async def get_user_by_id_(user_id: int, session: AsyncSession) -> User | None:
async def get_user_by_id_(
user_id: int, session: AsyncSession
) -> Union[User, None]:
"""Return a specific user by their email address."""
result = await session.execute(select(User).where(User.id == user_id))
return result.scalars().first()
Expand Down
19 changes: 13 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Fixtures and configuration for the test suite."""
import asyncio
import os
from typing import Any, AsyncGenerator, Generator

import pytest
Expand All @@ -17,12 +18,18 @@
from app.main import app
from app.managers.email import EmailManager

DATABASE_URL = (
"postgresql+asyncpg://"
f"{get_settings().db_user}:{get_settings().db_password}@"
f"{get_settings().db_address}:{get_settings().db_port}/"
f"{get_settings().test_db_name}"
)
if os.getenv("GITHUB_ACTIONS"):
DATABASE_URL = (
"postgresql+asyncpg://postgres:postgres"
"@localhost:5432/fastapi-template-test"
)
else:
DATABASE_URL = (
"postgresql+asyncpg://"
f"{get_settings().db_user}:{get_settings().db_password}@"
f"{get_settings().db_address}:{get_settings().db_port}/"
f"{get_settings().test_db_name}"
)


async_engine: AsyncEngine = create_async_engine(DATABASE_URL, echo=False)
Expand Down

0 comments on commit b1a91a3

Please sign in to comment.