~homeworkprod/byceps

ef0d0fa26bfd22c281c54bc348877afd0a7ee9d7 — Jochen Kupperschmidt 5 months ago ddfc0af
Use regex to match user metrics
1 files changed, 11 insertions(+), 6 deletions(-)

M tests/integration/blueprints/metrics/test_metrics.py
M tests/integration/blueprints/metrics/test_metrics.py => tests/integration/blueprints/metrics/test_metrics.py +11 -6
@@ 3,6 3,8 @@
:License: Modified BSD, see LICENSE for details.
"""

import re

import pytest




@@ 26,13 28,16 @@ def test_metrics(client):
    assert response.status_code == 200
    assert response.content_type == 'text/plain; version=0.0.4; charset=utf-8'
    assert response.mimetype == 'text/plain'
    assert response.get_data(as_text=True) == (
        'users_active_count 0\n'
        'users_uninitialized_count 0\n'
        'users_suspended_count 0\n'
        'users_deleted_count 0\n'
        'users_total_count 0\n'

    # Not a full match as there can be other metrics, too.
    regex = re.compile(
        'users_active_count \\d+\n'
        'users_uninitialized_count \\d+\n'
        'users_suspended_count \\d+\n'
        'users_deleted_count \\d+\n'
        'users_total_count \\d+\n'
    )
    assert regex.search(response.get_data(as_text=True)) is not None


@pytest.mark.parametrize('config_overrides', [{'METRICS_ENABLED': False}])