0001-sigerly-allow-for-new-nom_rue-parameter-and-elements.patch
passerelle/contrib/sigerly/models.py | ||
---|---|---|
26 | 26 |
CREATE_SCHEMA = { |
27 | 27 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
28 | 28 |
"type": "object", |
29 |
'required': ['demandeur', 'id_typeinterv', 'id_urgence', 'elements'],
|
|
29 |
'required': ['demandeur', 'id_typeinterv', 'id_urgence'], |
|
30 | 30 |
'properties': { |
31 | 31 |
'demandeur': { |
32 | 32 |
'description': "Nom du demandeur", |
... | ... | |
53 | 53 |
'type': 'string', |
54 | 54 |
'pattern': r'^[0-9A-Z :]+$', |
55 | 55 |
}, |
56 |
'nom_rue': { |
|
57 |
'description': 'Adresse', |
|
58 |
'type': 'string', |
|
59 |
}, |
|
56 | 60 |
}, |
57 | 61 |
} |
58 | 62 | |
... | ... | |
120 | 124 |
post_data['id_typeinterv'] = int(post_data['id_typeinterv']) |
121 | 125 |
post_data['id_urgence'] = int(post_data['id_urgence']) |
122 | 126 |
post_data['id_qualification'] = int(post_data['id_qualification']) |
123 |
post_data['elements'] = [x.strip() for x in post_data['elements'].split(':') if x.strip()] |
|
127 |
if 'elements' in post_data: |
|
128 |
post_data['elements'] = [x.strip() for x in post_data['elements'].split(':') if x.strip()] |
|
124 | 129 | |
125 | 130 |
response = self.request('createIntervention.php', json=post_data) |
126 | 131 |
if not response.get('success', None): |
tests/test_sigerly.py | ||
---|---|---|
79 | 79 |
def sigerly_mock(url, request): |
80 | 80 |
assert request.headers['Accept'] == 'application/json' |
81 | 81 |
assert json.loads(request.body)['elements'] == ['LIMW003D', 'LIMWW003C'] |
82 |
assert 'nom_rue' not in json.loads(request.body) |
|
83 |
return httmock.response(200, json.dumps({'success': True, 'message': '7830'})) |
|
84 | ||
85 |
with httmock.HTTMock(sigerly_mock): |
|
86 |
resp = app.post_json(endpoint, params=payload) |
|
87 |
assert not resp.json['err'] |
|
88 |
assert resp.json['data']['message'] == '7830' # id unusable within query endpoint |
|
89 | ||
90 | ||
91 |
def test_create_nom_rue(app, connector): |
|
92 |
endpoint = get_endpoint('create') |
|
93 |
payload = { |
|
94 |
'demandeur': 'Test webservice', |
|
95 |
'id_typeinterv': '5', |
|
96 |
'id_urgence': '1', |
|
97 |
'id_qualification': '8', |
|
98 |
'observations': 'Test webservice', |
|
99 |
'nom_rue': 'some place', |
|
100 |
} |
|
101 | ||
102 |
@httmock.urlmatch(netloc='sigerly.example.net', path='/createIntervention.php', method='POST') |
|
103 |
def sigerly_mock(url, request): |
|
104 |
assert request.headers['Accept'] == 'application/json' |
|
105 |
assert json.loads(request.body)['nom_rue'] == 'some place' |
|
106 |
assert 'elements' not in json.loads(request.body) |
|
82 | 107 |
return httmock.response(200, json.dumps({'success': True, 'message': '7830'})) |
83 | 108 | |
84 | 109 |
with httmock.HTTMock(sigerly_mock): |
85 |
- |