import pytest

from dnscms.utils import slugify
from events.models import EventCategory, EventOrganizer
from tests.conftest import GenericPageFactory


def test_slugify_transliterates_norwegian_letters():
    assert slugify("Bjørn") == "bjorn"
    assert slugify("Møterom") == "moterom"
    assert slugify("Forening for ÆØÅ") == "forening-for-aeoa"


def test_slugify_is_idempotent_on_ascii():
    assert slugify("already-clean-slug") == "already-clean-slug"


def test_page_save_transliterates_unicode_in_slug(home_page):
    page = GenericPageFactory(parent=home_page, title="Møterom", slug="møterom")

    assert page.slug == "moterom"


def test_page_save_leaves_clean_slug_untouched(home_page):
    page = GenericPageFactory(parent=home_page, title="Om oss", slug="om-oss")

    assert page.slug == "om-oss"


@pytest.mark.django_db
def test_event_organizer_save_transliterates_unicode_in_slug():
    organizer = EventOrganizer.objects.create(name="Bjørn", slug="bjørn")

    assert organizer.slug == "bjorn"


@pytest.mark.django_db
def test_event_category_save_transliterates_unicode_in_slug():
    category = EventCategory.objects.create(name="Mørkerom", slug="mørkerom")

    assert category.slug == "morkerom"
