0002-plone_restapi-add-endpoint-to-get-content-types-5790.patch
passerelle/apps/plone_restapi/models.py | ||
---|---|---|
196 | 196 |
params.update(parse_qsl(filter_expression)) |
197 | 197 |
params['fullobjects'] = 'y' |
198 | 198 |
response = self.request(uri=uri, uid='@search', method='GET', params=params) |
199 | 199 | |
200 | 200 |
for record in response.get('items') or []: |
201 | 201 |
self.adapt_record(record, text_template) |
202 | 202 |
return response.get('items') or [] |
203 | 203 | |
204 |
@endpoint( |
|
205 |
perm='can_access', |
|
206 |
description=_('Get content types'), |
|
207 |
display_order=1, |
|
208 |
) |
|
209 |
def get_content_types(self, request): |
|
210 |
response = self.request(uri='@types', method='GET') |
|
211 |
for record in response or []: |
|
212 |
self.adapt_record(record, '{{ title }}', id_key='PLONE_id') |
|
213 |
record['id'] = record['id'].split('/')[-1] |
|
214 |
return {'data': response or []} |
|
215 | ||
204 | 216 |
@endpoint( |
205 | 217 |
perm='can_access', |
206 | 218 |
description=_('Fetch'), |
207 | 219 |
parameters={ |
208 | 220 |
'uri': {'description': _('Uri')}, |
209 | 221 |
'uid': {'description': _('Uid')}, |
210 | 222 |
'text_template': {'description': _('Text template')}, |
211 | 223 |
}, |
tests/data/plone_restapi/get_content_types.json | ||
---|---|---|
1 |
[ |
|
2 |
{ |
|
3 |
"@id": "https://annuaire.preprod.imio.be/@types/News Item", |
|
4 |
"addable": false, |
|
5 |
"title": "Actualit\u00e9" |
|
6 |
}, |
|
7 |
{ |
|
8 |
"@id": "https://annuaire.preprod.imio.be/@types/Collection", |
|
9 |
"addable": false, |
|
10 |
"title": "Collection" |
|
11 |
}, |
|
12 |
{ |
|
13 |
"@id": "https://annuaire.preprod.imio.be/@types/imio.directory.Contact", |
|
14 |
"addable": false, |
|
15 |
"title": "Contact" |
|
16 |
}, |
|
17 |
{ |
|
18 |
"@id": "https://annuaire.preprod.imio.be/@types/Folder", |
|
19 |
"addable": false, |
|
20 |
"title": "Dossier" |
|
21 |
}, |
|
22 |
{ |
|
23 |
"@id": "https://annuaire.preprod.imio.be/@types/imio.directory.Entity", |
|
24 |
"addable": true, |
|
25 |
"title": "Entit\u00e9" |
|
26 |
}, |
|
27 |
{ |
|
28 |
"@id": "https://annuaire.preprod.imio.be/@types/File", |
|
29 |
"addable": false, |
|
30 |
"title": "Fichier" |
|
31 |
}, |
|
32 |
{ |
|
33 |
"@id": "https://annuaire.preprod.imio.be/@types/Image", |
|
34 |
"addable": false, |
|
35 |
"title": "Image" |
|
36 |
}, |
|
37 |
{ |
|
38 |
"@id": "https://annuaire.preprod.imio.be/@types/Link", |
|
39 |
"addable": false, |
|
40 |
"title": "Lien" |
|
41 |
}, |
|
42 |
{ |
|
43 |
"@id": "https://annuaire.preprod.imio.be/@types/Document", |
|
44 |
"addable": false, |
|
45 |
"title": "Page Web" |
|
46 |
}, |
|
47 |
{ |
|
48 |
"@id": "https://annuaire.preprod.imio.be/@types/Event", |
|
49 |
"addable": false, |
|
50 |
"title": "\u00c9v\u00e9nement" |
|
51 |
} |
|
52 |
] |
tests/test_plone_restapi.py | ||
---|---|---|
279 | 279 |
'text_template': '{{ title }} ({{ PLONE_type }})', |
280 | 280 |
} |
281 | 281 |
with utils.mock_url(url=url, response=response, status_code=status_code, exception=exception): |
282 | 282 |
resp = app.get(endpoint, params=params) |
283 | 283 |
assert resp.json['err'] |
284 | 284 |
assert err_desc in resp.json['err_desc'] |
285 | 285 | |
286 | 286 | |
287 |
def test_get_content_types(app, connector, token): |
|
288 |
endpoint = utils.generic_endpoint_url('plone-restapi', 'get_content_types', slug=connector.slug) |
|
289 |
assert endpoint == '/plone-restapi/my_connector/get_content_types' |
|
290 |
url = connector.service_url + '/@types' |
|
291 |
with utils.mock_url(url=url, response=json_get_data('get_content_types')): |
|
292 |
resp = app.get(endpoint) |
|
293 |
assert not resp.json['err'] |
|
294 |
assert len(resp.json['data']) == 10 |
|
295 |
assert resp.json['data'][2]['id'] == 'imio.directory.Contact' |
|
296 |
assert resp.json['data'][2]['text'] == 'Contact' |
|
297 | ||
298 | ||
287 | 299 |
def test_create(app, connector, token): |
288 | 300 |
endpoint = utils.generic_endpoint_url('plone-restapi', 'create', slug=connector.slug) |
289 | 301 |
assert endpoint == '/plone-restapi/my_connector/create' |
290 | 302 |
url = connector.service_url + '/braine-l-alleud' |
291 | 303 |
payload = { |
292 | 304 |
'@type': 'imio.directory.Contact', |
293 | 305 |
'title': "Test Entr'ouvert", |
294 | 306 |
'type': 'organization', |
295 |
- |