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

import pytest

from byceps.services.country import service as country_service


@pytest.fixture
def party_app_with_app_context(party_app):
    with party_app.app_context():
        yield party_app


@pytest.mark.parametrize('name, alpha2, alpha3', [
    ('Deutschland', 'DE', 'DEU'),
    ('Österreich' , 'AT', 'AUT'),
])
def test_get_countries_contains_country(
    party_app_with_app_context, name, alpha2, alpha3
):
    countries = country_service.get_countries()

    country = find_by_name(countries, name)

    assert country is not None
    assert country.name == name
    assert country.alpha2 == alpha2
    assert country.alpha3 == alpha3


def test_get_country_names_contains_selected_items(party_app_with_app_context):
    actual = country_service.get_country_names()

    some_expected = frozenset([
        'Belgien',
        'Dänemark',
        'Deutschland',
        'Vereinigtes Königreich Großbritannien und Nordirland',
        'Frankreich',
        'Niederlande',
        'Österreich',
        'Schweiz',
    ])

    assert frozenset(actual).issuperset(some_expected)


def test_get_country_names_contains_no_duplicates(party_app_with_app_context):
    actual = country_service.get_country_names()

    assert len(actual) == len(set(actual))


# helpers


def find_by_name(countries, name):
    """Return the first country with that name, or `None` if none matches."""
    for country in countries:
        if country.name == name:
            return country<commit_msg>Use `party_app_with_db` instead of `party_app`<commit_after>"""
:Copyright: 2006-2020 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

import pytest

from byceps.services.country import service as country_service


@pytest.mark.parametrize('name, alpha2, alpha3', [
    ('Deutschland', 'DE', 'DEU'),
    ('Österreich' , 'AT', 'AUT'),
])
def test_get_countries_contains_country(
    party_app_with_db, name, alpha2, alpha3
):
    countries = country_service.get_countries()

    country = find_by_name(countries, name)

    assert country is not None
    assert country.name == name
    assert country.alpha2 == alpha2
    assert country.alpha3 == alpha3


def test_get_country_names_contains_selected_items(party_app_with_db):
    actual = country_service.get_country_names()

    some_expected = frozenset([
        'Belgien',
        'Dänemark',
        'Deutschland',
        'Vereinigtes Königreich Großbritannien und Nordirland',
        'Frankreich',
        'Niederlande',
        'Österreich',
        'Schweiz',
    ])

    assert frozenset(actual).issuperset(some_expected)


def test_get_country_names_contains_no_duplicates(party_app_with_db):
    actual = country_service.get_country_names()

    assert len(actual) == len(set(actual))


# helpers


def find_by_name(countries, name):
    """Return the first country with that name, or `None` if none matches."""
    for country in countries:
        if country.name == name:
            return country
{'fraction_non_alphanumeric': 0.10401043364851646, 'fraction_numerical': 0.010433648516465601, 'mean_word_length': 3.8087774294670846, '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': '7135555', 'n_tokens_mistral': 1001, 'n_tokens_neox': 986, 'n_words': 220}