0001-toulouse_axel-get-update-management-dates-39001.patch
functests/toulouse_axel/test_toulouse_axel.py | ||
---|---|---|
3 | 3 | |
4 | 4 | |
5 | 5 |
def test_link(conn, user): |
6 |
print("Get update management dates") |
|
7 |
url = conn + '/update_management_dates' |
|
8 |
resp = requests.get(url) |
|
9 |
resp.raise_for_status() |
|
10 |
res = resp.json() |
|
11 |
assert res['err'] == 0 |
|
12 |
pprint.pprint(res) |
|
13 |
print('\n') |
|
14 | ||
6 | 15 |
name_id = user['name_id'] |
7 | 16 |
url = conn + '/link?NameID=%s' % name_id |
8 | 17 |
payload = { |
passerelle/contrib/toulouse_axel/models.py | ||
---|---|---|
172 | 172 | |
173 | 173 | |
174 | 174 |
def xml_schema_converter(name, root_element): |
175 |
return AxelSchema(os.path.join(BASE_XSD_PATH, name), root_element) |
|
175 |
xsd_path = os.path.join(BASE_XSD_PATH, name) |
|
176 |
if not os.path.exists(xsd_path): |
|
177 |
return None |
|
178 |
return AxelSchema(xsd_path, root_element) |
|
176 | 179 | |
177 | 180 | |
178 | 181 |
OperationResult = namedtuple('OperationResult', ['json_response', 'xml_request', 'xml_response']) |
... | ... | |
196 | 199 |
schema['merge_extra'] = True |
197 | 200 |
return schema |
198 | 201 | |
199 |
def __call__(self, resource, request_data): |
|
202 |
def __call__(self, resource, request_data=None):
|
|
200 | 203 |
client = resource.soap_client() |
201 | 204 | |
202 |
try: |
|
203 |
serialized_request = self.request_converter.encode(request_data) |
|
204 |
except xmlschema.XMLSchemaValidationError as e: |
|
205 |
raise AxelError('invalid request %s' % str(e)) |
|
206 |
indent(serialized_request) |
|
207 |
serialized_request = ET.tostring(serialized_request) |
|
208 |
try: |
|
209 |
self.request_converter.xml_schema.validate(serialized_request) |
|
210 |
except xmlschema.XMLSchemaValidationError as e: |
|
211 |
raise AxelError( |
|
212 |
'invalid request %s' % str(e), |
|
213 |
xml_request=serialized_request) |
|
205 |
serialized_request = '' |
|
206 |
if self.request_converter: |
|
207 |
try: |
|
208 |
serialized_request = self.request_converter.encode(request_data) |
|
209 |
except xmlschema.XMLSchemaValidationError as e: |
|
210 |
raise AxelError('invalid request %s' % str(e)) |
|
211 |
indent(serialized_request) |
|
212 |
serialized_request = ET.tostring(serialized_request) |
|
213 |
try: |
|
214 |
self.request_converter.xml_schema.validate(serialized_request) |
|
215 |
except xmlschema.XMLSchemaValidationError as e: |
|
216 |
raise AxelError( |
|
217 |
'invalid request %s' % str(e), |
|
218 |
xml_request=serialized_request) |
|
214 | 219 | |
215 | 220 |
result = client.service.getData( |
216 | 221 |
self.operation, |
... | ... | |
240 | 245 |
xml_response=pretty_result) |
241 | 246 | |
242 | 247 | |
248 |
ref_date_gestion_dui = Operation('RefDateGestionDui') |
|
243 | 249 |
ref_verif_dui = Operation('RefVerifDui') |
244 | 250 |
ref_famille_dui = Operation('RefFamilleDui') |
245 | 251 |
form_maj_famille_dui = Operation('FormMajFamilleDui') |
... | ... | |
402 | 408 |
except Lock.DoesNotExist: |
403 | 409 |
return {'key': key, 'locked': False} |
404 | 410 | |
411 |
@endpoint( |
|
412 |
description=_("Get dates of the update management"), |
|
413 |
perm='can_access') |
|
414 |
def update_management_dates(self, request): |
|
415 |
try: |
|
416 |
result = ref_date_gestion_dui(self) |
|
417 |
except AxelError as e: |
|
418 |
raise APIError( |
|
419 |
'Axel error: %s' % e, |
|
420 |
err_code='error', |
|
421 |
data={'xml_request': e.xml_request, |
|
422 |
'xml_response': e.xml_response}) |
|
423 |
return {'data': result.json_response['DATA']['PORTAIL']['DUIDATEGESTION']} |
|
424 | ||
405 | 425 |
@endpoint( |
406 | 426 |
description=_('Create link between user and Toulouse Axel'), |
407 | 427 |
perm='can_access', |
passerelle/contrib/toulouse_axel/xsd/Dui/R_RefDateGestionDui.xsd | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8" ?> |
|
2 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:all="urn:AllAxelTypes"> |
|
3 |
|
|
4 |
<xsd:import schemaLocation="../AllAxelTypes.xsd" namespace="urn:AllAxelTypes" /> |
|
5 |
|
|
6 |
<xsd:redefine schemaLocation="../R_ShemaResultat.xsd"> |
|
7 |
<xsd:simpleType name="TYPEType"> |
|
8 |
<xsd:restriction base="TYPEType"> |
|
9 |
<xsd:enumeration value="RefDateGestionDui" /> |
|
10 |
</xsd:restriction> |
|
11 |
</xsd:simpleType> |
|
12 |
|
|
13 |
<xsd:complexType name="PORTAILType"> |
|
14 |
<xsd:complexContent> |
|
15 |
<xsd:extension base="PORTAILType"> |
|
16 |
<xsd:sequence> |
|
17 |
<xsd:element ref="DUIDATEGESTION" minOccurs="0"/> |
|
18 |
</xsd:sequence> |
|
19 |
</xsd:extension> |
|
20 |
</xsd:complexContent> |
|
21 |
</xsd:complexType> |
|
22 |
</xsd:redefine> |
|
23 |
|
|
24 |
<xsd:complexType name="DUIDATEGESTIONType"> |
|
25 |
<xsd:sequence> |
|
26 |
<xsd:element ref="REPORT-REVENUS" /> |
|
27 |
<xsd:element ref="EXTRACTION-FAMILLES" /> |
|
28 |
<xsd:element ref="EXTRACTION-CAFPRO" /> |
|
29 |
</xsd:sequence> |
|
30 |
</xsd:complexType> |
|
31 |
|
|
32 |
<xsd:element name="REPORT-REVENUS" type="all:DATEType"/> |
|
33 |
<xsd:element name="EXTRACTION-FAMILLES" type="all:DATEType"/> |
|
34 |
<xsd:element name="EXTRACTION-CAFPRO" type="all:DATEType"/> |
|
35 |
|
|
36 |
<xsd:element name="DUIDATEGESTION" type="DUIDATEGESTIONType" /> |
|
37 |
|
|
38 |
</xsd:schema> |
tests/test_toulouse_axel.py | ||
---|---|---|
32 | 32 |
OperationResult, |
33 | 33 |
ToulouseAxel, |
34 | 34 |
form_maj_famille_dui, |
35 |
ref_date_gestion_dui, |
|
35 | 36 |
ref_famille_dui, |
36 | 37 |
ref_facture_a_payer, |
37 | 38 |
ref_facture_pdf, |
... | ... | |
238 | 239 |
yield |
239 | 240 | |
240 | 241 | |
242 |
@pytest.mark.parametrize('content', [ |
|
243 |
'<PORTAIL><DUIDATEGESTION/></PORTAIL>', |
|
244 |
]) |
|
245 |
def test_operation_ref_date_gestion_dui(resource, content): |
|
246 |
with mock_getdata(content, 'RefDateGestionDui'): |
|
247 |
with pytest.raises(AxelError): |
|
248 |
ref_date_gestion_dui(resource) |
|
249 | ||
250 | ||
241 | 251 |
@pytest.mark.parametrize('content', [ |
242 | 252 |
'<PORTAIL><DUI/></PORTAIL>', |
243 | 253 |
'<PORTAIL><DUI><CODE>foo</CODE></DUI></PORTAIL>', |
... | ... | |
317 | 327 |
}) |
318 | 328 | |
319 | 329 | |
330 |
def test_update_management_dates_endpoint_axel_error(app, resource): |
|
331 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_date_gestion_dui') as operation: |
|
332 |
operation.side_effect = AxelError('FooBar') |
|
333 |
resp = app.get('/toulouse-axel/test/update_management_dates') |
|
334 |
assert resp.json['err_desc'] == "Axel error: FooBar" |
|
335 |
assert resp.json['err'] == 'error' |
|
336 |
assert resp.json['data'] == {'xml_request': None, 'xml_response': None} |
|
337 | ||
338 | ||
339 |
def test_update_management_dates_endpoint(app, resource): |
|
340 |
content = '''<PORTAIL> |
|
341 |
<DUIDATEGESTION> |
|
342 |
<REPORT-REVENUS>08/08/2019</REPORT-REVENUS> |
|
343 |
<EXTRACTION-FAMILLES>18/10/2019</EXTRACTION-FAMILLES> |
|
344 |
<EXTRACTION-CAFPRO>18/01/2020</EXTRACTION-CAFPRO> |
|
345 |
</DUIDATEGESTION> |
|
346 |
</PORTAIL>''' |
|
347 |
with mock_getdata(content, 'RefDateGestionDui'): |
|
348 |
resp = app.get('/toulouse-axel/test/update_management_dates') |
|
349 |
assert set(resp.json.keys()) == set(['err', 'data']) |
|
350 |
assert resp.json['err'] == 0 |
|
351 |
assert set(resp.json['data'].keys()) == set(['REPORT-REVENUS', 'EXTRACTION-FAMILLES', 'EXTRACTION-CAFPRO']) |
|
352 | ||
353 | ||
320 | 354 |
def test_link_endpoint_nameid_empty(app, resource, link_params): |
321 | 355 |
resp = app.post_json('/toulouse-axel/test/link?NameID=', params=link_params, status=400) |
322 | 356 |
assert resp.json['err_desc'] == "NameID is empty" |
323 |
- |