def add_or_update_article(self, **adata): "creates article+article-version stubs for testing" replacements = [ ('pub-date', 'published'), ('update', 'versionDate'), ] renkeys(adata, replacements) struct = { 'id': utils.doi2msid(adata['doi']) if 'doi' in adata else adata['manuscript_id'], 'volume': 1, 'type': 'research-article', 'title': '[default]', 'version': 1, 'status': models.VOR, 'published': '2012-01-01T00:00:00Z' } struct.update(adata) delall(struct, ['journal']) # can't be serialized, not utilised anyway with self.settings(VALIDATE_FAILS_FORCE=False): # bad ajson won't fail ingest av = ajson_ingestor.ingest_publish({'article': struct}, force=True) av.datetime_published = utils.todt(struct['published']) av.save() return av
def setUp(self): ingest_these = [ "elife-01968-v1.xml.json", # => 01749 "elife-16695-v1.xml.json", # => [] #"elife-16695-v2.xml.json", "elife-20125-v1.xml.json", # poa #"elife-16695-v3.xml.json" ] ajson_dir = join(self.fixture_dir, 'ajson') for ingestable in ingest_these: path = join(ajson_dir, ingestable) data = json.load(open(path, 'r')) # remove these values here so they don't interfere in creation utils.delall( data, ['-related-articles-internal', '-related-articles-external']) ajson_ingestor.ingest_publish(data) self.msid1 = 1968 self.msid2 = 16695 self.msid3 = 20125 self.av = models.ArticleVersion.objects.get( article__manuscript_id=self.msid1, version=1) self.a = models.Article.objects.get( manuscript_id=self.msid2) # note: no version information
def load_ajson(self, path, strip_relations=True): "loads an article-json fixture. conveniently strips relations by default" data = json.load(open(path, 'r')) if strip_relations: # remove these values here so they don't interfere in creation utils.delall( data['article'], ['-related-articles-internal', '-related-articles-external']) return data
def test_delall(self): x = {'a': 1, 'b': 2, 'c': 3} expected_list = [ (['a', 'b', 'c'], {}), (['a', 'b'], {'c': 3}), (['a'], {'b': 2, 'c': 3}), ([], x), ] for keys, expected in expected_list: y = copy.deepcopy(x) utils.delall(y, keys) self.assertEqual(y, expected)
def setUp(self): ingest_these = [ #"elife-01968-v1.xml.json", "elife-20125-v1.xml.json", # poa "elife-20125-v2.xml.json", # poa "elife-20125-v3.xml.json", # vor, related to 21162 #"elife-21162-v1.xml.json", # vor, related to 20125 #"elife-16695-v1.xml.json", #"elife-16695-v2.xml.json", #"elife-16695-v3.xml.json", # vor "elife-20105-v1.xml.json", # poa "elife-20105-v2.xml.json", # poa "elife-20105-v3.xml.json" # poa, UNPUBLISHED ] ajson_dir = join(self.fixture_dir, 'ajson') for ingestable in ingest_these: data = self.load_ajson(join(ajson_dir, ingestable)) # remove these values here so they don't interfere in creation utils.delall( data, ['-related-articles-internal', '-related-articles-external']) ajson_ingestor.ingest_publish(data) self.msid1 = 20125 self.msid2 = 20105 # 2 article, 6 versions, 5 published, 1 unpublished self.unpublish(self.msid2, version=3) # an unauthenticated client self.c = Client() # an authenticated client self.ac = Client(**{ mware.CGROUPS: 'admin', })
def load_ajson2(self, path_or_data): "loads an article-json fixture. conveniently strips relations and other troublesome things" if isinstance(path_or_data, str): # assume string is a path to a file path = path_or_data data = json.load(open(path, 'r')) else: # assume data is article-json data = path_or_data # remove the 'journal' and 'snippet' sections if present if 'article' in data: data = data['article'] # remove these values here so they don't interfere in creation utils.delall(data, [ '-related-articles-internal', '-related-articles-external', '-history' ]) # remove these values here so they don't interfere with comparison utils.delall(data, ['-meta', 'statusDate', 'versionDate']) return data
def test_delall_bad_idx(self): x = {'a': 1, 'b': 2, 'c': 3} y = copy.deepcopy(x) utils.delall(x, ['foo', 'bar', 'baz']) self.assertEqual(x, y)