def test_article_publish_v2_forced(self): "an unpublished v2 article can be successfully published again, if forced" # ingest and publish the v1 _, _, av = ajson_ingestor.ingest(self.ajson) ajson_ingestor.publish(self.msid, self.version) av = self.freshen(av) self.assertTrue(av.published()) # modify and ingest+publish a v2 self.ajson['article']['version'] = 2 _, _, av2 = ajson_ingestor.ingest_publish(self.ajson) av2 = self.freshen(av2) self.assertTrue(av2.published()) # the v2 should have been published normally. self.assertEqual(utils.ymd(datetime.now()), utils.ymd(av2.datetime_published)) # give the article-json a 'versionDate' - this won't ordinarily happen until further down the line # but lets embed this logic while it's still fresh in everybody's heads. # modify the versionDate of the v2 and ingest+publish again yesterday = datetime.now() - timedelta(days=1) self.ajson['article']['versionDate'] = yesterday _, _, av2v2 = ajson_ingestor.ingest_publish(self.ajson, force=True) av2v2 = self.freshen(av2v2) self.assertEqual(utils.ymd(yesterday), utils.ymd(av2v2.datetime_published))
def test_article_publish_v2_forced2(self): "a PUBLISHED v2 article can be successfully published (again), if forced" av = ajson_ingestor.ingest(self.ajson) ajson_ingestor.publish(self.msid, self.version) av = self.freshen(av) self.assertTrue(av.published()) # modify and ingest+publish a v2 self.ajson['article']['version'] = 2 # there is a versionDate here, but because we're not forcing it, it doesn't get looked for # lax is the distributor of non-v1 pub dates. this may find their way into xml later, but # they will always come from lax. av2 = ajson_ingestor.ingest_publish(self.ajson) av2 = self.freshen(av2) self.assertTrue(av2.published()) self.assertEqual(utils.ymd(datetime.now()), utils.ymd(av2.datetime_published)) # don't set a versionDate, just force a publish # we expect the v2.datetime_publish to remain unchanged del self.ajson['article'][ 'versionDate'] # remember, this was copied from a v1 that had a versionDate! av2v2 = ajson_ingestor.ingest_publish(self.ajson, force=True) av2v2 = self.freshen(av2v2) self.assertEqual(av2.datetime_published, av2v2.datetime_published)
def test_article_publish_v1(self): "an unpublished v1 article can be successfully published" av = ajson_ingestor.ingest(self.ajson) self.assertEqual(models.Journal.objects.count(), 1) self.assertEqual(models.Article.objects.count(), 1) self.assertEqual(models.ArticleVersion.objects.count(), 1) self.assertFalse(av.published()) # publish av = ajson_ingestor.publish(self.msid, self.version) # aaand just make sure we still have the expected number of objects self.assertEqual(models.Journal.objects.count(), 1) self.assertEqual(models.Article.objects.count(), 1) self.assertEqual(models.ArticleVersion.objects.count(), 1) self.assertTrue(av.published()) self.assertTrue(isinstance(av.datetime_published, datetime)) # the pubdate of an unpublished v1 article is the same as that found in the # given json. av = self.freshen(av) expected_pubdate = utils.ymd( utils.todt(self.ajson['article']['published'])) self.assertEqual(expected_pubdate, utils.ymd(av.datetime_published))
def test_article_publish_v2_forced(self): "an unpublished v2 article can be successfully published again, if forced" # ingest and publish the v1 av = ajson_ingestor.ingest(self.ajson) ajson_ingestor.publish(self.msid, self.version) av = self.freshen(av) self.assertTrue(av.published()) # modify and ingest+publish a v2 self.ajson['article']['version'] = 2 av2 = ajson_ingestor.ingest_publish(self.ajson) av2 = self.freshen(av2) self.assertTrue(av2.published()) # the v2 should have been published normally. self.assertEqual(utils.ymd(datetime.now()), utils.ymd(av2.datetime_published)) # give the article-json a 'versionDate' - this won't ordinarily happen until further down the line # but lets embed this logic while it's still fresh in everybody's heads. # modify the versionDate of the v2 and ingest+publish again yesterday = datetime.now() - timedelta(days=1) self.ajson['article']['versionDate'] = yesterday av2v2 = ajson_ingestor.ingest_publish(self.ajson, force=True) av2v2 = self.freshen(av2v2) self.assertEqual(utils.ymd(yesterday), utils.ymd(av2v2.datetime_published))
def row(art): accepted = art.date_accepted poa = getattr(art.earliest_poa(), 'datetime_published', None) vor = getattr(art.earliest_vor(), 'datetime_published', None) days_to_poa = None if poa and accepted: days_to_poa = (poa.date() - accepted).days days_to_vor = None if vor and accepted: days_to_vor = (vor.date() - accepted).days days_to_vor_from_poa = None if poa and vor: days_to_vor_from_poa = (vor - poa).days return [ art.doi, art.type, art.ejp_type, art.date_accepted, utils.ymd(poa), utils.ymd(vor), days_to_poa, days_to_vor, days_to_vor_from_poa, ]
def test_paw_ahead_report_data(self): res = logic.paw_ahead_report_raw_data(limit=None) self.assertEqual(res.count(), self.poa_art_count) cases = [("09571", 1, "2015-11-09")] for msid, expected_version, expected_pubdate in cases: o = res.get(article__doi='10.7554/eLife.' + msid) self.assertEqual(o.status, 'poa') self.assertEqual(o.version, expected_version) self.assertEqual(utils.ymd(o.datetime_published), expected_pubdate)
def test_article_publish_succeeds_for_published_article_if_forced(self): "publication of an already published article can occur only if forced" _, _, av = ajson_ingestor.ingest(self.ajson) av = ajson_ingestor.publish(self.msid, self.version) av = self.freshen(av) expected_pubdate = utils.ymd(utils.todt(self.ajson['article']['published'])) self.assertEqual(expected_pubdate, utils.ymd(av.datetime_published)) # publish again, no changes to pubdate expected av = ajson_ingestor.publish(self.msid, self.version, force=True) av = self.freshen(av) self.assertEqual(expected_pubdate, utils.ymd(av.datetime_published)) # ingest new pubdate, force publication new_pubdate = utils.todt('2016-01-01') self.ajson['article']['published'] = new_pubdate ajson_ingestor.ingest_publish(self.ajson, force=True) av = self.freshen(av) self.assertEqual(utils.ymd(new_pubdate), utils.ymd(av.datetime_published))
def test_article_publish_v2(self): "an unpublished v2 article can be successfully published" _, _, av = ajson_ingestor.ingest(self.ajson) self.assertEqual(models.Journal.objects.count(), 1) self.assertEqual(models.Article.objects.count(), 1) self.assertEqual(models.ArticleVersion.objects.count(), 1) self.assertFalse(av.published()) ajson_ingestor.publish(self.msid, self.version) av = self.freshen(av) self.assertTrue(av.published()) # modify to a v2 and publish self.ajson['article']['version'] = 2 _, _, av2 = ajson_ingestor.ingest_publish(self.ajson) av2 = self.freshen(av2) self.assertEqual(models.ArticleVersion.objects.count(), 2) self.assertTrue(av2.published()) self.assertEqual(utils.ymd(datetime.now()), utils.ymd(av2.datetime_published))
def test_article_publish_succeeds_for_published_article_if_forced(self): "publication of an already published article can occur only if forced" av = ajson_ingestor.ingest(self.ajson) av = ajson_ingestor.publish(self.msid, self.version) av = self.freshen(av) expected_pubdate = utils.ymd( utils.todt(self.ajson['article']['published'])) self.assertEqual(expected_pubdate, utils.ymd(av.datetime_published)) # publish again, no changes to pubdate expected av = ajson_ingestor.publish(self.msid, self.version, force=True) av = self.freshen(av) self.assertEqual(expected_pubdate, utils.ymd(av.datetime_published)) # ingest new pubdate, force publication new_pubdate = utils.todt('2016-01-01') self.ajson['article']['published'] = new_pubdate ajson_ingestor.ingest_publish(self.ajson, force=True) av = self.freshen(av) self.assertEqual(utils.ymd(new_pubdate), utils.ymd(av.datetime_published))
def test_article_publish_v2(self): "an unpublished v2 article can be successfully published" av = ajson_ingestor.ingest(self.ajson) self.assertEqual(models.Journal.objects.count(), 1) self.assertEqual(models.Article.objects.count(), 1) self.assertEqual(models.ArticleVersion.objects.count(), 1) self.assertFalse(av.published()) ajson_ingestor.publish(self.msid, self.version) av = self.freshen(av) self.assertTrue(av.published()) # modify to a v2 and publish self.ajson['article']['version'] = 2 av2 = ajson_ingestor.ingest_publish(self.ajson) av2 = self.freshen(av2) self.assertEqual(models.ArticleVersion.objects.count(), 2) self.assertTrue(av2.published()) self.assertEqual(utils.ymd(datetime.now()), utils.ymd(av2.datetime_published))
def test_paw_recent_report_data(self): res = logic.paw_recent_report_raw_data(limit=None) self.assertEqual(res.count(), self.vor_art_count) vor_cases = [ (353, 1, "2012-12-13"), # v1 'pub-date' dates (3401, 3, "2014-08-01"), # >v1 'update' dates (8025, 2, "2015-06-16"), ] for msid, expected_version, expected_pubdate in vor_cases: av = res.get(article__manuscript_id=msid) self.assertEqual(av.status, 'vor') self.assertEqual(av.version, expected_version) self.assertEqual(utils.ymd(av.datetime_published), expected_pubdate)
def test_article_publish_v2_forced2(self): "a PUBLISHED v2 article can be successfully published (again), if forced" _, _, av = ajson_ingestor.ingest(self.ajson) ajson_ingestor.publish(self.msid, self.version) av = self.freshen(av) self.assertTrue(av.published()) # modify and ingest+publish a v2 self.ajson['article']['version'] = 2 # there is a versionDate here, but because we're not forcing it, it doesn't get looked for # lax is the distributor of non-v1 pub dates. this may find their way into xml later, but # they will always come from lax. _, _, av2 = ajson_ingestor.ingest_publish(self.ajson) av2 = self.freshen(av2) self.assertTrue(av2.published()) self.assertEqual(utils.ymd(datetime.now()), utils.ymd(av2.datetime_published)) # don't set a versionDate, just force a publish # we expect the v2.datetime_publish to remain unchanged del self.ajson['article']['versionDate'] # remember, this was copied from a v1 that had a versionDate! _, _, av2v2 = ajson_ingestor.ingest_publish(self.ajson, force=True) av2v2 = self.freshen(av2v2) self.assertEqual(av2.datetime_published, av2v2.datetime_published)
def test_article_publish_v1(self): "an unpublished v1 article can be successfully published" _, _, av = ajson_ingestor.ingest(self.ajson) self.assertEqual(models.Journal.objects.count(), 1) self.assertEqual(models.Article.objects.count(), 1) self.assertEqual(models.ArticleVersion.objects.count(), 1) self.assertFalse(av.published()) # publish av = ajson_ingestor.publish(self.msid, self.version) # aaand just make sure we still have the expected number of objects self.assertEqual(models.Journal.objects.count(), 1) self.assertEqual(models.Article.objects.count(), 1) self.assertEqual(models.ArticleVersion.objects.count(), 1) self.assertTrue(av.published()) self.assertTrue(isinstance(av.datetime_published, datetime)) # the pubdate of an unpublished v1 article is the same as that found in the # given json. av = self.freshen(av) expected_pubdate = utils.ymd(utils.todt(self.ajson['article']['published'])) self.assertEqual(expected_pubdate, utils.ymd(av.datetime_published))
def ymd_dt(av): if av and hasattr(av, 'datetime_published'): return ymd(av.datetime_published)