Example #1
0
 def get(self, request, *args, **kwargs):
     try:
         report, is_healthy = create_report(request=request)
     except PermissionDenied:
         response = HttpResponse(status=401)
         response['WWW-Authenticate'] = 'Basic realm="Healthchecks"'
         return response
     status_code = 200 if is_healthy else _get_err_status_code()
     return JsonResponse(report, status=status_code)
Example #2
0
def test_create_report(settings):
    settings.HEALTH_CHECKS = {
        'database': 'django_healthchecks.contrib.check_dummy_true'
    }
    result, is_healthy = checker.create_report()
    expected = {'database': True}

    assert result == expected
    assert is_healthy is True
Example #3
0
 def get(self, request, *args, **kwargs):
     try:
         report, is_healthy = create_report(request=request)
     except PermissionDenied:
         response = HttpResponse(status=401)
         response['WWW-Authenticate'] = 'Basic realm="Healthchecks"'
         return response
     status_code = 200 if is_healthy else _get_err_status_code()
     return JsonResponse(report, status=status_code)
def test_create_report(settings):
    settings.HEALTH_CHECKS = {
        'database': 'django_healthchecks.contrib.check_dummy_true'
    }
    result = checker.create_report()
    expected = {
        'database': True
    }

    assert result == expected
Example #5
0
def test_create_report_err(settings):
    settings.HEALTH_CHECKS = {
        'database': 'django_healthchecks.contrib.check_dummy_true',
        'i_fail': 'django_healthchecks.contrib.check_dummy_false',
    }
    result, is_healthy = checker.create_report()
    expected = {
        'database': True,
        'i_fail': False,
    }

    assert result == expected
    assert is_healthy is False
def test_create_report_err(settings):
    settings.HEALTH_CHECKS = {
        'database': 'django_healthchecks.contrib.check_dummy_true',
        'i_fail': 'django_healthchecks.contrib.check_dummy_false',
    }
    result, is_healthy = checker.create_report()
    expected = {
        'database': True,
        'i_fail': False,
    }

    assert result == expected
    assert is_healthy is False
Example #7
0
def test_service_timeout(settings):
    settings.HEALTH_CHECKS = {
        'database': 'django_healthchecks.contrib.check_dummy_true',
        'timeout_service': 'http://timeout.com/api/healthchecks/',
    }

    with requests_mock.Mocker() as mock:
        mock.register_uri('GET',
                          'http://timeout.com/api/healthchecks/',
                          exc=requests.exceptions.Timeout)
        result, is_healthy = checker.create_report()

    expected = {'database': True, 'timeout_service': False}

    assert result == expected
    assert is_healthy is False
Example #8
0
def test_create_report(settings):
    settings.HEALTH_CHECKS = {
        "database": "django_healthchecks.contrib.check_dummy_true",
        "remote_service": "https://test.com/api/healthchecks/",
    }

    with requests_mock.Mocker() as mock:
        mock.get("https://test.com/api/healthchecks/", text='{"cache_default": true}')
        result, is_healthy = checker.create_report()

    expected = {
        "database": True,
        "remote_service": {"cache_default": True},
    }

    assert result == expected
    assert is_healthy is True
Example #9
0
def test_service_timeout(settings):
    settings.HEALTH_CHECKS = {
        "database": "django_healthchecks.contrib.check_dummy_true",
        "timeout_service": "http://timeout.com/api/healthchecks/",
    }

    with requests_mock.Mocker() as mock:
        mock.register_uri(
            "GET",
            "http://timeout.com/api/healthchecks/",
            exc=requests.exceptions.Timeout,
        )
        result, is_healthy = checker.create_report()

    expected = {"database": True, "timeout_service": False}

    assert result == expected
    assert is_healthy is False
Example #10
0
 def get(self, request, *args, **kwargs):
     report = create_report()
     return JsonResponse(report)