Skip to content

Commit

Permalink
feat: github actions for backend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julienc91 committed Sep 7, 2024
1 parent 0276595 commit 5c72726
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/.github"
schedule:
interval: "weekly"
- package-ecosystem: "yarn"
directory: "/frontend"
schedule:
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint-backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Lint
working-directory: ./backend/
run: |
uvx ruff check .
uvx ruff format --check .
test-backend:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: tests
POSTGRES_DB: tests
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis:latest
ports:
- 6379:6379
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v4
- name: Install dependencies
working-directory: ./backend/
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
uv sync --extra tests
- name: Tests
working-directory: ./backend/
run: |
source .venv/bin/activate
python manage.py migrate
pytest --create-db
env:
DJANGO_SETTINGS_MODULE: caviardeul.settings
HOST_NAME: caviardeul.dev
DJANGO_SECRET_KEY: tests
POSTGRES_DB: tests
POSTGRES_USER: postgres
POSTGRES_PASSWORD: tests
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
REDIS_HOST: localhost
REDIS_PORT: 6379
SMTP_HOSTNAME: localhost
SMTP_PORT: 465
SMTP_LOGIN: mail
SMTP_PASSWORD: tests
EMAIL_FROM: [email protected]
1 change: 0 additions & 1 deletion backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DEBUG=0
HOST_NAME=caviardeul.fr
DATABASE_URL="postgresql://postgres:5432/caviardeul"
DJANGO_SECRET_KEY=
DJANGO_SETTINGS_MODULE=caviardeul.settings

Expand Down
3 changes: 1 addition & 2 deletions backend/caviardeul/serializers/custom_article.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import Literal

from pydantic import Field

from ninja import Schema
from pydantic import Field

from caviardeul.serializers.article import BaseEncryptedArticleSchema

Expand Down
9 changes: 7 additions & 2 deletions backend/caviardeul/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@
}
}


__redis_password = os.environ.get("REDIS_PASSWORD")
if __redis_password:
__redis_password = f":{__redis_password}@"

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": f"redis://:{os.environ['REDIS_PASSWORD']}@{os.environ['REDIS_HOST']}:{os.environ.get('REDIS_PORT', '6379')}",
"LOCATION": f"redis://{__redis_password}{os.environ['REDIS_HOST']}:{os.environ.get('REDIS_PORT', '6379')}",
}
}

Expand Down Expand Up @@ -169,7 +174,7 @@
if item
]
EMAIL_HOST = os.environ["SMTP_HOSTNAME"]
EMAIL_PORT = int(os.environ["SMTP_PORT"])
EMAIL_PORT = int(os.environ.get("SMTP_PORT", 465))
EMAIL_USE_SSL = os.environ.get("SMTP_USE_SSL", EMAIL_PORT == 465)
EMAIL_USE_TLS = os.environ.get("SMTP_USE_TLS", EMAIL_PORT == 587)
EMAIL_HOST_PASSWORD = os.environ["SMTP_PASSWORD"]
Expand Down
2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ include = ["caviardeul/**/*.py"]
omit = ["caviardeul/tests/*"]

[tool.pytest.ini_options]
addopts = "--disable-socket --allow-hosts=redis,postgres"
addopts = "--disable-socket --allow-hosts=redis,postgres,localhost"

[tool.ruff.lint]
extend-select = ["I"]

0 comments on commit 5c72726

Please sign in to comment.