# -*- coding: utf-8 -*- """test_all_harvester """ import pytest from gluon import current from harvest_tools.articles import ( MSG_NO_EDITOR, MSG_TRANSFORM_PREPRINT) from harvest_tools.base import ( MSG_FIX_ORIGIN, MSG_IN_DB, MSG_LOAD, MSG_NO_ENTRY, MSG_TOOMANY_SYNONYM) from harvest_tools.checkandfix import ( MSG_NO_AUTHOR, MSG_NO_CONF_DATE, MSG_NO_DATE, MSG_NO_MY_AUTHOR, MSG_NO_REF, MSG_NO_YEAR, MSG_TEMPORARY_RECORD, MSG_TO_MANY_DATE, MSG_TO_MANY_FAUTHOR, MSG_TO_MANY_YEAR, MSG_WELL_FORMED_CONF_DATES, MSG_WELL_FORMED_DATE, MSG_WELL_FORMED_EDITOR) from harvest_tools.factory import build_harvester_tool from harvest_tools.preprints import ( MSG_PREPRINT_IS_PAPER, MSG_PREPRINT_IS_CONFERENCE, MSG_PREPRINT_IS_THESIS, MSG_PREPRINT_NO_NUMBER) from harvest_tools.reports import MSG_REPORT_NO_NUMBER from harvest_tools.thesis import MSG_NO_THESIS from invenio_tools.base import MSG_NO_CONF, MSG_NO_PUBLISHER @pytest.fixture(scope="module") def messages(): T = current.T set_msgs = { T(MSG_NO_EDITOR), T(MSG_TRANSFORM_PREPRINT), T(MSG_FIX_ORIGIN), T(MSG_IN_DB), T(MSG_LOAD), T(MSG_NO_ENTRY % "collaborations"), T(MSG_NO_ENTRY % "countries"), T(MSG_NO_ENTRY % "publishers"), T(MSG_TOOMANY_SYNONYM), T(MSG_NO_AUTHOR), T(MSG_NO_CONF), T(MSG_NO_CONF_DATE), T(MSG_NO_DATE), T(MSG_NO_MY_AUTHOR), T(MSG_NO_PUBLISHER), T(MSG_NO_REF), T(MSG_NO_THESIS), T(MSG_NO_YEAR), T(MSG_PREPRINT_IS_PAPER), T(MSG_PREPRINT_IS_CONFERENCE), T(MSG_PREPRINT_IS_THESIS), T(MSG_PREPRINT_NO_NUMBER), T(MSG_REPORT_NO_NUMBER), T(MSG_TEMPORARY_RECORD), T(MSG_TO_MANY_DATE), T(MSG_TO_MANY_FAUTHOR), T(MSG_TO_MANY_YEAR), T(MSG_WELL_FORMED_CONF_DATES), T(MSG_WELL_FORMED_DATE), T(MSG_WELL_FORMED_EDITOR)} return set_msgs def test_astro_gamma(messages): """Test all harvesters for the astro-gamma team. """ # Parameters # Select the current year in order to test different case db = current.db id_team = 2 year = current.request.now.year # get the list of harvester query = db.harvesters.id_teams == id_team # process for harvester in db(query).iterselect(): tool = build_harvester_tool( db, harvester.id_teams, harvester.id_projects, harvester.controller, harvester.id_categories, year_start=str(year), year_end="", dry_run=True, debug=False) tool.process_url(harvester.host, harvester.collections) # analyse the log # Number of article cannot be check since it evolve within a year # Only test that there are no unexpected messages msgs = set([el.txt for el in tool.logs]) assert msgs.issubset(messages) def test_atlas_all(messages): """Test all harvesters for the Atlas team. """ # Parameters # Select the current year in order to test different case db = current.db id_team = 3 year = current.request.now.year # get the list of harvester query = db.harvesters.id_teams == id_team # process for harvester in db(query).iterselect(): tool = build_harvester_tool( db, harvester.id_teams, harvester.id_projects, harvester.controller, harvester.id_categories, year_start=str(year), year_end="", dry_run=True, debug=False) tool.process_url(harvester.host, harvester.collections) # analyse the log # Number of article cannot be check since it evolve within a year # Only test that there are no unexpected messages msgs = set([el.txt for el in tool.logs]) assert msgs.issubset(messages) def test_lhcb_all(messages): """Test all harvesters for the LHCb team. """ # Parameters # Select the current year in order to test different case db = current.db id_team = 7 year = current.request.now.year # get the list of harvester query = db.harvesters.id_teams == id_team # process for harvester in db(query).iterselect(): tool = build_harvester_tool( db, harvester.id_teams, harvester.id_projects, harvester.controller, harvester.id_categories, year_start=str(year), year_end="", dry_run=True, debug=False) tool.process_url(harvester.host, harvester.collections) # analyse the log # Number of article cannot be check since it evolve within a year # Only test that there are no unexpected messages msgs = set([el.txt for el in tool.logs]) assert msgs.issubset(messages)