|
1 | 1 | import json |
| 2 | +import re |
2 | 3 | from io import StringIO |
3 | 4 |
|
4 | 5 | from django.conf import settings |
@@ -64,24 +65,36 @@ def test_health_check_api_endpoint_works(self): |
64 | 65 | and settings.HEALTH_CHECK_URL_TOKEN is not None |
65 | 66 | else "" |
66 | 67 | ) |
67 | | - response = self.client.get(f"/api/v1/health{token}?format=json") |
| 68 | + response = self.client.get(f"/health{token}?format=json") |
68 | 69 | self.assertEqual(response.status_code, status.HTTP_200_OK) |
69 | 70 | response.data = json.loads(response.content) |
70 | | - self.assertIn("Cache backend: default", response.data) |
71 | | - self.assertIn("DatabaseBackend", response.data) |
72 | | - self.assertIn("DefaultFileStorageHealthCheck", response.data) |
73 | | - self.assertIn("MigrationsHealthCheck", response.data) |
74 | | - self.assertIn("RedisHealthCheck", response.data) |
| 71 | + self.assertIn("Cache(alias='default')", response.data) |
| 72 | + self.assertIn("Database(alias='default')", response.data) |
| 73 | + self.assertIn( |
| 74 | + "Mail(backend='django.core.mail.backends.dummy.EmailBackend')", |
| 75 | + response.data, |
| 76 | + ) |
| 77 | + self.assertIn("Storage(alias='default')", response.data) |
| 78 | + self.assertTrue( |
| 79 | + any( |
| 80 | + re.search(r"Redis\(host='[^']+', port=6379\)", key) |
| 81 | + for key in response.data |
| 82 | + ) |
| 83 | + ) |
75 | 84 |
|
76 | 85 | def test_health_check_management_command_works(self): |
77 | 86 | with StringIO() as out: |
78 | | - call_command("health_check", stdout=out) |
79 | | - self.assertEqual(out.getvalue().count("working"), 5) |
80 | | - self.assertIn("Cache backend: default", out.getvalue()) |
81 | | - self.assertIn("DatabaseBackend", out.getvalue()) |
82 | | - self.assertIn("DefaultFileStorageHealthCheck", out.getvalue()) |
83 | | - self.assertIn("MigrationsHealthCheck", out.getvalue()) |
84 | | - self.assertIn("RedisHealthCheck", out.getvalue()) |
| 87 | + with self.assertRaises(SystemExit) as cm: |
| 88 | + call_command("health_check", "health_check", "--no-http", stdout=out) |
| 89 | + self.assertEqual(cm.exception.code, 0) |
| 90 | + self.assertIn("Cache(alias='default')", out.getvalue()) |
| 91 | + self.assertIn("Database(alias='default')", out.getvalue()) |
| 92 | + self.assertIn( |
| 93 | + "Mail(backend='django.core.mail.backends.dummy.EmailBackend')", |
| 94 | + out.getvalue(), |
| 95 | + ) |
| 96 | + self.assertIn("Storage(alias='default')", out.getvalue()) |
| 97 | + self.assertRegex(out.getvalue(), r"Redis\(host='[^']+', port=6379\)") |
85 | 98 |
|
86 | 99 | def test_user_profile_avatar_json_validation(self): |
87 | 100 | self.user.refresh_from_db() |
|
0 commit comments