def test_success_accept_order__reverse(self, client): class JSONSuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(JSONSuccessBackend) response = client.get(self.url, HTTP_ACCEPT='text/html; q=0.1, application/xhtml+xml; q=0.1, application/json') assert response['content-type'] == 'application/json'
def test_format_override(self, client): class JSONSuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(JSONSuccessBackend) response = client.get(self.url + '?format=json', HTTP_ACCEPT='text/html') assert response['content-type'] == 'application/json'
def test_success_unsupported_accept(self, client): class SuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(SuccessBackend) response = client.get(self.url, HTTP_ACCEPT='application/octet-stream') assert response['content-type'] == 'text/html; charset=utf-8'
def test_success_accept_xhtml(self, client): class SuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(SuccessBackend) response = client.get(self.url, HTTP_ACCEPT='application/xhtml+xml') assert response['content-type'] == 'text/html; charset=utf-8' assert response.status_code == 200
def test_success_accept_json(self, api_client): class JSONSuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(JSONSuccessBackend) response = api_client.get(self.url, HTTP_ACCEPT='application/json') assert response['content-type'] == 'application/json' assert response.status_code == 200
def test_format_no_accept_header(self, client): class JSONSuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(JSONSuccessBackend) response = client.get(self.url) assert response.status_code == 200, response.content.decode('utf-8') assert response['content-type'] == 'text/html; charset=utf-8'
def test_error_json(self, client): class JSONErrorBackend(BaseHealthCheckBackend): def run_check(self): self.add_error('JSON Error') plugin_dir.reset() plugin_dir.register(JSONErrorBackend) response = client.get(self.url, HTTP_ACCEPT='application/json') assert response.status_code == 500, response.content.decode('utf-8') assert 'JSON Error' in json.loads(response.content.decode('utf-8'))[JSONErrorBackend().identifier()]
def test_format_no_accept_header(self, api_client): class JSONSuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(JSONSuccessBackend) response = api_client.get(self.url) assert response.status_code == 200, response.content.decode('utf-8') assert response['content-type'] == 'text/html; charset=utf-8'
def test_error(self, client): class MyBackend(BaseHealthCheckBackend): def run_check(self): self.add_error('Super Fail!') plugin_dir.reset() plugin_dir.register(MyBackend) response = client.get(self.url) assert response.status_code == 503, response.content.decode('utf-8') assert b'Super Fail!' in response.content
def test_success_unsupported_accept(self, client): class SuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(SuccessBackend) response = client.get(self.url, HTTP_ACCEPT='application/octet-stream') assert response['content-type'] == 'text/plain' assert response.status_code == 406 assert response.content == b'Not Acceptable: Supported content types: text/html, application/json'
def test_success_json(self, client): class JSONSuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(JSONSuccessBackend) response = client.get(self.url, HTTP_ACCEPT='application/json') assert response.status_code == 200, response.content.decode('utf-8') assert json.loads(response.content.decode('utf-8')) == \ {JSONSuccessBackend().identifier(): JSONSuccessBackend().pretty_status()}
def test_error(self, client): class MyBackend(BaseHealthCheckBackend): def check_status(self): self.add_error('Super Fail!') plugin_dir.reset() plugin_dir.register(MyBackend) response = client.get(self.url) assert response.status_code == 500, response.content.decode('utf-8') assert response['content-type'] == 'text/html; charset=utf-8' assert b'Super Fail!' in response.content
def test_error_param_json(self, client): class JSONErrorBackend(BaseHealthCheckBackend): def run_check(self): self.add_error('JSON Error') plugin_dir.reset() plugin_dir.register(JSONErrorBackend) response = client.get(self.url, {'format': 'json'}) assert response.status_code == 500, response.content.decode('utf-8') assert response['content-type'] == 'application/json' assert 'JSON Error' in json.loads(response.content.decode('utf-8'))[JSONErrorBackend().identifier()]
def test_error(self, api_client): class MyBackend(BaseHealthCheckBackend): def check_status(self): self.add_error('Super Fail!') plugin_dir.reset() plugin_dir.register(MyBackend) response = api_client.get(self.url) assert response.status_code == 500, response.content.decode('utf-8') assert response['content-type'] == 'text/html; charset=utf-8' assert b'Super Fail!' in response.content
def test_non_critical(self, client): class MyBackend(BaseHealthCheckBackend): critical_service = False def check_status(self): self.add_error('Super Fail!') plugin_dir.reset() plugin_dir.register(MyBackend) response = client.get(self.url) assert response.status_code == 200, response.content.decode('utf-8') assert b'Super Fail!' in response.content
def test_success_param_json(self, client): class JSONSuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(JSONSuccessBackend) response = client.get(self.url, {'format': 'json'}) assert response.status_code == 200, response.content.decode('utf-8') assert response['content-type'] == 'application/json' assert json.loads(response.content.decode('utf-8')) == \ {JSONSuccessBackend().identifier(): JSONSuccessBackend().pretty_status()}
def test_error_param_json(self, api_client): class JSONErrorBackend(BaseHealthCheckBackend): def run_check(self): self.add_error('JSON Error') plugin_dir.reset() plugin_dir.register(JSONErrorBackend) response = api_client.get(self.url, {'format': 'json'}) assert response.status_code == 500, response.content.decode('utf-8') assert response['content-type'] == 'application/json' assert 'JSON Error' in json.loads( response.content.decode('utf-8'))["data"][0]["status"]
def test_success_unsupported_and_supported_accept(self, api_client): class SuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(SuccessBackend) response = api_client.get( self.url, HTTP_ACCEPT='application/octet-stream, application/json; q=0.9') assert response['content-type'] == 'application/json' assert response.status_code == 200
def test_success_accept_order(self, api_client): class JSONSuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(JSONSuccessBackend) response = api_client.get( self.url, HTTP_ACCEPT= 'text/html, application/xhtml+xml, application/json; q=0.9, */*; q=0.1' ) assert response['content-type'] == 'text/html; charset=utf-8' assert response.status_code == 200
def test_warning(self, client): class MyBackend(BaseHealthCheckBackend): def check_status(self): raise ServiceWarning('so so') plugin_dir.reset() plugin_dir.register(MyBackend) response = client.get(self.url) assert response.status_code == 500, response.content.decode('utf-8') assert b'so so' in response.content, response.content HEALTH_CHECK['WARNINGS_AS_ERRORS'] = False response = client.get(self.url) assert response.status_code == 200, response.content.decode('utf-8') assert b'so so' in response.content, response.content
def test_success_param_json(self, api_client): class JSONSuccessBackend(BaseHealthCheckBackend): def run_check(self): pass plugin_dir.reset() plugin_dir.register(JSONSuccessBackend) response = api_client.get(self.url, {'format': 'json'}) assert response.status_code == 200, response.content.decode('utf-8') assert response['content-type'] == 'application/json' assert json.loads(response.content.decode('utf-8')) == { "data": [{ "name": JSONSuccessBackend().identifier(), "status": JSONSuccessBackend().pretty_status(), "time_taken": None }] }
def test_warning(self, client): class MyBackend(BaseHealthCheckBackend): def check_status(self): raise ServiceWarning('so so') plugin_dir.reset() plugin_dir.register(MyBackend) response = client.get(self.url) assert response.status_code == 500, response.content.decode('utf-8') assert b'so so' in response.content, response.content HEALTH_CHECK['WARNINGS_AS_ERRORS'] = False response = client.get(self.url) assert response.status_code == 200, response.content.decode('utf-8') assert response['content-type'] == 'text/html; charset=utf-8' assert b'so so' in response.content, response.content
def ready(self): self.init_ngrok() plugin_dir.reset() from health_check.db.backends import DatabaseBackend from health_check.cache.backends import CacheBackend from health_check.contrib.celery.backends import CeleryHealthCheck from health_check.contrib.s3boto_storage.backends import S3BotoStorageHealthCheck from health_check.contrib.twilio.backends import TwilioHealthCheck plugin_dir.register(type('Database', (DatabaseBackend,), { 'description': 'The database is critical for a fully operational system' })) plugin_dir.register(type('Cache', (CacheBackend,), { 'description': 'The caching service is critical for a fully operational system' })) plugin_dir.register(type('TaskProcessing', (CeleryHealthCheck,), { 'description': 'Grade calculation, emails, text messages, and other ' 'deferred tasks', 'queues': current_app.amqp.queues })) plugin_dir.register(type('Twilio', (TwilioHealthCheck,), { 'critical': False, 'description': 'Reminders and other text message notifications', 'services': ['SMS'] })) if not settings.SERVE_LOCAL: plugin_dir.register(type('AWS', (S3BotoStorageHealthCheck,), { 'critical': False, 'description': 'Attachment and other file storage' }))
def setup(self): plugin_dir.reset() plugin_dir.register(FailPlugin) plugin_dir.register(OkPlugin) yield plugin_dir.reset()
def setup(self): plugin_dir.reset() plugin_dir.register(FakePlugin) yield plugin_dir.reset()