mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Amorçage des tests automatiques [#64]
This commit is contained in:
39
Back-End/test_all_endpoints.py
Normal file
39
Back-End/test_all_endpoints.py
Normal file
@ -0,0 +1,39 @@
|
||||
"""
|
||||
Starter de tests automatiques pour valider tous les endpoints définis dans les fichiers urls.py du projet Django N3WT-SCHOOL.
|
||||
Chaque endpoint est testé pour la réponse HTTP attendue (200, 401, 403, 404, etc.).
|
||||
"""
|
||||
import pytest
|
||||
from django.urls import reverse, resolve
|
||||
from rest_framework.test import APIClient
|
||||
from django.conf import settings
|
||||
from django.urls import get_resolver
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestAllEndpoints:
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup(self):
|
||||
self.client = APIClient()
|
||||
|
||||
def get_all_url_patterns(self):
|
||||
resolver = get_resolver()
|
||||
patterns = resolver.url_patterns
|
||||
urls = []
|
||||
def extract(patterns, prefix=""):
|
||||
for p in patterns:
|
||||
if hasattr(p, 'url_patterns'):
|
||||
extract(p.url_patterns, prefix + str(p.pattern))
|
||||
else:
|
||||
urls.append(prefix + str(p.pattern))
|
||||
extract(patterns)
|
||||
return urls
|
||||
|
||||
def test_all_endpoints_anonymous(self):
|
||||
urls = self.get_all_url_patterns()
|
||||
for url in urls:
|
||||
if '<' in url: # skip dynamic urls for starter
|
||||
continue
|
||||
try:
|
||||
response = self.client.get(url)
|
||||
assert response.status_code in [200, 401, 403, 404]
|
||||
except Exception as e:
|
||||
print(f"Erreur sur {url}: {e}")
|
||||
Reference in New Issue
Block a user