arpege_ecp: allow filtering demands by status (#79400)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Serghei Mihai 2023-07-05 11:00:13 +02:00
parent de3d69e2d2
commit 9626f03f34
2 changed files with 15 additions and 2 deletions

View File

@ -75,12 +75,21 @@ class ArpegeECP(BaseResource):
@endpoint(
name='api',
pattern=r'^users/(?P<nameid>\w+)/forms$',
description='Returns user forms',
example_pattern='users/{nameid}/forms',
description=_('Returns user forms'),
parameters={
'nameid': {'description': _('Publik ID'), 'example_value': 'nameid'},
'status': {'description': _('Demands status'), 'example_value': 'pending'},
},
)
def get_user_forms(self, request, nameid):
def get_user_forms(self, request, nameid, status='pending'):
access_token = self.get_access_token(nameid)
url = urlparse.urljoin(self.webservice_base_url, 'DemandesUsager')
params = {'scope': 'data_administratives'}
if status == 'pending':
params['EtatDemande'] = 'DEPOSEE, ENCRSINSTR' # value for filtering pending forms
elif status == 'done':
params['EtatDemande'] = 'TRAITEEPOS, TRAITEENEG, TRAITEE' # value for filtering done forms
auth = HawkAuth(self.hawk_auth_id, self.hawk_auth_key, ext=access_token)
try:
response = self.requests.get(url, params=params, auth=auth)

View File

@ -129,6 +129,7 @@ def test_get_user_forms(mocked_post, mocked_get, app, connector):
mocked_post.return_value = tests.utils.FakedResponse(content=FAKE_LOGIN_OIDC_RESPONSE, status_code=200)
mocked_get.return_value = tests.utils.FakedResponse(content=FAKE_USER_DEMANDS_RESPONSE, status_code=200)
resp = app.get(endpoint)
assert mocked_get.call_args[1]['params']['EtatDemande'] == 'DEPOSEE, ENCRSINSTR'
assert resp.json['data']
for item in resp.json['data']:
assert item['status'] == 'Deposee'
@ -143,6 +144,9 @@ def test_get_user_forms(mocked_post, mocked_get, app, connector):
assert item['readable'] is True
assert item['form_status_is_endpoint'] is False
resp = app.get(endpoint, params={'status': 'done'})
assert mocked_get.call_args[1]['params']['EtatDemande'] == 'TRAITEEPOS, TRAITEENEG, TRAITEE'
@mock.patch('passerelle.utils.Request.get')
@mock.patch('passerelle.utils.Request.post')