Commit 5bb6ecac authored by David Foucher's avatar David Foucher

Merge branch 'add-idcc-search' into 'master'

Add idcc search

See merge request ybon/trefle!93
parents 4acecb86 012f6da3
......@@ -119,8 +119,10 @@ async def test_populate_formation_upstream_error(mock_get):
with pytest.raises(exceptions.UpstreamError):
await routine.populate_formation({'formation.numero': 'ZORGLUB'})
def test_build_catalog_url(monkeypatch):
fakenow = datetime.datetime(2017, 10, 12, 13, 45, 0)
class mydate:
@classmethod
def utcnow(cls):
......@@ -132,3 +134,8 @@ def test_build_catalog_url(monkeypatch):
assert routine.build_catalog_url('12345') == 'http://catalog.fr?user=foobar&uid=12345&timestamp=2017-10-12T13%3A45%3A00&signature=2aabef68f687ecdbb084e2b1dc930583'
@pytest.mark.parametrize('term', ['coiff', '2596'])
def test_search_idcc_code_by_word(term):
data = {'2596': {'Convention collective': 'Coiffure', 'OPCA': 'AGEFOS PME',
'OPACIF': 'Fongecif'}}
assert routine.search_idcc(term) == data
......@@ -5,13 +5,13 @@ from roll.extensions import cors
import ujson as json
from . import VERSION, simulate, get_financements
from .config import FINANCEMENTS, GLOSSARY, NAF, RAW_RULES, SCHEMA
from .config import FINANCEMENTS, GLOSSARY, NAF, IDCC, RAW_RULES, SCHEMA
from .debugging import data_from_lbf_url, make_scenario, SCENARIOS
from .exceptions import DataError
from .legacy import simulate_legacy
from .loggers import log_simulate, logger
from .openapis import OPENAPI
from .routine import get_formation_json
from .routine import get_formation_json, search_idcc
app = Roll()
cors(app)
......@@ -78,6 +78,11 @@ async def naf(request, response):
response.json = NAF.get(request.query.get("q"), [])
@app.route("/idcc")
async def idcc(request, response):
response.json = search_idcc(request.query.get("q"))
@app.route("/explore/schema")
async def explore_schema(request, response):
response.json = SCHEMA
......
......@@ -5,7 +5,7 @@ import datetime
from urllib.parse import urlencode
from . import config # allow to monkeypatch test
from .config import CONSTANTS, LABELS, ORGANISMES, RULES, SCHEMA, Organisme
from .config import CONSTANTS, LABELS, ORGANISMES, RULES, SCHEMA, Organisme, IDCC
from .exceptions import DataError
from .helpers import (
......@@ -293,3 +293,15 @@ def check_financement(context, financement):
name = f"financement.{key}"
if name not in SCHEMA or not SCHEMA[name].get("public"):
del financement[key]
def search_idcc(term):
data = {}
for k in IDCC:
if k.startswith(term):
data[k] = IDCC[k]
else:
for v in IDCC[k]:
if IDCC[k][v].lower().startswith(term.lower()):
data[k] = IDCC[k]
return data
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment