def test_search_journal_title_no_match(self, mock_urlopen): mock_urlopen.return_value.read.return_value = \ self.fixture_text('example-08.xml') journals = romeo.search_journal_title('recycling journal') # query mock_urlopen.assert_called_once() args, kwargs = mock_urlopen.call_args self.assertEqual(kwargs, {}) self.assertEqual(len(args), 1) query_args = parse_qs(urlsplit(args[0]).query) self.assertEqual(query_args['jtitle'], ['recycling journal']) # response self.assertEqual(len(journals), 0)
def test_search_journal_title_single_example(self, mock_urlopen): mock_urlopen.return_value.read.return_value = \ self.fixture_text('example-05.xml') journals = romeo.search_journal_title('revista argentina de cardiologia') publisher = journals[0].publisher_details() # query mock_urlopen.assert_called_once() args, kwargs = mock_urlopen.call_args self.assertEqual(kwargs, {}) self.assertEqual(len(args), 1) query_args = parse_qs(urlsplit(args[0]).query) self.assertEqual(query_args['jtitle'], ['revista argentina de cardiologia']) # response self.assertEqual(len(journals), 1) self.assertEqual(journals[0].title, 'Revista Argentina de Cardiologia') self.assertEqual(journals[0].issn, '0034-7000') self.assertTrue(isinstance(publisher, romeo.Publisher)) self.assertEqual(publisher.name, u'Sociedad Argentina de Cardiolog\xeda')
def test_search_journal_title_multiple_example(self, mock_urlopen): mock_urlopen.return_value.read.return_value = \ self.fixture_text('example-04.xml') journals = romeo.search_journal_title('dna') # query mock_urlopen.assert_called_once() args, kwargs = mock_urlopen.call_args self.assertEqual(kwargs, {}) self.assertEqual(len(args), 1) query_args = parse_qs(urlsplit(args[0]).query) self.assertEqual(query_args['jtitle'], ['dna']) # response self.assertEqual(len(journals), 5) self.assertEqual(journals[0].title, 'DNA') self.assertEqual(journals[0].issn, '0198-0238') self.assertEqual(journals[1].title, 'DNA and Cell Biology') self.assertEqual(journals[1].issn, '1044-5498') self.assertEqual(journals[1].publisher_zetoc, 'Mary Ann Liebert, Inc.') self.assertEqual(journals[1].publisher_romeo, 'Mary Ann Liebert')
def test_search_journal_title_single_example(self, mock_urlopen): mock_urlopen.return_value.read.return_value = \ self.fixture_text('example-05.xml') journals = romeo.search_journal_title( 'revista argentina de cardiologia') publisher = journals[0].publisher_details() # query mock_urlopen.assert_called_once() args, kwargs = mock_urlopen.call_args self.assertEqual(kwargs, {}) self.assertEqual(len(args), 1) query_args = parse_qs(urlsplit(args[0]).query) self.assertEqual(query_args['jtitle'], ['revista argentina de cardiologia']) # response self.assertEqual(len(journals), 1) self.assertEqual(journals[0].title, 'Revista Argentina de Cardiologia') self.assertEqual(journals[0].issn, '0034-7000') self.assertTrue(isinstance(publisher, romeo.Publisher)) self.assertEqual(publisher.name, u'Sociedad Argentina de Cardiolog\xeda')
def handle(self, *args, **options): self.verbosity = int(options['verbosity']) # 1 = normal, 0 = minimal, 2 = all self.v_normal = 1 # connection to repository self.repo = ManagementRepository() pid_set = self.repo.get_objects_with_cmodel(Publication.ARTICLE_CONTENT_MODEL, type=Publication) try: articles = Paginator(pid_set, 100) except Exception as e: self.output(0, "Error paginating items: : %s " % (e.message)) #process all Articles for p in articles.page_range: try: objs = articles.page(p).object_list except Exception as e: #print error and go to next iteration of loop self.output(0,"Error getting page: %s : %s " % (p, e.message)) continue for article in objs: try: if not article.exists: self.output(0, "Skipping %s because pid does not exist" % article.pid) continue else: mods = article.descMetadata.content if mods.journal is not None: if mods.journal.title is not None: try: journals = romeo.search_journal_title(mods.journal.title, type='starts') if mods.journal.title else [] suggestions = [journal_suggestion_data(journal) for journal in journals] if mods.journal.title.lower() in map(str.lower, JOURNAL_LIST): mods.journal.title = suggestions[0]['value'] print "JOURNAL" print mods.journal.title article.save() else: continue except: suggestions = [] # if mods.journal.publisher is not None: # try: # publishers = romeo.search_publisher_name(mods.journal.publisher, versions='all') # suggestions = [publisher_suggestion_data(pub) for pub in publishers] # mods.journal.publisher = suggestions[0]['value'] # print "PUBLISHER" # print mods.journal.publisher # except: # suggestions = [] else: continue except Exception as e: self.output(0, "Error processing pid: %s : %s " % (article.pid, e.message))