isere-esrh: add job-types endpoint (#82880)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Corentin Sechet 2023-10-26 17:02:23 +02:00 committed by Corentin Sechet
parent a8e2223c50
commit 230d424571
2 changed files with 60 additions and 0 deletions

View File

@ -127,3 +127,25 @@ class IsereESRH(BaseResource, HTTPResource):
result.append(entity | {'id': id, 'text': label})
return {'data': result}
@endpoint(
name='job-types',
description=_('Get job types'),
parameters={
'authority': {'description': _('Public authority'), 'example_value': 'CG38'},
},
)
def job_types(self, request, authority):
job_types = self._get(
'Poste', params={'codeCollectivite': authority, 'avecLibellePoste': True, 'aDate': iso_now()}
)
result = []
for job_type in job_types:
id = job_type.get('posteId')
labels = job_type.get('libelles', [])
label = 'N/A' if len(labels) == 0 else labels[0]['libelle']
result.append(job_type | {'id': id, 'text': label})
return {'data': result}

View File

@ -242,3 +242,41 @@ def test_entities(app, connector, freezer):
response = app.get('/isere-esrh/test/entities?code_pattern=^6500&label_pattern=^dir\\..*')
assert response.json['data'] == [entity_1]
def test_job_types(app, connector, freezer):
freezer.move_to('1871-03-18 13:13:00')
now = urllib.parse.quote('1871-03-18T13:13:00+00:00')
@httmock.urlmatch()
def error_handler(url, request):
assert False, 'should not be reached'
@httmock.urlmatch(
path=r'^/api/v2/Poste$', query=f'codeCollectivite=CG38&avecLibellePoste=True&aDate={now}'
)
def mock_entites(url, request):
return httmock.response(
200,
{
'values': [
{'posteId': 1, 'libelles': [{'libelle': 'Patron de l\'auberge'}], 'ravioles': 'non'},
{'posteId': 2, 'libelles': [], 'ravioles': 'oui'},
{'posteId': 3, 'ravioles': 'non'},
]
},
)
with httmock.HTTMock(mock_entites, error_handler):
response = app.get('/isere-esrh/test/job-types?authority=CG38')
assert response.json['data'] == [
{
'id': 1,
'text': 'Patron de l\'auberge',
'ravioles': 'non',
'posteId': 1,
'libelles': [{'libelle': 'Patron de l\'auberge'}],
},
{'id': 2, 'text': 'N/A', 'ravioles': 'oui', 'posteId': 2, 'libelles': []},
{'id': 3, 'text': 'N/A', 'ravioles': 'non', 'posteId': 3},
]