def test_revalidate_from_cli_dry_run(self): "a dry run doesn't modify anything. the report should be the same as an actual run, but with no changes" args = [self.nom, '--dry-run'] errcode, stdout = self.call_command(*args) self.assertEqual(errcode, 0) report = json.loads(stdout) self.assertEqual(report['total-set'], 1) self.assertEqual(report['total-unset'], 1) self.assertEqual(report['total-reset'], 1) self.assertEqual(report['total-not-set'], 1) # SET (nothing SET) av = article_logic.article_version(self.msid1, self.version) self.assertFalse(av.article_json_v1) self.assertFalse(av.article_json_v1_snippet) # RESET (still SET) av = article_logic.article_version(self.msid2, self.version) self.assertTrue(av.article_json_v1) self.assertTrue(av.article_json_v1_snippet) # UNSET (nothing UNSET) av = article_logic.article_version(self.msid3, self.version) self.assertTrue(av.article_json_v1) self.assertTrue(av.article_json_v1_snippet) # NOTSET (nothing ... not ... set ?) av = article_logic.article_version(self.msid4, self.version) self.assertFalse(av.article_json_v1) self.assertFalse(av.article_json_v1_snippet)
def test_revalidate_all_from_cli(self): args = [self.nom] errcode, stdout = self.call_command(*args) self.assertEqual(errcode, 0) report = json.loads(stdout) self.assertEqual(report['total-set'], 1) self.assertEqual(report['total-unset'], 1) self.assertEqual(report['total-reset'], 1) self.assertEqual(report['total-not-set'], 1) # SET av = article_logic.article_version(self.msid1, self.version) self.assertTrue(av.article_json_v1) self.assertTrue(av.article_json_v1_snippet) # RESET av = article_logic.article_version(self.msid2, self.version) self.assertTrue(av.article_json_v1) self.assertTrue(av.article_json_v1_snippet) # UNSET av = article_logic.article_version(self.msid3, self.version) self.assertFalse(av.article_json_v1) self.assertFalse(av.article_json_v1_snippet) # NOTSET av = article_logic.article_version(self.msid4, self.version) self.assertFalse(av.article_json_v1) self.assertFalse(av.article_json_v1_snippet)
def test_article_version(self): "the specific article version is returned" cases = [(self.msid1, 1), (self.msid2, 1), (self.msid2, 2), (self.msid2, 3)] for msid, expected_version in cases: av = logic.article_version(msid, version=expected_version) self.assertEqual(av.article.manuscript_id, msid) self.assertEqual(av.version, expected_version)
def setUp(self): self.nom = 'revalidate' # publish four valid articles, ensure each is in different states fixture_list = [ '01968', # SET '16695', # RESET '20105', # UNSET '20125', # NOTSET ] self.msid1, self.msid2, self.msid3, self.msid4 = fixture_list self.version = '1' for msid in fixture_list: fixture_path = join(self.fixture_dir, 'ajson', 'elife-%s-v1.xml.json' % msid) ajson_ingestor.ingest_publish(json.load(open(fixture_path, 'r'))) # SET # remove the valid ajson so it gets set av = article_logic.article_version(self.msid1, self.version) av.article_json_v1 = av.article_json_v1_snippet = None av.save() # RESET # already valid, nothing to do # UNSET # ensure the fragment is now invalid av = article_logic.article_version(self.msid3, self.version) frag = logic.get(av, models.XML2JSON) frag.fragment['title'] = '' frag.save() # NOTSET # remove the valid article-json # ensure fragment is invalid and won't be set av = article_logic.article_version(self.msid4, self.version) av.article_json_v1 = av.article_json_v1_snippet = None av.save() frag = logic.get(av, models.XML2JSON) frag.fragment['title'] = '' frag.save()
def test_article_version(self): "the specific article version is returned" cases = [ (self.msid1, 1), (self.msid2, 1), (self.msid2, 2), (self.msid2, 3) ] for msid, expected_version in cases: av = logic.article_version(msid, version=expected_version) self.assertEqual(av.article.manuscript_id, msid) self.assertEqual(av.version, expected_version)
def test_logic_doesnt_mangle_unicode(self): "the api logic doesn't alter unicode values" ajson = json.load(open(self.ajson_fixture1, 'r')) ajson_ingestor.ingest_publish(ajson) expected = ajson['snippet']['authors'][1]['name']['preferred'] # /articles/{id} given = logic.most_recent_article_version( self.msid).article_json_v1['authors'][1]['name']['preferred'] self.assertEqual(expected, given) # /articles/{id}/versions/{version} given = logic.article_version( self.msid, self.version).article_json_v1['authors'][1]['name']['preferred'] self.assertEqual(expected, given)