コード例 #1
0
    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'
コード例 #2
0
    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'
コード例 #3
0
    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'
コード例 #4
0
    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
コード例 #5
0
    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
コード例 #6
0
    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'
コード例 #7
0
    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()]
コード例 #8
0
    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'
コード例 #9
0
    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
コード例 #10
0
    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'
コード例 #11
0
    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()}
コード例 #12
0
    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
コード例 #13
0
    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()]
コード例 #14
0
    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
コード例 #15
0
    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
コード例 #16
0
    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()}
コード例 #17
0
    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"]
コード例 #18
0
    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
コード例 #19
0
    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
コード例 #20
0
    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
コード例 #21
0
    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
            }]
        }
コード例 #22
0
    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
コード例 #23
0
    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'
                                     }))
コード例 #24
0
 def setup(self):
     plugin_dir.reset()
     plugin_dir.register(FailPlugin)
     plugin_dir.register(OkPlugin)
     yield
     plugin_dir.reset()
コード例 #25
0
 def setup(self):
     plugin_dir.reset()
     plugin_dir.register(FakePlugin)
     yield
     plugin_dir.reset()