<commit_before>from django.test import TestCase

from . import make_date
from spectator.factories import *
from spectator.models import Concert, Movie, MovieEvent,\
        Play, PlayProduction, PlayProductionEvent, Venue


class EventTestCase(TestCase):
    "Testing the parent class."

    def test_str(self):
        e = EventFactory()
        self.assertEqual(str(e), 'Event #{}'.format(e.pk))


class ConcertTestCase(TestCase):

    def test_str_with_title(self):
        "If concert has a title, that should be used."
        band = GroupCreatorFactory(name='Martha')
        concert = ConcertFactory(title='Indietracks 2017')
        ConcertRoleFactory(concert=concert, creator=band)
        self.assertEqual(str(concert), 'Indietracks 2017')

    def test_str_with_no_title_or_creators(self):
        "With no title or band names, it still has a __str__"
        concert = ConcertFactory(title='')
        self.assertEqual(str(concert), 'Concert #{}'.format(concert.pk))

    def test_str_with_no_title_one_creator(self):
        concert = ConcertFactory(title='')
        ConcertRoleFactory(
                concert=concert,
                creator=GroupCreatorFactory(name='Martha'),
                role_name='Headliner')
        self.assertEqual(str(concert), 'Martha')

    def test_str_with_no_title_several_creators(self):
        "If concert has no title, band names should be used."
        concert = ConcertFactory(title='')
        ConcertRoleFactory(
                concert=concert,
                creator=GroupCreatorFactory(name='<NAME>'),
                role_name='Headliner', role_order=1)
        ConcertRoleFactory(
                concert=concert,
                creator=GroupCreatorFactory(name='<NAME>'),
                role_name='Support', role_order=3)
        ConcertRoleFactory(
                concert=concert,
                creator=GroupCreatorFactory(name='Martha'),
                role_name='Support', role_order=2)
        self.assertEqual(str(concert), '<NAME>, Martha and The Tuts')

    def test_ordering(self):
        "Should order by date"
        c3 = ConcertFactory(date=make_date('2017-02-28'))
        c1 = ConcertFactory(date=make_date('2016-06-28'))
        c2 = ConcertFactory(date=make_date('2016-12-28'))
        concerts = Concert.objects.all()
        self.assertEqual(concerts[0], c1)
        self.assertEqual(concerts[1], c2)
        self.assertEqual(concerts[2], c3)

    def test_roles(self):
        "It can have multiple ConcertRoles."
        bob = IndividualCreatorFactory(name='Bob')
        martha = GroupCreatorFactory(name='Martha')
        concert = ConcertFactory()
        bobs_role = ConcertRoleFactory(concert=concert, creator=bob,
                                        role_name='Supporter', role_order=2)
        marthas_role = ConcertRoleFactory(concert=concert, creator=martha,
                                        role_name='Headliner', role_order=1)
        roles = concert.roles.all()
        self.assertEqual(len(roles), 2)
        self.assertEqual(roles[0], marthas_role)
        self.assertEqual(roles[1], bobs_role)<commit_msg>Fix concert ordering test<commit_after>from django.test import TestCase

from . import make_date
from spectator.factories import *
from spectator.models import Concert, Movie, MovieEvent,\
        Play, PlayProduction, PlayProductionEvent, Venue


class EventTestCase(TestCase):
    "Testing the parent class."

    def test_str(self):
        e = EventFactory()
        self.assertEqual(str(e), 'Event #{}'.format(e.pk))


class ConcertTestCase(TestCase):

    def test_str_with_title(self):
        "If concert has a title, that should be used."
        band = GroupCreatorFactory(name='Martha')
        concert = ConcertFactory(title='Indietracks 2017')
        ConcertRoleFactory(concert=concert, creator=band)
        self.assertEqual(str(concert), 'Indietracks 2017')

    def test_str_with_no_title_or_creators(self):
        "With no title or band names, it still has a __str__"
        concert = ConcertFactory(title='')
        self.assertEqual(str(concert), 'Concert #{}'.format(concert.pk))

    def test_str_with_no_title_one_creator(self):
        concert = ConcertFactory(title='')
        ConcertRoleFactory(
                concert=concert,
                creator=GroupCreatorFactory(name='Martha'),
                role_name='Headliner')
        self.assertEqual(str(concert), 'Martha')

    def test_str_with_no_title_several_creators(self):
        "If concert has no title, band names should be used."
        concert = ConcertFactory(title='')
        ConcertRoleFactory(
                concert=concert,
                creator=GroupCreatorFactory(name='<NAME>'),
                role_name='Headliner', role_order=1)
        ConcertRoleFactory(
                concert=concert,
                creator=GroupCreatorFactory(name='The Tuts'),
                role_name='Support', role_order=3)
        ConcertRoleFactory(
                concert=concert,
                creator=GroupCreatorFactory(name='Martha'),
                role_name='Support', role_order=2)
        self.assertEqual(str(concert), '<NAME>, Martha and The Tuts')

    def test_ordering(self):
        "Should order by title_sort"
        c3 = ConcertFactory(title='Concert')
        c1 = ConcertFactory(title='Abba Concert')
        c2 = ConcertFactory(title='The Big Concert')
        concerts = Concert.objects.all()
        self.assertEqual(concerts[0], c1)
        self.assertEqual(concerts[1], c2)
        self.assertEqual(concerts[2], c3)

    def test_roles(self):
        "It can have multiple ConcertRoles."
        bob = IndividualCreatorFactory(name='Bob')
        martha = GroupCreatorFactory(name='Martha')
        concert = ConcertFactory()
        bobs_role = ConcertRoleFactory(concert=concert, creator=bob,
                                        role_name='Supporter', role_order=2)
        marthas_role = ConcertRoleFactory(concert=concert, creator=martha,
                                        role_name='Headliner', role_order=1)
        roles = concert.roles.all()
        self.assertEqual(len(roles), 2)
        self.assertEqual(roles[0], marthas_role)
        self.assertEqual(roles[1], bobs_role)
{'fraction_non_alphanumeric': 0.10576923076923077, 'fraction_numerical': 0.011858974358974358, 'mean_word_length': 2.706057007125891, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5601446', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1780, 'n_words': 346}