from datetime import timedelta

import pytest

from django.urls import reverse
from django.core.files.uploadedfile import SimpleUploadedFile
from django.utils import timezone

from conference.models import TALK_STATUS, TALK_LEVEL
from p3.templatetags import sessions
from tests.factories import UserFactory, TalkFactory, ConferenceTagFactory, TalkSpeakerFactory, SpeakerFactory
from tests.common_tools import get_default_conference, redirects_to, template_used, make_user

pytestmark = [pytest.mark.django_db]


def test_spealers_templatetag():
    names = [
        # these 2 should not be listed
        ("To Be", "Announced"),
        ("Tobey", "Announced"),
        # these 2 should be groupped under D
        ("Dan", "Schmoe"),
        ("Đan", "Again"),
        # these 2 should be groupped under A
        ("Anna", "Doe"),
        ("Ändy", "Unicode"),
        # Make sure we preserve unicode for non-latin names.
        # the numbers are here to work around quirks of how the atendeeprofile slugs are generated by the factory
        ("艾", "未未1"),
        ("Никола", "Тесла2"),
    ]
    conf = get_default_conference()
    speakers = [
        TalkSpeakerFactory(
            speaker__user=make_user(first_name=f_name, last_name=l_name),
            talk__status='accepted',
        )
        for (i, (f_name, l_name)) in enumerate(names)
    ]
    data = sessions.speakers(conf.code)
    assert set(data['groups'].keys()) == {
        'A',
        'D',
        '艾',
        'Н',  # this is not an H it's https://en.wikipedia.org/wiki/En_(Cyrillic)
    }
    assert [s['fullname'] for s in data['groups']['D']] == ["Đan Again", "Dan Schmoe"]
    assert [s['fullname'] for s in data['groups']['A']] == ["Ändy Unicode", "Anna Doe"]
    assert [s['fullname'] for s in data['groups']['艾']] == ["艾 未未1"]
    assert [s['fullname'] for s in data['groups']['Н']] == ["Никола Тесла2"]

@@ -1,367 +1,88 @@
-from datetime import timedelta%0A%0Aimport pytest%0A%0Afrom django.urls import reverse%0Afrom django.core.files.uploadedfile import SimpleUploadedFile%0Afrom django.utils import timezone%0A%0Afrom conference.models import TALK_STATUS, TALK_LEVEL%0Afrom p3.templatetags import sessions%0Afrom tests.factories import UserFactory, TalkFactory, ConferenceTagFactory, TalkSpeakerFactory, 
+import pytest%0A%0Afrom p3.templatetags import sessions%0Afrom tests.factories import Talk
 Spea
@@ -150,37 +150,8 @@
 nce,
- redirects_to, template_used,
  mak
@@ -210,17 +210,17 @@
 est_spea
-l
+k
 ers_temp

fix typo in test_p3_templatetags test name (#1277)