test_all_harvesters.py 4.91 KB
Newer Older
LE GAC Renaud's avatar
LE GAC Renaud committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
# -*- 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)