first commit
This commit is contained in:
101
tests/apps/core/test_views.py
Normal file
101
tests/apps/core/test_views.py
Normal file
@@ -0,0 +1,101 @@
|
||||
"""Tests for core views (health checks)"""
|
||||
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
|
||||
class HealthCheckViewTest(APITestCase):
|
||||
"""Tests for HealthCheckView"""
|
||||
|
||||
def test_health_check_url_reverse(self):
|
||||
"""Test reverse URL resolution for health check"""
|
||||
url = reverse("core:health")
|
||||
self.assertEqual(url, "/health/")
|
||||
|
||||
def test_health_check_success(self):
|
||||
"""Test health check returns healthy status"""
|
||||
url = reverse("core:health")
|
||||
response = self.client.get(url)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertIn("status", response.data)
|
||||
self.assertIn("version", response.data)
|
||||
self.assertIn("checks", response.data)
|
||||
self.assertIn("database", response.data["checks"])
|
||||
|
||||
def test_health_check_database_up(self):
|
||||
"""Test health check reports database as up"""
|
||||
url = reverse("core:health")
|
||||
response = self.client.get(url)
|
||||
|
||||
self.assertEqual(response.data["checks"]["database"]["status"], "up")
|
||||
self.assertIn("latency_ms", response.data["checks"]["database"])
|
||||
|
||||
|
||||
class LivenessViewTest(APITestCase):
|
||||
"""Tests for LivenessView"""
|
||||
|
||||
def test_liveness_url_reverse(self):
|
||||
"""Test reverse URL resolution for liveness"""
|
||||
url = reverse("core:liveness")
|
||||
self.assertEqual(url, "/health/live/")
|
||||
|
||||
def test_liveness_returns_alive(self):
|
||||
"""Test liveness probe returns alive status"""
|
||||
url = reverse("core:liveness")
|
||||
response = self.client.get(url)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data["status"], "alive")
|
||||
|
||||
|
||||
class ReadinessViewTest(APITestCase):
|
||||
"""Tests for ReadinessView"""
|
||||
|
||||
def test_readiness_url_reverse(self):
|
||||
"""Test reverse URL resolution for readiness"""
|
||||
url = reverse("core:readiness")
|
||||
self.assertEqual(url, "/health/ready/")
|
||||
|
||||
def test_readiness_returns_ready(self):
|
||||
"""Test readiness probe returns ready when DB is available"""
|
||||
url = reverse("core:readiness")
|
||||
response = self.client.get(url)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data["status"], "ready")
|
||||
|
||||
|
||||
class APIVersioningURLTest(APITestCase):
|
||||
"""Tests for API versioning URL structure"""
|
||||
|
||||
def test_api_v1_user_register_reverse(self):
|
||||
"""Test reverse URL for user registration"""
|
||||
url = reverse("api_v1:user:register")
|
||||
self.assertEqual(url, "/api/v1/users/register/")
|
||||
|
||||
def test_api_v1_user_login_reverse(self):
|
||||
"""Test reverse URL for user login"""
|
||||
url = reverse("api_v1:user:login")
|
||||
self.assertEqual(url, "/api/v1/users/login/")
|
||||
|
||||
def test_api_v1_user_logout_reverse(self):
|
||||
"""Test reverse URL for user logout"""
|
||||
url = reverse("api_v1:user:logout")
|
||||
self.assertEqual(url, "/api/v1/users/logout/")
|
||||
|
||||
def test_api_v1_user_current_user_reverse(self):
|
||||
"""Test reverse URL for current user"""
|
||||
url = reverse("api_v1:user:current_user")
|
||||
self.assertEqual(url, "/api/v1/users/me/")
|
||||
|
||||
def test_api_v1_user_token_refresh_reverse(self):
|
||||
"""Test reverse URL for token refresh"""
|
||||
url = reverse("api_v1:user:token_refresh")
|
||||
self.assertEqual(url, "/api/v1/users/token/refresh/")
|
||||
|
||||
def test_api_v1_user_password_change_reverse(self):
|
||||
"""Test reverse URL for password change"""
|
||||
url = reverse("api_v1:user:password_change")
|
||||
self.assertEqual(url, "/api/v1/users/password/change/")
|
||||
Reference in New Issue
Block a user