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)
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_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)
def most_seen_directors_card(num=10): """ Custom wrapper around spectator_events' most_seen_creators_by_works_card(). This is purely so that we can group the Coen Brothers together into a single list item. """ num = num + 1 data = most_seen_creators_by_works_card( num=num, work_kind='movie', role_name='Director') prev_creator = None coens = ['Joel Coen', 'Ethan Coen'] coen_position = None # Original list, with the Coens occupying two adjacent positions: creators = data['object_list'] for n, creator in enumerate(creators): if prev_creator: if prev_creator.name in coens and creator.name in coens: # Both this item and the previous are Coen brothers. # This is the position they should both be at: coen_position = (n - 1) break prev_creator = creator if coen_position is not None: # The Coen brothers were in the list. # So, get both of the Creator objects: coen1 = creators[coen_position] coen2 = creators[coen_position + 1] # Put them both in a list at the first position a Coen occupied: creators[coen_position] = [ coen1, coen2 ] # And delete the second position: del( creators[coen_position + 1] ) # Now we need to improve the positions of all subsequent people # because we just removed a position: for m in range(coen_position + 1, len(creators)): creators[m].chart_position = creators[m].chart_position - 1 # While we're here, a better title: data['card_title'] = 'Directors by number of movies' data['object_list'] = creators return data
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_card(work_kind='movie') 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_works, 3) self.assertEqual(data['object_list'][1], c2) self.assertEqual(data['object_list'][1].num_works, 2)
def test_title_work_with_work_kind_and_role_name(self): data = most_seen_creators_by_works_card(work_kind='movie', role_name='Director') self.assertEqual(data['card_title'], 'Directors with most movies')
def test_title_work_with_role_name(self): data = most_seen_creators_by_works_card(role_name='Director') self.assertEqual(data['card_title'], 'Directors with most works')
def test_title_work_with_work_kind(self): data = most_seen_creators_by_works_card(work_kind='movie') self.assertEqual(data['card_title'], 'People/groups with most movies')