Completed
Push — main ( dc9c2e...80557c )
by Jochen
05:20
created

test_healthcheck_fail()   A

Complexity

Conditions 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nop 2
dl 0
loc 15
rs 9.8
c 0
b 0
f 0
1
"""
2
:Copyright: 2006-2020 Jochen Kupperschmidt
3
:License: Modified BSD, see LICENSE for details.
4
"""
5
6
from unittest.mock import patch
7
8
import pytest
9
10
11
# Test against an admin app because that doesn't require setup of brand
12
# party. After all, both admin and party apps should react the same.
13
14
15
def test_healthcheck_ok(client):
16
    expected_media_type = 'application/health+json'
17
18
    response = client.get('/health')
19
20
    assert response.status_code == 200
21
    assert response.content_type == expected_media_type
22
    assert response.mimetype == expected_media_type
23
    assert response.get_json() == {
24
        'status': 'ok',
25
        'details': {
26
            'rdbms': [{'status': 'ok'}],
27
        },
28
    }
29
30
31
@patch('byceps.blueprints.monitoring.healthcheck.views._is_rdbms_ok')
32
def test_healthcheck_fail(is_rdbms_ok_mock, client):
33
    expected_media_type = 'application/health+json'
34
35
    is_rdbms_ok_mock.return_value = False
36
37
    response = client.get('/health')
38
39
    assert response.status_code == 503
40
    assert response.content_type == expected_media_type
41
    assert response.mimetype == expected_media_type
42
    assert response.get_json() == {
43
        'status': 'ok',
44
        'details': {
45
            'rdbms': [{'status': 'fail'}],
46
        },
47
    }
48
49
50
@pytest.fixture(scope='module')
51
def client(make_client, admin_app):
52
    return make_client(admin_app)
53