mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-03 16:51:26 +00:00
chore(ci): ajout test_settings.py et SKILL run-tests
This commit is contained in:
1
.github/copilot-instructions.md
vendored
1
.github/copilot-instructions.md
vendored
@ -56,3 +56,4 @@ Pour le front-end, les exigences de qualité sont les suivantes :
|
|||||||
|
|
||||||
- **Tickets** : [issues guidelines](./instructions/issues.instruction.md)
|
- **Tickets** : [issues guidelines](./instructions/issues.instruction.md)
|
||||||
- **Commits** : [commit guidelines](./instructions/general-commit.instruction.md)
|
- **Commits** : [commit guidelines](./instructions/general-commit.instruction.md)
|
||||||
|
- **Tests** : [run tests](./instructions/run-tests.instruction.md)
|
||||||
|
|||||||
53
.github/instructions/run-tests.instruction.md
vendored
Normal file
53
.github/instructions/run-tests.instruction.md
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
---
|
||||||
|
applyTo: "**"
|
||||||
|
---
|
||||||
|
|
||||||
|
# Lancer les tests – N3WT-SCHOOL
|
||||||
|
|
||||||
|
## Tests backend (Django)
|
||||||
|
|
||||||
|
Les tests backend tournent dans le conteneur Docker. Toujours utiliser `--settings=N3wtSchool.test_settings`.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# Tous les tests
|
||||||
|
docker exec -it n3wt-school-backend-1 python3 manage.py test --settings=N3wtSchool.test_settings --verbosity=2
|
||||||
|
|
||||||
|
# Un module spécifique
|
||||||
|
docker exec -it n3wt-school-backend-1 python3 manage.py test --settings=N3wtSchool.test_settings Auth.tests --verbosity=2
|
||||||
|
```
|
||||||
|
|
||||||
|
### Points importants
|
||||||
|
|
||||||
|
- Le fichier `Back-End/N3wtSchool/test_settings.py` configure l'environnement de test :
|
||||||
|
- Base PostgreSQL dédiée `school_test` (SQLite incompatible avec `ArrayField`)
|
||||||
|
- Cache en mémoire locale (pas de Redis)
|
||||||
|
- Channels en mémoire (`InMemoryChannelLayer`)
|
||||||
|
- Throttling désactivé
|
||||||
|
- Hashage MD5 (plus rapide)
|
||||||
|
- Email en mode `locmem`
|
||||||
|
- Si le conteneur n'est pas démarré : `docker compose up -d` depuis la racine du projet
|
||||||
|
- Les logs `WARNING` dans la sortie des tests sont normaux (endpoints qui retournent 400/401 intentionnellement)
|
||||||
|
|
||||||
|
## Tests frontend (Jest)
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# Depuis le dossier Front-End
|
||||||
|
cd Front-End
|
||||||
|
npm test -- --watchAll=false
|
||||||
|
|
||||||
|
# Avec couverture
|
||||||
|
npm test -- --watchAll=false --coverage
|
||||||
|
```
|
||||||
|
|
||||||
|
### Points importants
|
||||||
|
|
||||||
|
- Les tests sont dans `Front-End/src/test/`
|
||||||
|
- Les warnings `ReactDOMTestUtils.act is deprecated` sont non bloquants (dépendance `@testing-library/react`)
|
||||||
|
- Config Jest : `Front-End/jest.config.js`
|
||||||
|
|
||||||
|
## Résultats attendus
|
||||||
|
|
||||||
|
| Périmètre | Nb tests | Statut |
|
||||||
|
| -------------- | -------- | ------ |
|
||||||
|
| Backend Django | 121 | ✅ OK |
|
||||||
|
| Frontend Jest | 24 | ✅ OK |
|
||||||
66
Back-End/N3wtSchool/test_settings.py
Normal file
66
Back-End/N3wtSchool/test_settings.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
"""
|
||||||
|
Settings de test pour l'exécution des tests unitaires Django.
|
||||||
|
Utilise la base PostgreSQL du docker-compose (ArrayField non supporté par SQLite).
|
||||||
|
Redis et Celery sont désactivés.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
os.environ.setdefault('SECRET_KEY', 'django-insecure-test-secret-key-for-unit-tests-only')
|
||||||
|
os.environ.setdefault('WEBHOOK_API_KEY', 'test-webhook-api-key-for-unit-tests-only')
|
||||||
|
os.environ.setdefault('DJANGO_DEBUG', 'True')
|
||||||
|
|
||||||
|
from N3wtSchool.settings import * # noqa: F401, F403
|
||||||
|
|
||||||
|
# Base de données PostgreSQL dédiée aux tests (isolée de la base de prod)
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
|
'NAME': 'school_test',
|
||||||
|
'USER': os.environ.get('DB_USER', 'postgres'),
|
||||||
|
'PASSWORD': os.environ.get('DB_PASSWORD', 'postgres'),
|
||||||
|
'HOST': os.environ.get('DB_HOST', 'database'),
|
||||||
|
'PORT': os.environ.get('DB_PORT', '5432'),
|
||||||
|
'TEST': {
|
||||||
|
'NAME': 'school_test',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cache en mémoire locale (pas de Redis)
|
||||||
|
CACHES = {
|
||||||
|
'default': {
|
||||||
|
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sessions en base de données (plus simple que le cache pour les tests)
|
||||||
|
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
|
||||||
|
|
||||||
|
# Django Channels en mémoire (pas de Redis)
|
||||||
|
CHANNEL_LAYERS = {
|
||||||
|
'default': {
|
||||||
|
'BACKEND': 'channels.layers.InMemoryChannelLayer',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Désactiver Celery pendant les tests
|
||||||
|
CELERY_TASK_ALWAYS_EAGER = True
|
||||||
|
CELERY_TASK_EAGER_PROPAGATES = True
|
||||||
|
|
||||||
|
# Email en mode console (pas d'envoi réel)
|
||||||
|
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
|
||||||
|
|
||||||
|
# Clé secrète fixe pour les tests
|
||||||
|
SECRET_KEY = 'django-insecure-test-secret-key-for-unit-tests-only'
|
||||||
|
SIMPLE_JWT['SIGNING_KEY'] = SECRET_KEY # noqa: F405
|
||||||
|
|
||||||
|
# Désactiver le throttling pendant les tests
|
||||||
|
REST_FRAMEWORK['DEFAULT_THROTTLE_CLASSES'] = [] # noqa: F405
|
||||||
|
REST_FRAMEWORK['DEFAULT_THROTTLE_RATES'] = {} # noqa: F405
|
||||||
|
|
||||||
|
# Accélérer le hashage des mots de passe pour les tests
|
||||||
|
PASSWORD_HASHERS = [
|
||||||
|
'django.contrib.auth.hashers.MD5PasswordHasher',
|
||||||
|
]
|
||||||
|
|
||||||
|
# Désactiver les logs verbeux pendant les tests
|
||||||
|
LOGGING['root']['level'] = 'CRITICAL' # noqa: F405
|
||||||
Reference in New Issue
Block a user