Skip to content

Commit

Permalink
Project refactor 2 (#11)
Browse files Browse the repository at this point in the history
* Refactor project to make structure simpler, remove modules dirs
* update project config to use new structure, consolidate test utils
* add modified files
* extract web stuff to it's own toplevel dir
* format package.json

---------

Co-authored-by: phernandez <[email protected]>
  • Loading branch information
phernandez and phernandez authored Oct 1, 2024
1 parent 94572ff commit bf6506d
Show file tree
Hide file tree
Showing 108 changed files with 148 additions and 293 deletions.
3 changes: 1 addition & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ source =
foundation

omit =
foundation/conftest.py
modules/foundation/web/*
foundation/web/*

concurrency=greenlet
10 changes: 5 additions & 5 deletions .github/workflows/basic-foundation-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ jobs:
run: |
make init-data
- name: Run foundation tests
- name: Run foundation core tests
run: |
make test-foundation
make test-foundation-core
- name: Run foundation tests
- name: Run foundation api tests
run: |
make test-modules-api
make test-foundation-api
- name: Install Playwright and dependencies
run: |
Expand All @@ -93,7 +93,7 @@ jobs:
- name: Run Playwright tests
run: |
make test-modules-web
make test-foundation-web
- name: Upload Playwright Traces
uses: actions/upload-artifact@v4
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ cython_debug/

.DS_Store
.idea/
modules/foundation/web/node_modules/
!/foundation/templates/email/build/
web/node_modules/
coverage.txt
/junit.xml
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#used by pyenv
# used by pyenv
3.12
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ install-python:
poetry install

install-node:
cd modules/foundation/web && npm install
cd web && npm install

reset-cov:
rm -f .coverage

test: reset-cov test-foundation test-modules-api test-modules-web
test: reset-cov test-foundation-core test-foundation-api test-foundation-web

COVERAGE_ARGS ?= --cov-append --cov-report=term-missing --cov-report=xml --cov-config=.coveragerc --junitxml=junit.xml -o junit_family=legacy

test-foundation:
poetry run pytest foundation --cov=./foundation $(COVERAGE_ARGS)
test-foundation-core:
poetry run pytest foundation/test/core --cov=./foundation/core $(COVERAGE_ARGS)

test-modules-api:
poetry run pytest modules/foundation/api --cov=./modules/foundation/api $(COVERAGE_ARGS)
test-foundation-api:
poetry run pytest foundation/test/api --cov=./foundation/api $(COVERAGE_ARGS)

test-modules-web: # runs playwright tests: assumes app is running on at API_URL in config
poetry run pytest modules/foundation/web --cov=./modules/foundation/web $(COVERAGE_ARGS) -m "playwright" --tracing=retain-on-failure
test-foundation-web: # runs playwright tests: assumes app is running on at API_URL in config
poetry run pytest foundation/test/web -m "playwright" --tracing=retain-on-failure
#poetry run pytest -m "playwright" --headed --slowmo 500

test-coverage:
Expand All @@ -50,18 +50,18 @@ format-python:
poetry run ruff format .

format-prettier:
cd modules/foundation/web && npx prettier templates --write
cd web && npx prettier templates --write

format: format-python format-prettier

type-check:
poetry run pyright

tailwind:
cd modules/foundation/web && npm run build
cd web && npm run build

tailwind-prod:
cd modules/foundation/web && npm run build-prod
cd web && npm run build-prod

# Database migrations
# Database URL for db mate
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions modules/foundation/api/deps.py → foundation/api/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from fastapi_jwt import JwtAuthorizationCredentials, JwtAccessBearer, JwtRefreshBearer

from foundation.core.config import settings
from foundation.users import get_current_user, validate_role_is_admin
from foundation.users.deps import UserServiceDep
from foundation.users.models import User
from foundation.core.users import get_current_user, validate_role_is_admin
from foundation.core.users.deps import UserServiceDep
from foundation.core.users.models import User

# Read access token from bearer header
access_token_security_bearer = JwtAccessBearer(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
from fastapi import APIRouter, Depends, HTTPException
from fastapi.encoders import jsonable_encoder
from fastapi.security import OAuth2PasswordRequestForm

from modules.foundation.api.deps import access_token_security_bearer, CurrentUserDep
from foundation.core.config import settings
from foundation.core.security import verify_password_reset_token
from foundation.users.deps import UserServiceDep
from foundation.users.schemas import (
from foundation.core.users.deps import UserServiceDep
from foundation.core.users.models import StatusEnum
from foundation.core.users.schemas import (
AuthToken,
AuthTokenPayload,
Message,
UserPublic,
NewPassword,
)
from foundation.users.services import UserNotFoundError
from foundation.users.models import StatusEnum
from foundation.core.users.services import UserNotFoundError

from foundation.api.deps import access_token_security_bearer, CurrentUserDep
from foundation.core.config import settings
from foundation.core.security import verify_password_reset_token

router = APIRouter()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
from uuid import UUID

from fastapi import APIRouter, HTTPException, status

from modules.foundation.api.deps import (
validate_role_is_admin,
CurrentUserDep,
AdminRequired,
)
from foundation.users.deps import UserServiceDep
from foundation.users.schemas import (
from foundation.core.users.deps import UserServiceDep
from foundation.core.users.schemas import (
UsersPublic,
UserPublic,
UserCreate,
UserUpdate,
Message,
)
from foundation.users.services import UserNotFoundError, UserValueError, UserCreateError
from foundation.core.users.services import (
UserNotFoundError,
UserValueError,
UserCreateError,
)

from foundation.api.deps import (
validate_role_is_admin,
CurrentUserDep,
AdminRequired,
)

router = APIRouter()

Expand Down
25 changes: 12 additions & 13 deletions foundation/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@
import sys

from fastapi import FastAPI
from fastapi.exception_handlers import (
http_exception_handler,
)
from loguru import logger
from starlette.exceptions import HTTPException as StarletteHTTPException
from starlette.middleware.sessions import SessionMiddleware
from starlette.staticfiles import StaticFiles
from starlette_wtf import CSRFProtectMiddleware

from foundation.tools import init_data
from foundation.api.routes import (
api_router,
) # Import the router from api
from foundation.core import config
from foundation.core.config import BASE_DIR, settings
from modules.foundation.web.templates import templates

from modules.foundation.api.routes import (
api_router,
) # Import the router from api module
from modules.foundation.web.routes import (
from foundation.tools import init_data
from foundation.web.routes import (
html_router,
) # Import the router from web module
from fastapi.exception_handlers import (
http_exception_handler,
)
) # Import the router from web
from foundation.web.templates import templates

# delete all existing default loggers
logger.remove()
Expand All @@ -35,11 +34,11 @@

app.mount(
"/static",
StaticFiles(directory=f"{BASE_DIR}/modules/foundation/web/static"),
StaticFiles(directory=f"{BASE_DIR}/web/static"),
name="static",
)

# include routes from modules
# include routes from api and web
app.include_router(api_router, prefix="/api")
app.include_router(html_router)

Expand Down
149 changes: 0 additions & 149 deletions foundation/conftest.py

This file was deleted.

2 changes: 1 addition & 1 deletion foundation/core/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def render_email_template(*, template_name: str, context: dict[str, Any]) -> str
Raises KeyError if any placeholders in the template are missing from the context.
"""
template_str = (
BASE_DIR / "foundation" / "templates" / "email" / "build" / template_name
BASE_DIR / "foundation" / "core" / "email_templates" / "build" / template_name
).read_text()
html_content = Template(template_str).render(context)
return html_content
Expand Down
Loading

0 comments on commit bf6506d

Please sign in to comment.