toulouse_foederis: retrieve HTML field contents (#68546)
This commit is contained in:
parent
45c45fb534
commit
918e46d99d
|
@ -108,6 +108,12 @@ class Resource(BaseResource, HTTPResource):
|
|||
('reference_offre', 'reference_offre'),
|
||||
]
|
||||
|
||||
DEMANDE_DE_PERSONNEL_FIELDS = [
|
||||
# response_field, document_field
|
||||
('missions', 'description'),
|
||||
('profil_requis', 'profil'),
|
||||
]
|
||||
|
||||
ANNOUNCE_SCHEMA = {
|
||||
'type': 'object',
|
||||
'properties': {field: {'type': 'string'} for dummy, field in ANNOUNCES_FIELDS},
|
||||
|
@ -117,12 +123,34 @@ class Resource(BaseResource, HTTPResource):
|
|||
'description': _('Public URL of the PDF announce'),
|
||||
}
|
||||
|
||||
FIELD_ANNOUNCE_FKEY_DEMANDE_DE_PERSONNEL = 'R14848258'
|
||||
|
||||
def update_announce(self, response_announce):
|
||||
document_data = {
|
||||
document_field: response_announce.get(response_field)
|
||||
for response_field, document_field in self.ANNOUNCES_FIELDS
|
||||
}
|
||||
file_content = None
|
||||
|
||||
# retrieve HTML content fields
|
||||
if len(response_announce[self.FIELD_ANNOUNCE_FKEY_DEMANDE_DE_PERSONNEL]):
|
||||
recrut_id = response_announce[self.FIELD_ANNOUNCE_FKEY_DEMANDE_DE_PERSONNEL][0]
|
||||
try:
|
||||
fields = ','.join([x[0] for x in self.DEMANDE_DE_PERSONNEL_FIELDS])
|
||||
params = {
|
||||
'filterName': 'id',
|
||||
'filterValue': recrut_id,
|
||||
'fieldList': fields,
|
||||
'viewIntegrationName': 'api_publik',
|
||||
}
|
||||
results = self.http_request('GET', 'data/demande_de_personnel', params=params)
|
||||
except requests.RequestException:
|
||||
raise UpdateError(_('Service is unavailable'))
|
||||
if len(results):
|
||||
for response_field, document_field in self.DEMANDE_DE_PERSONNEL_FIELDS:
|
||||
if response_field in results[0]:
|
||||
document_data[document_field] = results[0][response_field]
|
||||
|
||||
document_data['id'] = announce_id = str(response_announce['id'])
|
||||
external_id = f'announce-{announce_id}'
|
||||
text = document_data['text'] = document_data['intitule']
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"code" : 200,
|
||||
"message" : "OK",
|
||||
"results" : [
|
||||
{
|
||||
"id" : 3450229,
|
||||
"missions" : "Métier : CHARGE OU CHARGEE PLANIFICATION PROGRAMMATION (ADT/UA/03)<br><br>Diagnostics et études préalables : <br><br>Pilotage des procédures d’évolution du PLUIH et du RLPI : <br><br>Suivi technique administratif et financier :",
|
||||
"profil_requis" : "Métier : CHARGE OU CHARGEE PLANIFICATION PROGRAMMATION (ADT/UA/03)<br><br>Connaissances : <br> - Droit et réglementation dans le domaine (niveau : 4)<br> - Techniques de planification urbaine ( SIG, bases de données) (niveau : 1)<br> - Environnement administratif, institutionnel et politique (niveau : 4)<br> - Foncier (niveau : 2)<br> - Urbanisme (niveau : 3)<br> - Aménagement urbain (niveau : 3)<br> - Environnement territorial (niveau : 3)<br> - Géographie et cartographie (niveau : 3)<br> - Bureautique et/ou outils collaboratifs (niveau : 2)<br> - Logiciels métiers (niveau : 1)<br> - Techniques de rédaction dans le domaine (niveau : 4)<br> - Ingénierie de conduite de projet (niveau : 4)<br><br>Savoir Faire : <br> - Accompagner l'application de la réglementation (niveau : 3)<br> - Travailler en partenariat (niveau : 4)<br> - Analyser un besoin (niveau : 4)<br> - Conduire un projet (niveau : 4)<br> - Coordonner des actions (niveau : 4)<br> - Contrôler (niveau : 3)<br> - Evaluer un dispositif, un projet, une action, un budget (niveau : 4)<br> - Mener une veille dans le domaine (niveau : 3)<br><br>Savoir Être : <br> - Etre réactif (niveau : 4)<br> - Etre rigoureux (niveau : 4)<br> - Sens de l'organisation (niveau : 4)<br> - Capacité d’analyse (niveau : 4)<br> - Esprit de synthèse (niveau : 4)<br> - Aisance relationnelle (niveau : 4)<br> - Sens du travail en équipe (niveau : 4)"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
import base64
|
||||
import json
|
||||
import os
|
||||
import urllib.parse
|
||||
|
||||
import httmock
|
||||
import pytest
|
||||
|
@ -65,6 +66,21 @@ APIKEY = '111c11ee-e1b1-11f1-11ce-11d11af1a111-1111-111111'
|
|||
|
||||
@pytest.fixture
|
||||
def http_mock():
|
||||
for annonce_r14848258 in [3450229, 3782122, 3782130, 4005534, 4005526]:
|
||||
HTTP_MOCKS['html-fields-%s' % annonce_r14848258] = {
|
||||
'path': r'^.*/data/demande_de_personnel$',
|
||||
'query': '&'.join(
|
||||
[
|
||||
'filterName=id',
|
||||
'filterValue=%s' % annonce_r14848258,
|
||||
'fieldList=missions' + urllib.parse.quote(',') + 'profil_requis',
|
||||
'viewIntegrationName=api_publik',
|
||||
]
|
||||
),
|
||||
# give same html field contents for all annonces (only test first one here)
|
||||
'content': get_json_content('demande_de_personnel'),
|
||||
}
|
||||
|
||||
handlers = []
|
||||
|
||||
for defn in HTTP_MOCKS.values():
|
||||
|
@ -173,6 +189,11 @@ class TestHourly:
|
|||
resource.hourly()
|
||||
assert 'Service is unavailable' in caplog.text
|
||||
|
||||
def test_html_fields_error_500(self, resource, http_mock, caplog):
|
||||
with mock_url(url=r'/.*demande_de_personnel.*', status_code=500):
|
||||
resource.hourly()
|
||||
assert 'Service is unavailable' in caplog.text
|
||||
|
||||
|
||||
class TestEndpoints:
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -218,6 +239,11 @@ class TestEndpoints:
|
|||
assert setof('filiere') == {'', 'FILIERE TECHNIQUE'}
|
||||
assert setof('date') == {'2022-04-11', '2022-04-06', '2022-03-17', '2022-04-19', '2022-04-13'}
|
||||
assert setof('date_fin_publication') == {'2022-05-11', '2022-04-25', '2022-12-31', '2022-04-30'}
|
||||
|
||||
# check html fields
|
||||
assert '<br>Pilotage' in data[0]['description']
|
||||
assert '<br>Connaissances' in data[0]['profil']
|
||||
|
||||
# check anti-chronological order on 'date'
|
||||
assert list(sorted(setof('date'), reverse=True)) == list(x['date'] for x in data)
|
||||
|
||||
|
|
Loading…
Reference in New Issue