0001-cartads-cs-add-endpoint-to-list-files-36130.patch
passerelle/apps/cartads_cs/models.py | ||
---|---|---|
885 | 885 |
piece.sent_to_cartads = now() |
886 | 886 |
piece.save() |
887 | 887 | |
888 |
@endpoint(perm='can_access', |
|
889 |
description=_('Get status of file'), |
|
890 |
parameters={ |
|
891 |
'dossier_id': { |
|
892 |
'description': _('Identifier of file'), |
|
893 |
} |
|
894 |
}) |
|
895 |
def status(self, request, dossier_id): |
|
896 |
dossier = CartaDSDossier.objects.get(id=dossier_id) |
|
888 |
def get_file_status(self, dossier): |
|
897 | 889 |
extra = None |
898 | 890 |
if dossier.cartads_id_dossier: |
899 | 891 |
if dossier.cartads_steps_cache: |
... | ... | |
925 | 917 |
return {'status_id': status_id, 'status_label': status_label, 'extra': extra} |
926 | 918 | |
927 | 919 | |
920 |
@endpoint(perm='can_access', |
|
921 |
description=_('Get status of file'), |
|
922 |
parameters={ |
|
923 |
'dossier_id': { |
|
924 |
'description': _('Identifier of file'), |
|
925 |
} |
|
926 |
}) |
|
927 |
def status(self, request, dossier_id): |
|
928 |
dossier = CartaDSDossier.objects.get(id=dossier_id) |
|
929 |
return self.get_file_status(dossier) |
|
930 | ||
931 |
@endpoint(perm='can_access', |
|
932 |
description=_('Get list of files attached to user'), |
|
933 |
parameters={ |
|
934 |
'name_id': { |
|
935 |
'description': _('UUID of requester'), |
|
936 |
'example_value': '3eb56fc' |
|
937 |
}, |
|
938 |
'status': { |
|
939 |
'description': _('File Status'), |
|
940 |
'example_value': 'Attente DOC', |
|
941 |
}, |
|
942 |
}) |
|
943 |
def files(self, request, name_id, status=None): |
|
944 |
files = CartaDSDossier.objects.filter(name_id=name_id, cartads_numero_dossier__isnull=False) |
|
945 |
if status: |
|
946 |
files = [x for x in files if |
|
947 |
self.get_file_status(x).get('status_id') == status or |
|
948 |
self.get_file_status(x).get('status_label') == status] |
|
949 |
return {'data': [ |
|
950 |
{'id': str(x.id), |
|
951 |
'text': x.cartads_numero_dossier, |
|
952 |
'tracking_code': x.tracking_code, |
|
953 |
} for x in files] |
|
954 |
} |
|
955 | ||
956 | ||
928 | 957 |
class CartaDSCS(AbstractCartaDSCS): |
929 | 958 |
category = _('Misc') |
930 | 959 |
class Meta: |
tests/test_cartads_cs.py | ||
---|---|---|
521 | 521 | |
522 | 522 |
assert CartaDSFile.objects.filter(tracking_code=dossier.tracking_code, |
523 | 523 |
sent_to_cartads=None).count() == 0 |
524 | ||
525 | ||
526 |
def test_list_of_files(connector, app, cached_data): |
|
527 |
CartaDSDossier.objects.all().delete() |
|
528 |
test_send(connector, app, cached_data) |
|
529 |
dossier = CartaDSDossier.objects.all()[0] |
|
530 | ||
531 |
with mock.patch('passerelle.apps.cartads_cs.models.CartaDSCS.soap_client') as client: |
|
532 |
client.return_value = mock.Mock(service=FakeService()) |
|
533 |
# all for user |
|
534 |
resp = app.get('/cartads-cs/test/files?name_id=1234') |
|
535 |
assert len(resp.json['data']) == 1 |
|
536 |
# invalid user |
|
537 |
resp = app.get('/cartads-cs/test/files?name_id=5678') |
|
538 |
assert len(resp.json['data']) == 0 |
|
539 |
# existing status |
|
540 |
resp = app.get('/cartads-cs/test/files?name_id=1234&status=En cours de saisie') |
|
541 |
assert len(resp.json['data']) == 1 |
|
542 |
# missing status |
|
543 |
resp = app.get('/cartads-cs/test/files?name_id=1234&status=Attente DOC') |
|
544 |
assert len(resp.json['data']) == 0 |
|
524 |
- |