Ejemplo n.º 1
0
    def test_article_create_update_view(self):
        "an article can be created and updated via API using EIF"
        self.assertEqual(0, models.Article.objects.count())
        self.assertEqual(0, models.ArticleVersion.objects.count())
        json_data = open(self.json_fixture, 'r').read()
        data = json.loads(json_data)

        # create the article. 1xEIF == 1xArticle + 1xArticleVersion
        resp = self.c.post(reverse('api-create-update-article'), json_data, content_type="application/json")
        self.assertEqual(200, resp.status_code)
        self.assertEqual(1, models.Article.objects.count())
        self.assertEqual(1, models.ArticleVersion.objects.count())

        # change the doi, ensure it's changed in the db
        updated_data = utils.updatedict(data, title='pants.party')
        logic.add_or_update_article(**updated_data)
        models.ArticleVersion.objects.get(title=updated_data['title'])

        # update the same article (with the original doi)
        resp = self.c.post(reverse('api-create-update-article'), json_data, content_type="application/json")
        self.assertEqual(200, resp.status_code)

        # ensure nothing new has been created
        self.assertEqual(1, models.Article.objects.count())
        self.assertEqual(1, models.ArticleVersion.objects.count())

        # ensure the article has been updated
        models.ArticleVersion.objects.get(title=data['title'])
Ejemplo n.º 2
0
 def test_article_info_api_case_insensitive(self):
     "article data returned by the api is the same as what is serialize"
     kwargs = self.article_data
     kwargs['doi'] = kwargs['doi'].upper()
     article, version = logic.add_or_update_article(**kwargs)
     resp = self.c.get(reverse("api-article", kwargs={'doi': article.doi}))
     self.assertEqual(resp.data, views.ArticleVersionSerializer(version).data)
Ejemplo n.º 3
0
 def test_article_info_api(self):
     "article data returned by the api is the same as what is serialize"
     article, version = logic.add_or_update_article(**self.article_data)
     resp = self.c.get(reverse("api-article", kwargs={'doi': article.doi}))
     expected = views.ArticleVersionSerializer(version).data
     actual = resp.data
     self.assertEqual(actual, expected)
Ejemplo n.º 4
0
    def test_fetches_latest_always(self):
        "when version is not specified, `logic.article` returns the latest"
        self.assertEqual(0, models.Article.objects.count())
        doi = "10.7554/eLife.01234"
        now = datetime.now()
        one_ago = now - timedelta(days=1)
        two_ago = now - timedelta(days=2)
        three_ago = now - timedelta(days=3)
        article_data_list = [
            {'title': 'foo',
             'version': 1,
             'doi': doi,
             'pub-date': three_ago,
             'journal': self.journal},

            {'title': 'bar',
             'version': 2,
             'doi': doi,
             'update': two_ago,
             'journal': self.journal},

            {'title': 'baz',
             'version': 3,
             'doi': doi,
             'update': one_ago,
             'journal': self.journal},
        ]
        [logic.add_or_update_article(**article_data) for article_data in article_data_list]
        self.assertEqual(1, models.Article.objects.count())
        self.assertEqual(3, models.ArticleVersion.objects.count())

        art, ver = logic.article(doi)
        self.assertEqual(ver.version, 3)
        self.assertEqual(ver.title, 'baz')
Ejemplo n.º 5
0
    def test_article_info_version(self):
        "the correct article version is returned when specified via the api"
        doi = "10.7554/eLife.01234"
        article_data_list = [
            {'title': 'foo',
             'version': 1,
             'doi': doi,
             'journal': self.journal},

            {'title': 'bar',
             'version': 1,
             'doi': doi,
             'journal': self.journal},

            {'title': 'baz',
             'version': 2,
             'doi': doi,
             'journal': self.journal},
        ]
        [logic.add_or_update_article(**article_data) for article_data in article_data_list]
        self.assertEqual(1, models.Article.objects.count())
        self.assertEqual(2, models.ArticleVersion.objects.count())

        expected_version = 1
        api_args = {'doi': doi, 'version': expected_version}
        resp = self.c.get(reverse("api-article-version", kwargs=api_args))

        print resp.data

        self.assertEqual(resp.data['version'], expected_version)
        self.assertEqual(resp.data['title'], 'bar')
Ejemplo n.º 6
0
    def setUp(self):
        self.c = Client()
        self.journal = logic.journal()
        an_hour_ago = utils.utcnow() - timedelta(hours=1)
        many_hours_ago = an_hour_ago - timedelta(hours=999)
        fmt = utils.ymdhms
        self.article_data_list = [
            {'title': 'foo',
             'status': 'vor',
             'version': 1,
             'doi': "10.7554/eLife.00001",
             'journal': self.journal,
             'pub-date': fmt(an_hour_ago),
             },

            {'title': 'bar',
             'status': 'vor',
             'version': 1,
             'doi': "10.7554/eLife.00002",
             'journal': self.journal,
             'pub-date': fmt(many_hours_ago),
             },

            {'title': 'baz',
             'version': 1,
             'status': 'poa', # **
             'doi': "10.7554/eLife.00003",
             'journal': self.journal,
             'pub-date': fmt(an_hour_ago),
             }
        ]
        [logic.add_or_update_article(**article_data) for article_data in self.article_data_list]
Ejemplo n.º 7
0
 def test_article_info_incorrect_version(self):
     "a 404 is returned when the correct article with an incorrect version is specified via the api"
     doi = "10.7554/eLife.01234"
     version = 1
     article_data_list = [
         {'title': 'foo',
          'version': version,
          'doi': doi,
          'journal': self.journal},
     ]
     [logic.add_or_update_article(**article_data) for article_data in article_data_list]
     url = reverse("api-article-version", kwargs={'doi': doi, 'version': version + 1})
     resp = self.c.get(url)
     self.assertEqual(404, resp.status_code)
Ejemplo n.º 8
0
    def test_ejp_ingest_over_existing_data_with_defaults(self):
        "importing ejp articles over existing articles causes an error"
        self.assertEqual(models.Article.objects.count(), 0)
        article_data_list = [
            {'manuscript_id': 123,
             'journal': self.journal},

            {'manuscript_id': 11835,
             'journal': self.journal},

            {'manuscript_id': 321,
             'journal': self.journal},
        ]
        [logic.add_or_update_article(**article_data) for article_data in article_data_list]
        self.assertEqual(models.Article.objects.count(), 3)
        self.assertRaises(AssertionError, ejp_ingestor.import_article_list_from_json_path, self.journal, self.tiny_json_path)
        self.assertEqual(models.Article.objects.count(), 3) # import is atomic, all or nothing.
Ejemplo n.º 9
0
    def test_ejp_ingest_over_existing_data(self):
        "importing ejp articles and updating existing articles is possible but only if we explicitly say so"
        self.assertEqual(models.Article.objects.count(), 0)
        article_data_list = [
            {'manuscript_id': 123,
             'journal': self.journal},

            {'manuscript_id': 11835,
             'journal': self.journal},

            {'manuscript_id': 321,
             'journal': self.journal},
        ]
        [logic.add_or_update_article(**article_data) for article_data in article_data_list]
        self.assertEqual(models.Article.objects.count(), 3)
        ejp_ingestor.import_article_list_from_json_path(self.journal, self.tiny_json_path, update=True)
        self.assertEqual(models.Article.objects.count(), 8)
        art = models.Article.objects.get(manuscript_id=11835)
        self.assertTrue(art.initial_decision)
Ejemplo n.º 10
0
    def test_article_info_version_grouping(self):
        "an article with multiple versions is returned"
        doi = "10.7554/eLife.01234"
        now = datetime.now()
        one_ago = now - timedelta(days=1)
        two_ago = now - timedelta(days=2)
        three_ago = now - timedelta(days=3)
        article_data_list = [
            {'title': 'foo',
             'version': 1,
             'doi': doi,
             'pub-date': three_ago,
             'journal': self.journal},

            {'title': 'bar',
             'version': 2,
             'doi': doi,
             'update': two_ago,
             'journal': self.journal},

            {'title': 'baz',
             'version': 3,
             'doi': doi,
             'update': one_ago,
             'journal': self.journal},
        ]
        [logic.add_or_update_article(**article_data) for article_data in article_data_list]

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

        resp = self.c.get(reverse("api-article-versions", kwargs={'doi': doi}))
        data = resp.data
        self.assertEqual([1, 2, 3], data.keys())
        for expected_item in article_data_list:
            resp_item = data[expected_item['version']]
            self.assertEqual(resp_item['title'], expected_item['title'])
            self.assertEqual(resp_item['version'], expected_item['version'])
            self.assertEqual(resp_item['doi'], expected_item['doi'])
Ejemplo n.º 11
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])