diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 10b5bf8..029b8b9 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -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: @@ -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 @@ -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 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 49a7618..2b77d0d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 \ No newline at end of file + pytest tests/test_ci.py -v diff --git a/core/config.py b/core/config.py index 7bbd6eb..d50a489 100644 --- a/core/config.py +++ b/core/config.py @@ -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") diff --git a/requirements.txt b/requirements.txt index 191aaf0..0e4a41c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file diff --git a/schemas/email_schema.py b/schemas/email_schema.py index cb31f95..ccd0fa2 100644 --- a/schemas/email_schema.py +++ b/schemas/email_schema.py @@ -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") \ No newline at end of file + 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") \ No newline at end of file