Skip to content

Commit 1decdd3

Browse files
committed
Simplify tests
1 parent 9762527 commit 1decdd3

File tree

3 files changed

+23
-51
lines changed

3 files changed

+23
-51
lines changed

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='django-simple-health-check',
10-
version='0.3.0',
10+
version='0.3.1',
1111
description='Simple Django health check',
1212
long_description=open('README.md').read(),
1313
long_description_content_type='text/markdown',
@@ -41,4 +41,9 @@
4141
'Programming Language :: Python :: 3.9',
4242
'Programming Language :: Python :: 3.10',
4343
],
44+
keywords=[
45+
'django', 'monitoring', 'healthcheck', 'health-check', 'ping', 'health-checks', 'healthchecks',
46+
'liveness', 'readiness', 'liveness-detection', 'readiness-checker', 'django-health-check',
47+
'readiness-detection', 'liveness-checker',
48+
],
4449
)

simple_health_check/apps.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.apps import AppConfig
22
from django.conf import settings
3+
from django.core.signals import setting_changed
34
from django.utils.module_loading import import_string
45

56

@@ -9,7 +10,7 @@ class SimpleHealthCheckConfig(AppConfig):
910
checks = {}
1011

1112
@classmethod
12-
def register_checks(cls):
13+
def register_checks(cls, **kwargs):
1314
cls.checks = {}
1415
SIMPLE_HEALTH_CHECKS = getattr(settings, 'SIMPLE_HEALTH_CHECKS', None)
1516
if SIMPLE_HEALTH_CHECKS is None:
@@ -43,3 +44,6 @@ def check_all(cls):
4344

4445
def ready(self):
4546
self.register_checks()
47+
48+
49+
setting_changed.connect(SimpleHealthCheckConfig.register_checks)

simple_health_check/tests.py

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
from django.test import TestCase, override_settings
2-
from django.apps import apps
32

43

54
class 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

Comments
 (0)