def test_article_patch(self): # I think this might be the better patch structure, # forcing one patch per version so order isn't ambiguous ... ''' patch = { 'doi': "10.7554/eLife.00353", 'versions': { 1: {'title': 'replaced title'}, } } ''' # but the only thing generating patches is the `updated-date-scraper` tool # and it's output looks like this: patch = { 'doi': "10.7554/eLife.00353", 'versions': [ {'title': 'replaced title', 'version': 1}, ] } ingestor.import_article_from_json_path(self.journal, self.json_fixture) av = models.ArticleVersion.objects.all()[0] self.assertEqual(av.title, "A meh life") ingestor.patch(patch) av = models.ArticleVersion.objects.all()[0] self.assertEqual(av.title, patch['versions'][0]['title'])
def test_article_created(self): "an article can be imported from JSON" self.assertEqual(0, models.Article.objects.count()) self.assertEqual(0, models.ArticleVersion.objects.count()) ingestor.import_article_from_json_path(self.journal, self.json_fixture) self.assertEqual(1, models.Article.objects.count()) self.assertEqual(1, models.Article.objects.count())
def test_ppp_update(self): "ppp eif can be used to update existing article without exceptions" fixture = join(self.fixture_dir, 'elife00353.xml.json') eif_update_fixture = join(self.fixture_dir, 'ppp', '00353.1', 'elife-00353-v1.json') art, ver = ingestor.import_article_from_json_path(self.journal, fixture) self.assertEqual(ver.title, "A meh life") art, ver = ingestor.import_article_from_json_path(self.journal, eif_update_fixture, update=True) self.assertEqual(ver.title, "A good life")
def test_article_not_updated(self): "an exception is raised when attempting to import article data for an existing article when update=False" self.assertEqual(0, models.Article.objects.count()) ingestor.import_article_from_json_path(self.journal, self.json_fixture) self.assertEqual(1, models.Article.objects.count()) # attempt the update self.assertRaises(AssertionError, ingestor.import_article_from_json_path, self.journal, self.json_fixture, update=False)
def setUp(self): self.journal = logic.journal() import_all = [ '00353.1', # discussion, VOR '00385.1', # commentary, VOR '01328.1', # correction, VOR '02619.1', # editorial, VOR '03401.1', # research, POA '03401.2', # POA '03401.3', # VOR '03665.1', # research, VOR '06250.1', # research, POA '06250.2', # POA '06250.3', # VOR '07301.1', # research, VOR '08025.1', # research, POA '08025.2', # VOR '09571.1', # research, POA ] for subdir in import_all: fname = subdir.replace('.', '-v') fname = "elife-%s.json" % fname path = join(self.fixture_dir, 'ppp', subdir, fname) eif_ingestor.import_article_from_json_path(self.journal, path) self.vor_version_count = 9 self.poa_version_count = 6 self.total_version_count = self.vor_version_count + self.poa_version_count self.poa_art_count = 1 self.vor_art_count = 9 self.total_art_count = self.poa_art_count + self.vor_art_count self.research_art_count = 6
def test_article_version_data(self): art, ver = ingestor.import_article_from_json_path(self.journal, self.json_fixture) expected_data = { 'article': art, 'datetime_published': utils.todt('2012-12-10'), 'status': 'poa', 'version': 1, } avobj = models.ArticleVersion.objects.get(article=art, version=1) for attr, expected in expected_data.items(): self.assertEqual(getattr(avobj, attr), expected)
def test_article_updated(self): "an article is successfully updated when update=True" self.assertEqual(0, models.Article.objects.count()) art, ver = ingestor.import_article_from_json_path(self.journal, self.json_fixture) for attr, expected in [['title', "A meh life"], ['status', "poa"], ['version', 1], ["datetime_published", utils.todt("2012-12-10")]]: self.assertEqual(getattr(ver, attr), expected) self.assertEqual(1, models.Article.objects.count()) # attempt the update art, ver = ingestor.import_article_from_json_path(self.journal, self.update_fixture, update=True) for attr, expected in [['title', "A good life"], ['status', "vor"], ["datetime_published", utils.todt("2012-12-13")]]: self.assertEqual(getattr(ver, attr), expected) self.assertEqual(1, models.Article.objects.count())
def test_article_data(self): "the Article created from the json import has the correct data" expected_data = { #'title': "A good life", 'doi': "10.7554/eLife.00353", 'journal': self.journal, 'type': 'discussion' } dirty_article, ver = ingestor.import_article_from_json_path(self.journal, self.json_fixture) clean_article = models.Article.objects.get(pk=dirty_article.pk) for attr, expected_value in expected_data.items(): self.assertEqual(getattr(clean_article, attr), expected_value)
def test_article_import_update_of_many_versions(self): "three versions of the same article can be ingested with expected results" path = join(self.fixture_dir, "ppp-09066") v1 = join(path, "elife-09066-v1.json") v2 = join(path, "elife-09066-v2.json") v3 = join(path, "elife-09066-v3.json") ingestor.import_article_from_json_path(self.journal, v1) ingestor.import_article_from_json_path(self.journal, v2) ingestor.import_article_from_json_path(self.journal, v3) self.assertEqual(models.Article.objects.count(), 1) self.assertEqual(models.ArticleVersion.objects.count(), 3) v1obj = models.ArticleVersion.objects.get(version=1) # POA v2obj = models.ArticleVersion.objects.get(version=2) # POA v3obj = models.ArticleVersion.objects.get(version=3) # VOR self.assertEqual(v1obj.datetime_published, utils.todt("2015-12-19T00:00:00Z")) self.assertEqual(v2obj.datetime_published, utils.todt("2015-12-23T00:00:00Z")) self.assertEqual(v3obj.datetime_published, utils.todt("2016-02-04T00:00:00Z")) # all three objects should share the same article and the article's date_published should be the # date of the earliest Article Version self.assertEqual(v1obj.datetime_published, v1obj.article.datetime_published) self.assertEqual(v1obj.datetime_published, v2obj.article.datetime_published) self.assertEqual(v1obj.datetime_published, v3obj.article.datetime_published)
def test_ppp_basic_import(self): "ppp eif can be imported without exceptions" for fixture in self.fixture_list: ingestor.import_article_from_json_path(self.journal, fixture)