<commit_before>import pytest

from moulinette.utils.filesystem import read_toml

from yunohost.domain import domain_add, domain_remove
from yunohost.dns import (
    DOMAIN_REGISTRAR_LIST_PATH,
    _get_dns_zone_for_domain,
    _get_registrar_config_section,
    _build_dns_conf,
)


def setup_function(function):

    clean()


def teardown_function(function):

    clean()


def clean():
    pass


# DNS utils testing
def test_get_dns_zone_from_domain_existing():
    assert _get_dns_zone_for_domain("yunohost.org") == "yunohost.org"
    assert _get_dns_zone_for_domain("donate.yunohost.org") == "yunohost.org"
    assert _get_dns_zone_for_domain("fr.wikipedia.org") == "wikipedia.org"
    assert _get_dns_zone_for_domain("www.fr.wikipedia.org") == "wikipedia.org"
    assert _get_dns_zone_for_domain("non-existing-domain.yunohost.org") == "yunohost.org"
    assert _get_dns_zone_for_domain("yolo.nohost.me") == "nohost.me"
    assert _get_dns_zone_for_domain("foo.yolo.nohost.me") == "nohost.me"
    assert _get_dns_zone_for_domain("yolo.test") == "test"
    assert _get_dns_zone_for_domain("foo.yolo.test") == "test"


# Domain registrar testing
def test_registrar_list_integrity():
    assert read_toml(DOMAIN_REGISTRAR_LIST_PATH)


def test_magic_guess_registrar_weird_domain():
    assert _get_registrar_config_section("yolo.test")["registrar"]["value"] is None


def test_magic_guess_registrar_ovh():
    assert _get_registrar_config_section("yolo.yunohost.org")["registrar"]["value"] == "ovh"


def test_magic_guess_registrar_yunodyndns():
    assert _get_registrar_config_section("yolo.nohost.me")["registrar"]["value"] == "yunohost"


@pytest.fixture
def example_domain():
    domain_add("example.tld")
    yield "example_tld"
    domain_remove("example.tld")


def test_domain_dns_suggest(example_domain):

    assert _build_dns_conf(example_domain)

#def domain_dns_push(domain, dry_run):
#    import yunohost.dns
#    return yunohost.dns.domain_registrar_push(domain, dry_run)<commit_msg>dns: fix typo in tests<commit_after>import pytest

from moulinette.utils.filesystem import read_toml

from yunohost.domain import domain_add, domain_remove
from yunohost.dns import (
    DOMAIN_REGISTRAR_LIST_PATH,
    _get_dns_zone_for_domain,
    _get_registrar_config_section,
    _build_dns_conf,
)


def setup_function(function):

    clean()


def teardown_function(function):

    clean()


def clean():
    pass


# DNS utils testing
def test_get_dns_zone_from_domain_existing():
    assert _get_dns_zone_for_domain("yunohost.org") == "yunohost.org"
    assert _get_dns_zone_for_domain("donate.yunohost.org") == "yunohost.org"
    assert _get_dns_zone_for_domain("fr.wikipedia.org") == "wikipedia.org"
    assert _get_dns_zone_for_domain("www.fr.wikipedia.org") == "wikipedia.org"
    assert _get_dns_zone_for_domain("non-existing-domain.yunohost.org") == "yunohost.org"
    assert _get_dns_zone_for_domain("yolo.nohost.me") == "nohost.me"
    assert _get_dns_zone_for_domain("foo.yolo.nohost.me") == "nohost.me"
    assert _get_dns_zone_for_domain("yolo.test") == "test"
    assert _get_dns_zone_for_domain("foo.yolo.test") == "test"


# Domain registrar testing
def test_registrar_list_integrity():
    assert read_toml(DOMAIN_REGISTRAR_LIST_PATH)


def test_magic_guess_registrar_weird_domain():
    assert _get_registrar_config_section("yolo.test")["registrar"]["value"] is None


def test_magic_guess_registrar_ovh():
    assert _get_registrar_config_section("yolo.yunohost.org")["registrar"]["value"] == "ovh"


def test_magic_guess_registrar_yunodyndns():
    assert _get_registrar_config_section("yolo.nohost.me")["registrar"]["value"] == "yunohost"


@pytest.fixture
def example_domain():
    domain_add("example.tld")
    yield "example.tld"
    domain_remove("example.tld")


def test_domain_dns_suggest(example_domain):

    assert _build_dns_conf(example_domain)

#def domain_dns_push(domain, dry_run):
#    import yunohost.dns
#    return yunohost.dns.domain_registrar_push(domain, dry_run)
{'fraction_non_alphanumeric': 0.11457036114570361, 'fraction_numerical': 0.0, 'mean_word_length': 5.924137931034482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3373133', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1562, 'n_words': 205}