def test_filters_by_event_kind(self):
        "It should only count events of the supplied event_kind."

        # It should include c1 and c2 as both have > 1 GigEvent:

        c1 = IndividualCreatorFactory()
        EventRoleFactory(event=GigEventFactory(), creator=c1)
        EventRoleFactory(event=GigEventFactory(), creator=c1)
        EventRoleFactory(event=GigEventFactory(), creator=c1)
        EventRoleFactory(event=CinemaEventFactory(), creator=c1)

        c2 = IndividualCreatorFactory()
        EventRoleFactory(event=GigEventFactory(), creator=c2)
        EventRoleFactory(event=GigEventFactory(), creator=c2)

        c3 = IndividualCreatorFactory()
        EventRoleFactory(event=CinemaEventFactory(), creator=c3)
        EventRoleFactory(event=CinemaEventFactory(), creator=c3)

        data = most_seen_creators_card(event_kind='gig')

        self.assertIn('object_list', data)
        self.assertEqual(len(data['object_list']), 2)
        self.assertEqual(data['object_list'][0], c1)
        self.assertEqual(data['object_list'][0].num_events, 3)
        self.assertEqual(data['object_list'][1], c2)
        self.assertEqual(data['object_list'][1].num_events, 2)
    def test_filters_by_work_kind_and_role_name(self):
        c1 = IndividualCreatorFactory()
        WorkRoleFactory(creator=c1, work=MovieFactory(), role_name='Director')
        WorkRoleFactory(creator=c1, work=MovieFactory(), role_name='Director')
        WorkRoleFactory(creator=c1, work=MovieFactory(), role_name='Director')
        WorkRoleFactory(creator=c1, work=MovieFactory(), role_name='')
        WorkRoleFactory(creator=c1, work=PlayFactory(), role_name='Director')

        c2 = IndividualCreatorFactory()
        WorkRoleFactory(creator=c2, work=MovieFactory(), role_name='Director')
        WorkRoleFactory(creator=c2, work=MovieFactory(), role_name='Director')

        c3 = IndividualCreatorFactory()
        WorkRoleFactory(creator=c3,
                        work=MovieFactory(),
                        role_name='Playwright')
        WorkRoleFactory(creator=c3, work=PlayFactory(), role_name='Director')

        data = most_seen_creators_by_works_card(work_kind='movie',
                                                role_name='Director')

        self.assertEqual(len(data['object_list']), 2)
        self.assertEqual(data['object_list'][0], c1)
        self.assertEqual(data['object_list'][0].num_works, 3)
        self.assertEqual(data['object_list'][1], c2)
        self.assertEqual(data['object_list'][1].num_works, 2)
示例#3
0
    def test_handle_empty_chart(self):
        "There was an error if all items in chart met the cutoff value."
        creator = IndividualCreatorFactory()
        creator.num_readings = 1

        chart = chartify([creator], 'num_readings', cutoff=1)

        self.assertEqual(len(chart), 0)
示例#4
0
 def test_context_counts(self):
     "It should include the individual and group counts."
     IndividualCreatorFactory.create_batch(2)
     GroupCreatorFactory.create_batch(3)
     response = views.CreatorListView.as_view()(self.request)
     self.assertIn('individual_count', response.context_data)
     self.assertEqual(response.context_data['individual_count'], 2)
     self.assertIn('group_count', response.context_data)
     self.assertEqual(response.context_data['group_count'], 3)
示例#5
0
    def test_show_creators_with_roles(self):
        "When a Publication has roles, display them."
        pub = PublicationFactory()
        PublicationRoleFactory(publication=pub,
                               creator=IndividualCreatorFactory(name='Bob'),
                               role_order=1)
        PublicationRoleFactory(publication=pub,
                               creator=IndividualCreatorFactory(name='Terry'),
                               role_order=2)

        ba = PublicationAdmin(Publication, self.site)
        self.assertEqual(ba.show_creators(pub), 'Bob, Terry')
示例#6
0
 def test_queryset_individual(self):
     "It should only include individuals in the creator_list"
     group = GroupCreatorFactory()
     indiv = IndividualCreatorFactory()
     response = views.CreatorListView.as_view()(self.request)
     self.assertEqual(len(response.context_data['creator_list']), 1)
     self.assertEqual(response.context_data['creator_list'][0], indiv)
示例#7
0
    def test_ensure_chartiness(self):
        "By default list should be empty if all objects have the same score."
        creators = IndividualCreatorFactory.create_batch(3)
        for c in creators:
            c.num_readings = 10

        chart = chartify(creators, 'num_readings')

        self.assertEqual(len(chart), 0)
示例#8
0
    def setUp(self):
        super().setUp()

        self.creators = IndividualCreatorFactory.create_batch(5)
        self.creators[0].num_readings = 10
        self.creators[1].num_readings = 8
        self.creators[2].num_readings = 8
        self.creators[3].num_readings = 6
        self.creators[4].num_readings = 0
示例#9
0
    def test_ensure_chartiness_false(self):
        "Should be possible to disable the behaviour."
        creators = IndividualCreatorFactory.create_batch(3)

        for c in creators:
            c.num_readings = 10

        chart = chartify(creators, 'num_readings', ensure_chartiness=False)

        self.assertEqual(len(chart), 3)
    def test_num(self):
        "It should return `num` items."
        for i in range(2, 6):
            # It'll cut off any with only 1 work, so:
            WorkRoleFactory.create_batch(i, creator=IndividualCreatorFactory())

        data = most_seen_creators_by_works_card(num=3)

        self.assertIn('object_list', data)
        self.assertEqual(len(data['object_list']), 3)
    def test_multiple_roles(self):
        "If a Creator has multiple roles on an Event, the Event should only be counted once."
        bob = IndividualCreatorFactory()
        ev = TheatreEventFactory()
        # 1 Event, 2 roles. Should only result in 1 Event in chart:
        EventRoleFactory(creator=bob, event=ev, role_name='Director')
        EventRoleFactory(creator=bob, event=ev, role_name='Playwright')

        creators = most_seen_creators()

        self.assertEqual(len(creators), 1)
        self.assertEqual(creators[0].num_events, 1)
示例#12
0
    def test_returns_queryset(self):
        "It should return 10 items by default."
        d = make_date('2017-02-15')

        for i in range(11):
            c = IndividualCreatorFactory()
            pub = PublicationFactory()
            PublicationRoleFactory(publication=pub, creator=c, role_name='')
            ReadingFactory(publication=pub, start_date=d, end_date=d)

        creators = most_read_creators()

        self.assertEqual(len(creators), 10)
示例#13
0
    def test_num(self):
        "It should return `num` items."
        d = make_date('2017-02-15')

        for i in range(4):
            c = IndividualCreatorFactory()
            pub = PublicationFactory()
            PublicationRoleFactory(publication=pub, creator=c, role_name='')
            ReadingFactory(publication=pub, start_date=d, end_date=d)

        creators = most_read_creators(num=3)

        self.assertEqual(len(creators), 3)
    def test_filters_by_role_name(self):
        c1 = IndividualCreatorFactory()
        WorkRoleFactory(creator=c1, role_name='Director')
        WorkRoleFactory(creator=c1, role_name='Director')
        WorkRoleFactory(creator=c1, role_name='Director')
        WorkRoleFactory(creator=c1, role_name='')

        c2 = IndividualCreatorFactory()
        WorkRoleFactory(creator=c2, role_name='Director')
        WorkRoleFactory(creator=c2, role_name='Director')

        c3 = IndividualCreatorFactory()
        WorkRoleFactory(creator=c3, role_name='Playwright')
        WorkRoleFactory(creator=c3, role_name='Playwright')

        data = most_seen_creators_by_works(role_name='Director')

        self.assertEqual(len(data), 2)
        self.assertEqual(data[0], c1)
        self.assertEqual(data[0].num_works, 3)
        self.assertEqual(data[1], c2)
        self.assertEqual(data[1].num_works, 2)
    def test_filters_by_work_kind(self):
        c1 = IndividualCreatorFactory()
        WorkRoleFactory(work=MovieFactory(), creator=c1)
        WorkRoleFactory(work=MovieFactory(), creator=c1)
        WorkRoleFactory(work=MovieFactory(), creator=c1)
        WorkRoleFactory(work=PlayFactory(), creator=c1)

        c2 = IndividualCreatorFactory()
        WorkRoleFactory(work=MovieFactory(), creator=c2)
        WorkRoleFactory(work=MovieFactory(), creator=c2)

        c3 = IndividualCreatorFactory()
        WorkRoleFactory(work=PlayFactory(), creator=c3)
        WorkRoleFactory(work=PlayFactory(), creator=c3)

        data = most_seen_creators_by_works(work_kind='movie')

        self.assertEqual(len(data), 2)
        self.assertEqual(data[0], c1)
        self.assertEqual(data[0].num_works, 3)
        self.assertEqual(data[1], c2)
        self.assertEqual(data[1].num_works, 2)
示例#16
0
    def test_output_can_change(self):
        creator = IndividualCreatorFactory(pk=5)
        perms = [
            'spectator.can_edit_creator',
        ]

        result = change_object_link_card(creator, perms)
        self.assertTrue(result['display_link'])
        if get_version() < StrictVersion('1.9.0'):
            self.assertEqual(result['change_url'],
                             '/admin/spectator_core/creator/5/')
        else:
            self.assertEqual(result['change_url'],
                             '/admin/spectator_core/creator/5/change/')
    def test_returns_correct_data(self):
        for i in range(2, 13):
            # It'll cut off any with only 1 work, so:
            WorkRoleFactory.create_batch(i, creator=IndividualCreatorFactory())

        data = most_seen_creators_by_works_card()

        self.assertIn('card_title', data)
        self.assertIn('score_attr', data)
        self.assertIn('object_list', data)

        self.assertEqual(data['card_title'], 'People/groups with most works')
        self.assertEqual(data['score_attr'], 'num_works')
        self.assertEqual(len(data['object_list']), 10)
示例#18
0
    def test_num(self):
        "It should return `num` items."
        d = make_date('2017-02-15')

        for i in range(2, 6):
            c = IndividualCreatorFactory()
            pub = PublicationFactory()
            PublicationRoleFactory(publication=pub, creator=c, role_name='')
            # It'll cut off any with only 1 reading, so:
            ReadingFactory.create_batch(i,
                                        publication=pub,
                                        start_date=d,
                                        end_date=d)

        data = most_read_creators_card(num=3)

        self.assertIn('object_list', data)
        self.assertEqual(len(data['object_list']), 3)
示例#19
0
    def test_returns_correct_data(self):
        d = make_date('2017-02-15')

        for i in range(2, 13):
            c = IndividualCreatorFactory()
            pub = PublicationFactory()
            PublicationRoleFactory(publication=pub, creator=c, role_name='')
            # It'll cut off any with only 1 reading, so:
            ReadingFactory.create_batch(i,
                                        publication=pub,
                                        start_date=d,
                                        end_date=d)

        data = most_read_creators_card()

        self.assertIn('card_title', data)
        self.assertIn('score_attr', data)
        self.assertIn('object_list', data)

        self.assertEqual(data['card_title'], 'Most read authors')
        self.assertEqual(data['score_attr'], 'num_readings')
        self.assertEqual(len(data['object_list']), 10)
示例#20
0
 def setUp(self):
     super().setUp()
     IndividualCreatorFactory(pk=123)
示例#21
0
 def test_creator_detail_view(self):
     "Should use the correct view."
     IndividualCreatorFactory(pk=123)
     self.assertEqual(resolve('/creators/9g5o8/').func.__name__,
                      views.CreatorDetailView.__name__)
示例#22
0
 def test_creator_detail_url(self):
     IndividualCreatorFactory(name='Bob Ferris')
     self.assertEqual(reverse('spectator:creators:creator_detail', kwargs={'slug': 'bob-ferris'}),
                     '/creators/bob-ferris/')