feat(core): add core module with mixins, services, and background jobs
- Add Model Mixins: TimestampMixin, SoftDeleteMixin, AuditMixin, etc. - Add Base Services: BaseService, BulkOperationsMixin, QueryOptimizerMixin - Add Base ViewSets with bulk operations - Add BackgroundJob model for Celery task tracking - Add BaseAppCommand for management commands - Add permissions, pagination, filters, cache, logging - Migrate tests to factory_boy + faker - Add CHANGELOG.md - 297 tests passing
This commit is contained in:
34
tests/apps/core/test_middleware.py
Normal file
34
tests/apps/core/test_middleware.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""Tests for core middleware"""
|
||||
|
||||
from django.urls import reverse
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
|
||||
class RequestIDMiddlewareTest(APITestCase):
|
||||
"""Tests for RequestIDMiddleware"""
|
||||
|
||||
def test_request_id_generated(self):
|
||||
"""Test that request ID is generated and returned in response header"""
|
||||
url = reverse("core:health")
|
||||
response = self.client.get(url)
|
||||
|
||||
self.assertIn("X-Request-ID", response)
|
||||
self.assertIsNotNone(response["X-Request-ID"])
|
||||
# UUID format check (36 chars with hyphens)
|
||||
self.assertEqual(len(response["X-Request-ID"]), 36)
|
||||
|
||||
def test_request_id_passed_through(self):
|
||||
"""Test that provided X-Request-ID is passed through"""
|
||||
url = reverse("core:health")
|
||||
custom_id = "custom-request-id-12345"
|
||||
response = self.client.get(url, HTTP_X_REQUEST_ID=custom_id)
|
||||
|
||||
self.assertEqual(response["X-Request-ID"], custom_id)
|
||||
|
||||
def test_different_requests_different_ids(self):
|
||||
"""Test that different requests get different IDs"""
|
||||
url = reverse("core:health")
|
||||
response1 = self.client.get(url)
|
||||
response2 = self.client.get(url)
|
||||
|
||||
self.assertNotEqual(response1["X-Request-ID"], response2["X-Request-ID"])
|
||||
Reference in New Issue
Block a user