Exemplo n.º 1
0
    def test_latest_article_versions_only_published(self):
        "ensure only the latest versions of the articles are returned when unpublished versions exist"
        self.assertEqual(self.total_version_count, models.ArticleVersion.objects.count())

        unpublish_these = [
            (3401, 3),
            (6250, 3),
            (8025, 2),
            (9571, 1)
        ]
        for msid, version in unpublish_these:
            self.unpublish(msid, version)

        latest = logic.latest_article_versions(only_published=False) # THIS IS THE IMPORTANT BIT

        self.assertEqual(len(latest), self.total_art_count)
        self.assertEqual(len(latest), models.Article.objects.count())

        latest_idx = {obj.article.manuscript_id: obj for obj in latest}
        expected_latest = [
            (353, 1),
            (385, 1),
            (1328, 1),
            (2619, 1),
            (3401, 3),
            (3665, 1),
            (6250, 3),
            (7301, 1),
            (8025, 2),
            (9571, 1)
        ]
        for msid, v in expected_latest:
            # throws a DoesNotExist if expected not in latest resultset
            self.assertEqual(latest_idx[msid].version, v)
Exemplo n.º 2
0
    def test_latest_article_versions_with_unpublished(self):
        "ensure only the latest versions of the articles are returned when unpublished versions exist"
        self.assertEqual(self.total_version_count, models.ArticleVersion.objects.count())

        unpublish_these = [
            (3401, 3),
            (6250, 3),
            (8025, 2),
            (9571, 1)
        ]
        for msid, version in unpublish_these:
            self.unpublish(msid, version)

        latest = logic.latest_article_versions(only_published=True) # THIS IS THE IMPORTANT BIT
        latest_idx = {obj.article.manuscript_id: obj for obj in latest}

        self.assertEqual(len(latest), self.total_art_count - 1) # we remove 9571

        expected_latest = [
            (353, 1),
            (385, 1),
            (1328, 1),
            (2619, 1),
            (3401, 2), # from 3 to 2
            (3665, 1),
            (6250, 2), # from 3 to 2
            (7301, 1),
            (8025, 1), # from 2 to 1
            #(9571, 1) # from 1 to None
        ]
        for msid, expected_version in expected_latest:
            try:
                av = latest_idx[msid]
                self.assertEqual(av.version, expected_version)
            except:
                print 'failed on', msid, 'version', expected_version
                raise
Exemplo n.º 3
0
    def test_latest_article_versions(self):
        "ensure only the latest versions of the articles are returned"
        self.assertEqual(self.total_version_count, models.ArticleVersion.objects.count())

        latest = logic.latest_article_versions()
        self.assertEqual(len(latest), self.total_art_count)
        self.assertEqual(len(latest), models.Article.objects.count())

        latest_idx = {obj.article.manuscript_id: obj for obj in latest}
        expected_latest = [
            (353, 1),
            (385, 1),
            (1328, 1),
            (2619, 1),
            (3401, 3),
            (3665, 1),
            (6250, 3),
            (7301, 1),
            (8025, 2),
            (9571, 1)
        ]
        for msid, v in expected_latest:
            # throws a DoesNotExist if expected not in latest resultset
            self.assertEqual(latest_idx[msid].version, v)
Exemplo n.º 4
0
    def test_only_most_recent_article_versions_returned(self):
        an_hour_ago = utils.utcnow() - timedelta(hours=1)
        many_hours_ago = an_hour_ago - timedelta(hours=999)
        fmt = utils.ymdhms
        article_data_list = [
            {'title': 'foo',
             'version': 1,
             'doi': "10.7554/eLife.00001",
             'pub-date': fmt(an_hour_ago),
             },


            {'title': 'bar',
             'version': 1,
             'doi': "10.7554/eLife.00002",
             'pub-date': fmt(many_hours_ago),
             },
            {'title': 'bar',
             'version': 2,
             'doi': "10.7554/eLife.00002",
             'pub-date': fmt(many_hours_ago - timedelta(hours=1)),
             'update': fmt(many_hours_ago - timedelta(hours=1)),
             },
            {'title': 'bar',
             'version': 3,
             'doi': "10.7554/eLife.00002",
             'pub-date': fmt(many_hours_ago - timedelta(hours=2)),
             'update': fmt(many_hours_ago - timedelta(hours=2)),
             },


            {'title': 'baz',
             'version': 1,
             'doi': "10.7554/eLife.00003",
             'pub-date': fmt(an_hour_ago + timedelta(minutes=5)),
             },
            {'title': 'baz',
             'version': 2,
             'doi': "10.7554/eLife.00003",
             'pub-date': fmt(an_hour_ago + timedelta(minutes=10)),
             'update': fmt(an_hour_ago + timedelta(minutes=10)),
             }

        ]
        [logic.add_or_update_article(**article_data) for article_data in article_data_list]

        self.assertEqual(models.Article.objects.count(), 3)
        self.assertEqual(models.ArticleVersion.objects.count(), 6)

        avlist = logic.latest_article_versions()
        self.assertEqual(len(avlist), 3)

        expected_version_order = [
            ('10.7554/eLife.00003', 2), # published less than an hour ago
            ('10.7554/eLife.00001', 1), # published an hour ago
            ('10.7554/eLife.00002', 3), # published many hours ago
        ]

        for av, expected in zip(avlist, expected_version_order):
            self.assertEqual(av.article.doi, expected[0])
            self.assertEqual(av.version, expected[1])