11from django .test import TestCase , override_settings
2- from django .apps import apps
32
43
54class SimpleTest (TestCase ):
65 def test_liveness (self ):
7- apps .get_app_config ('simple_health_check' ).register_checks ()
8-
96 response = self .client .get ('/liveness/' )
10- self .assertTrue (response .status_code == 200 )
11- self .assertTrue (response .content == b'ok' )
7+ self .assertContains (response , b'ok' )
128
139 def test_readiness (self ):
14- apps .get_app_config ('simple_health_check' ).register_checks ()
15-
1610 response = self .client .get ('/readiness/' )
17- self .assertTrue (response .status_code == 200 )
18- self .assertTrue (response .content == b'ok' )
11+ self .assertContains (response , b'ok' )
1912
2013 @override_settings (SIMPLE_HEALTH_CHECKS = {'simple_health_check.checks.dummy.DummyFalse' : None })
2114 def test_no_readiness (self ):
22- apps .get_app_config ('simple_health_check' ).register_checks ()
23-
2415 response = self .client .get ('/readiness/' )
25- self .assertTrue (response .status_code == 500 )
26- self .assertTrue (response .content == b'down' )
16+ self .assertContains (response , b'down' , status_code = 500 )
2717
2818 @override_settings (
2919 CACHES = {
@@ -32,11 +22,8 @@ def test_no_readiness(self):
3222 SIMPLE_HEALTH_CHECKS = {'simple_health_check.checks.caches.CacheBackends' : None },
3323 )
3424 def test_caches (self ):
35- apps .get_app_config ('simple_health_check' ).register_checks ()
36-
3725 response = self .client .get ('/readiness/' )
38- self .assertTrue (response .status_code == 200 )
39- self .assertTrue (response .content == b'ok' )
26+ self .assertContains (response , b'ok' )
4027
4128 @override_settings (
4229 CACHES = {
@@ -51,11 +38,8 @@ def test_caches(self):
5138 },
5239 )
5340 def test_cache_aliases (self ):
54- apps .get_app_config ('simple_health_check' ).register_checks ()
55-
5641 response = self .client .get ('/readiness/' )
57- self .assertTrue (response .status_code == 200 )
58- self .assertTrue (response .content == b'ok' )
42+ self .assertContains (response , b'ok' )
5943
6044 @override_settings (
6145 CACHES = {
@@ -69,80 +53,59 @@ def test_cache_aliases(self):
6953 },
7054 )
7155 def test_cache_no_rediness (self ):
72- apps .get_app_config ('simple_health_check' ).register_checks ()
73-
7456 response = self .client .get ('/readiness/' )
75- self .assertTrue (response .status_code == 500 )
76- self .assertTrue (response .content == b'down' )
57+ self .assertContains (response , b'down' , status_code = 500 )
7758
7859 @override_settings (
7960 SIMPLE_HEALTH_CHECKS = {
8061 'simple_health_check.checks.ps.DiskUsage' : None ,
8162 },
8263 )
8364 def test_ps_disk_usage_no_value (self ):
84- apps .get_app_config ('simple_health_check' ).register_checks ()
85-
8665 response = self .client .get ('/readiness/' )
87- self .assertTrue (response .status_code == 200 )
88- self .assertTrue (response .content == b'ok' )
66+ self .assertContains (response , b'ok' )
8967
9068 @override_settings (
9169 SIMPLE_HEALTH_CHECKS = {
9270 'simple_health_check.checks.ps.DiskUsage' : dict (max_usage_percent = 99 ),
9371 },
9472 )
9573 def test_ps_disk_usage (self ):
96- apps .get_app_config ('simple_health_check' ).register_checks ()
97-
9874 response = self .client .get ('/readiness/' )
99- self .assertTrue (response .status_code == 200 )
100- self .assertTrue (response .content == b'ok' )
75+ self .assertContains (response , b'ok' )
10176
10277 @override_settings (
10378 SIMPLE_HEALTH_CHECKS = {
10479 'simple_health_check.checks.ps.DiskUsage' : dict (max_usage_percent = 0.001 ),
10580 },
10681 )
10782 def test_ps_disk_usage_no_rediness (self ):
108- apps .get_app_config ('simple_health_check' ).register_checks ()
109-
11083 response = self .client .get ('/readiness/' )
111- self .assertTrue (response .status_code == 500 )
112- self .assertTrue (response .content == b'down' )
84+ self .assertContains (response , b'down' , status_code = 500 )
11385
11486 @override_settings (
11587 SIMPLE_HEALTH_CHECKS = {
11688 'simple_health_check.checks.ps.MemoryUsage' : None ,
11789 },
11890 )
11991 def test_ps_memory_usage_no_value (self ):
120- apps .get_app_config ('simple_health_check' ).register_checks ()
121-
12292 response = self .client .get ('/readiness/' )
123- self .assertTrue (response .status_code == 200 )
124- self .assertTrue (response .content == b'ok' )
93+ self .assertContains (response , b'ok' )
12594
12695 @override_settings (
12796 SIMPLE_HEALTH_CHECKS = {
12897 'simple_health_check.checks.ps.MemoryUsage' : dict (min_memory_mb = 10 ),
12998 },
13099 )
131100 def test_ps_memory_usage (self ):
132- apps .get_app_config ('simple_health_check' ).register_checks ()
133-
134101 response = self .client .get ('/readiness/' )
135- self .assertTrue (response .status_code == 200 )
136- self .assertTrue (response .content == b'ok' )
102+ self .assertContains (response , b'ok' )
137103
138104 @override_settings (
139105 SIMPLE_HEALTH_CHECKS = {
140106 'simple_health_check.checks.ps.MemoryUsage' : dict (min_memory_mb = 100_000 ),
141107 },
142108 )
143109 def test_ps_memory_usage_no_rediness (self ):
144- apps .get_app_config ('simple_health_check' ).register_checks ()
145-
146110 response = self .client .get ('/readiness/' )
147- self .assertTrue (response .status_code == 500 )
148- self .assertTrue (response .content == b'down' )
111+ self .assertContains (response , b'down' , status_code = 500 )
0 commit comments