def test_data(self):
        "Test data returned."
        ReadingFactory.create_batch(3,
                                publication=PublicationFactory(kind='book'),
                                end_date=make_date('1998-01-01'))
        ReadingFactory(publication=PublicationFactory(kind='book'),
                                end_date=make_date('2000-01-01'))

        result = ReadingGenerator(kind='book').get_per_year()

        self.assertIn('data', result)
        self.assertEqual(result['data'], [
            {'label': '1998', 'value': 3, 'url': '/terry/reading/1998/books/'},
            {'label': '1999', 'value': 0},
            {'label': '2000', 'value': 1, 'url': '/terry/reading/2000/books/'},
        ])
Example #2
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)
Example #3
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)
Example #4
0
    def setUp(self):
        # Books only in 2015:
        ReadingFactory.create_batch(
            2,
            publication=PublicationFactory(kind='book'),
            end_date=make_date('2015-01-01'))

        # Nothing in 2016.

        # Books and periodicals in 2017:
        ReadingFactory.create_batch(
            3,
            publication=PublicationFactory(kind='book'),
            end_date=make_date('2017-09-01'))
        ReadingFactory.create_batch(
            2,
            publication=PublicationFactory(kind='periodical'),
            end_date=make_date('2017-09-01'))

        # Periodicals only in 2018:
        ReadingFactory.create_batch(
            2,
            publication=PublicationFactory(kind='periodical'),
            end_date=make_date('2018-01-01'))