<commit_before>"""
:Copyright: 2006-2019 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

def test_metrics(make_admin_app):
    client = _get_test_client(make_admin_app, True)

    response = client.get('/metrics')

    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_enabled_count 0\n'
        'users_disabled_count 0\n'
        'users_suspended_count 0\n'
        'users_deleted_count 0\n'
        'users_total_count 0\n'
    )


def test_disabled_metrics(make_admin_app):
    client = _get_test_client(make_admin_app, False)

    response = client.get('/metrics')

    assert response.status_code == 404


def _get_test_client(make_admin_app, metrics_enabled):
    config_overrides = {'METRICS_ENABLED': metrics_enabled}
    app = make_admin_app(**config_overrides)

    return app.test_client()<commit_msg>Adjust metrics test to set up/tear down database<commit_after>"""
:Copyright: 2006-2019 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

import pytest

from ...conftest import database_recreated


# To be overridden by test parametrization
@pytest.fixture
def config_overrides():
    return {}


@pytest.fixture
def client(config_overrides, make_admin_app, db):
    app = make_admin_app(**config_overrides)
    with app.app_context():
        with database_recreated(db):
            yield app.test_client()


@pytest.mark.parametrize('config_overrides', [{'METRICS_ENABLED': True}])
def test_metrics(client):
    response = client.get('/metrics')

    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_enabled_count 0\n'
        'users_disabled_count 0\n'
        'users_suspended_count 0\n'
        'users_deleted_count 0\n'
        'users_total_count 0\n'
    )


@pytest.mark.parametrize('config_overrides', [{'METRICS_ENABLED': False}])
def test_disabled_metrics(client):
    response = client.get('/metrics')

    assert response.status_code == 404
{'fraction_non_alphanumeric': 0.11727842435094002, 'fraction_numerical': 0.020590868397493287, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2545017', 'n_tokens_mistral': 779, 'n_tokens_neox': 740, 'n_words': 147}