Skip to content
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
17 changes: 11 additions & 6 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: CD Tests

on:
Expand All @@ -11,14 +8,14 @@ permissions:
contents: read

jobs:
build:

cd-tests:
name: Python Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install apt dependencies
Expand All @@ -29,7 +26,15 @@ jobs:
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Patch fastapi-mail for Python 3.12
run: |
python -m pip install --upgrade pip
pip install --upgrade "fastapi-mail>=1.4.1"
- name: Run pytest (CD only)
env:
ENV_MAIL_USERNAME: ${{ secrets.ENV_MAIL_USERNAME }}
ENV_MAIL_PASSWORD: ${{ secrets.ENV_MAIL_PASSWORD }}
ENV_SECRET_KEY: ${{ secrets.ENV_SECRET_KEY }}
run: |
export PYTHONPATH=$(pwd)
if [ -f bank_db.db ]; then rm -rf bank_db.db; fi
Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,38 @@ name: CI Tests
on:
pull_request:
branches: [ "main" ]
push:
branches: [ "main" ]
workflow_dispatch:

jobs:
build:
ci-tests:
name: Python Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

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

- name: Install apt dependencies
run: |
sudo apt-get update
sudo apt-get install -y libmariadb3 libmariadb-dev python3-dev build-essential pkg-config

- name: Install pip dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Patch fastapi-mail for Python 3.12
run: |
pip install --upgrade "fastapi-mail>=1.4.1"
- name: Run pytest (CI only)
env:
ENV_MAIL_USERNAME: ${{ secrets.ENV_MAIL_USERNAME }}
ENV_MAIL_PASSWORD: ${{ secrets.ENV_MAIL_PASSWORD }}
ENV_SECRET_KEY: ${{ secrets.ENV_SECRET_KEY }}
run: |
export PYTHONPATH=$(pwd)
pytest tests/test_ci.py -v
pytest tests/test_ci.py -v
29 changes: 17 additions & 12 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
from dotenv import load_dotenv
import os
from schemas.email_schema import Settings
from pydantic import ValidationError

load_dotenv()

settings = Settings()

# SMTP server configuration
smtp_conf = ConnectionConfig(
MAIL_USERNAME=settings.MAIL_USERNAME,
MAIL_PASSWORD=settings.MAIL_PASSWORD,
MAIL_FROM=settings.MAIL_FROM,
MAIL_FROM_NAME="Your App",
MAIL_PORT=587,
MAIL_SERVER="smtp.gmail.com",
MAIL_STARTTLS=True,
MAIL_SSL_TLS=False,
USE_CREDENTIALS=True,
VALIDATE_CERTS=True
)
try:
smtp_conf = ConnectionConfig(
MAIL_USERNAME=os.getenv("ENV_MAIL_USERNAME",settings.ENV_MAIL_USERNAME),
MAIL_PASSWORD=os.getenv("ENV_MAIL_PASSWORD",settings.ENV_MAIL_PASSWORD),
MAIL_FROM=os.getenv("ENV_MAIL_USERNAME",settings.ENV_MAIL_FROM),
MAIL_FROM_NAME="Your App",
MAIL_PORT=587,
MAIL_SERVER="smtp.gmail.com",
MAIL_STARTTLS=True,
MAIL_SSL_TLS=False,
USE_CREDENTIALS=True,
VALIDATE_CERTS=True
)
except ValidationError as e:
print("⚠️ Missing mail config in environment; skipping email setup for tests.")
smtp_conf = None

# JWT configuration
JWT_SECRET_KEY = os.getenv("ENV_SECRET_KEY", "testkey")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pydantic_core~=2.33.2
PyJWT~=2.10.1
pydantic[email]
python-dotenv
fastapi-mail~=1.5.0
fastapi-mail>=1.4.1
redis~=5.3.1
pytest~=8.4.2
httpx~=0.28.1
6 changes: 3 additions & 3 deletions schemas/email_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from pydantic import EmailStr

class Settings(BaseSettings):
MAIL_USERNAME: str = Field("test@example.com", env="MAIL_USERNAME")
MAIL_PASSWORD: str = Field("password", env="MAIL_PASSWORD")
MAIL_FROM: EmailStr = Field("noreply@example.com", env="MAIL_FROM")
ENV_MAIL_USERNAME: str = Field("test@example.com", env="ENV_MAIL_USERNAME")
ENV_MAIL_PASSWORD: str = Field("password", env="ENV_MAIL_PASSWORD")
ENV_MAIL_FROM: EmailStr = Field("test@example.com", env="ENV_MAIL_USERNAME")