def run_import(claims_file, queue='ads.orcid.claims', **kwargs): """ Import claims from a file and inserts them into ads.orcid.claims queue :param: claims_file - path to the claims :type: str :param: queue - where to send the claims :type: str (ads.orcid.claims) :return: no return """ logging.captureWarnings(True) logger.info('Loading records from: {0}'.format(claims_file)) c = [] importer.import_recs(claims_file, collector=c) if len(c): worker = RabbitMQWorker(params={ 'publish': queue, 'exchange': app.config.get('EXCHANGE', 'ads-orcid') }) worker.connect(app.config.get('RABBITMQ_URL')) for claim in c: worker.publish(claim) logger.info('Done processing {0} claims.'.format(len(c)))
def test_importer_import_recs(self): """It should know how to import bibcode:orcidid pairs :return None """ fake_file = BytesIO("\n".join([ "b123456789123456789\t0000-0000-0000-0001", "b123456789123456789\t0000-0000-0000-0002\tarxiv", "b123456789123456789\t0000-0000-0000-0003\tarxiv\tclaimed", "b123456789123456789\t0000-0000-0000-0004\tfoo \tclaimed\t2008-09-03T20:56:35.450686Z", "b123456789123456789\t0000-0000-0000-0005", "b123456789123456789\t0000-0000-0000-0006", "b123456789123456789\t0000-0000-0000-0004\tfoo \tupdated\t2009-09-03T20:56:35.450686Z", ])) with mock.patch('ADSOrcid.importer.open', return_value=fake_file, create=True ) as context: importer.import_recs(__file__) self.assertTrue(len(self.app.session.query(ClaimsLog).all()) == 7) fake_file = BytesIO('\n'.join([ "b123456789123456789\t0000-0000-0000-0001", "b123456789123456789\t0000-0000-0000-0002\tarxiv"])) with mock.patch('ADSOrcid.importer.open', return_value=fake_file, create=True ) as context: c = [] importer.import_recs(__file__, collector=c) self.assertTrue(len(c) == 2)