Browse Source
feat: add core backend application structure, enhanced auth middleware, and API components
main
feat: add core backend application structure, enhanced auth middleware, and API components
main
10 changed files with 3160 additions and 33 deletions
-
1apps/__init__.py
-
7apps/account/admin/notification.py
-
9apps/account/models/user.py
-
79apps/api/tests.py
-
31apps/api/views/api_views.py
-
10config/enhanced_auth_middleware.py
-
1config/settings/base.py
-
1dynamic_preferences/admin.py
-
1requirements.txt
-
3031schema.yml
@ -0,0 +1 @@ |
|||||
|
# apps package |
||||
@ -1,3 +1,80 @@ |
|||||
from django.test import TestCase |
from django.test import TestCase |
||||
|
from django.urls import reverse |
||||
|
from rest_framework.test import APIClient |
||||
|
from rest_framework import status |
||||
|
from django.contrib.auth import get_user_model |
||||
|
|
||||
# Create your tests here. |
|
||||
|
User = get_user_model() |
||||
|
|
||||
|
|
||||
|
class Phase0InfrastructureTests(TestCase): |
||||
|
""" |
||||
|
Automated verification tests for Phase 0 infrastructure: |
||||
|
- OpenAPI 3.0 schema endpoints via drf-spectacular |
||||
|
- Swagger UI & ReDoc interfaces |
||||
|
- JWT token issue, refresh, and verification endpoints |
||||
|
- Core API health checks |
||||
|
""" |
||||
|
def setUp(self): |
||||
|
self.client = APIClient() |
||||
|
self.user = User.objects.create_user( |
||||
|
email='tester@shiadeepconnect.org', |
||||
|
username='tester@shiadeepconnect.org', |
||||
|
password='SecurePassword123!', |
||||
|
fullname='Tester User' |
||||
|
) |
||||
|
|
||||
|
def test_health_check_endpoint(self): |
||||
|
response = self.client.get('/api/v1/health/') |
||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK) |
||||
|
self.assertEqual(response.data.get('status'), 'healthy') |
||||
|
self.assertEqual(response.data.get('version'), '1.0.0') |
||||
|
|
||||
|
def test_openapi_schema_endpoint(self): |
||||
|
response = self.client.get('/api/schema/') |
||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK) |
||||
|
self.assertIn('openapi', response.content.decode('utf-8')) |
||||
|
|
||||
|
def test_swagger_ui_endpoint(self): |
||||
|
response = self.client.get('/api/schema/swagger-ui/') |
||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK) |
||||
|
|
||||
|
def test_redoc_endpoint(self): |
||||
|
response = self.client.get('/api/schema/redoc/') |
||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK) |
||||
|
|
||||
|
def test_swagger_legacy_redirect(self): |
||||
|
response = self.client.get('/swagger/') |
||||
|
self.assertIn(response.status_code, [status.HTTP_302_FOUND, status.HTTP_301_MOVED_PERMANENTLY]) |
||||
|
self.assertEqual(response.url, '/api/schema/swagger-ui/') |
||||
|
|
||||
|
def test_jwt_token_obtain_pair(self): |
||||
|
# Obtain JWT tokens |
||||
|
payload = { |
||||
|
'email': 'tester@shiadeepconnect.org', |
||||
|
'password': 'SecurePassword123!' |
||||
|
} |
||||
|
response = self.client.post('/api/v1/auth/token/', payload, format='json') |
||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK) |
||||
|
self.assertIn('access', response.data) |
||||
|
self.assertIn('refresh', response.data) |
||||
|
|
||||
|
access_token = response.data['access'] |
||||
|
refresh_token = response.data['refresh'] |
||||
|
|
||||
|
# Verify token |
||||
|
verify_response = self.client.post( |
||||
|
'/api/v1/auth/token/verify/', |
||||
|
{'token': access_token}, |
||||
|
format='json' |
||||
|
) |
||||
|
self.assertEqual(verify_response.status_code, status.HTTP_200_OK) |
||||
|
|
||||
|
# Refresh token |
||||
|
refresh_response = self.client.post( |
||||
|
'/api/v1/auth/token/refresh/', |
||||
|
{'refresh': refresh_token}, |
||||
|
format='json' |
||||
|
) |
||||
|
self.assertEqual(refresh_response.status_code, status.HTTP_200_OK) |
||||
|
self.assertIn('access', refresh_response.data) |
||||
3031
schema.yml
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue