391 |
391 |
payload = {
|
392 |
392 |
'@type': 'imio.directory.Contact',
|
393 |
393 |
'title': "Test Entr'ouvert",
|
394 |
394 |
'type': 'organization',
|
395 |
395 |
'schedule': {},
|
396 |
396 |
'topics/0/title': 'Tourisme',
|
397 |
397 |
'topics/0/token': 'tourism',
|
398 |
398 |
'image': {'filename': 'foo.jpg', 'content_type': 'image/jpeg', 'content': '...'},
|
|
399 |
'phones': [
|
|
400 |
{'label': 'numéro principal', 'number': '0123456789', 'type': 'work'},
|
|
401 |
{'label': '', 'number': '', 'type': ''},
|
|
402 |
],
|
399 |
403 |
}
|
400 |
404 |
with utils.mock_url(url=url, response=json_get_data('fetch'), status_code=201) as mocked:
|
401 |
405 |
resp = app.post_json(endpoint + '?uri=braine-l-alleud&publish=false', params=payload)
|
402 |
406 |
body = json.loads(mocked.handlers[0].call['requests'][1].body)
|
403 |
407 |
assert body['topics'] == [{'title': 'Tourisme', 'token': 'tourism'}]
|
404 |
408 |
assert body['image'] == {
|
405 |
409 |
'filename': 'foo.jpg',
|
406 |
410 |
'content_type': 'image/jpeg',
|
407 |
411 |
'encoding': 'base64',
|
408 |
412 |
'data': '...',
|
409 |
413 |
'content-type': 'image/jpeg',
|
410 |
414 |
}
|
|
415 |
assert body['phones'] == [{'label': 'numéro principal', 'number': '0123456789', 'type': 'work'}]
|
411 |
416 |
assert not resp.json['err']
|
412 |
417 |
assert resp.json['data'] == {
|
413 |
418 |
'uid': 'dccd85d12cf54b6899dff41e5a56ee7f',
|
414 |
419 |
'created': True,
|
415 |
420 |
'review_state': None,
|
416 |
421 |
}
|
417 |
422 |
|
418 |
423 |
|
... | ... | |
466 |
471 |
endpoint = utils.generic_endpoint_url('plone-restapi', 'update', slug=connector.slug)
|
467 |
472 |
assert endpoint == '/plone-restapi/my_connector/update'
|
468 |
473 |
url = connector.service_url + '/braine-l-alleud/dccd85d12cf54b6899dff41e5a56ee7f'
|
469 |
474 |
query_string = '?uri=braine-l-alleud&uid=dccd85d12cf54b6899dff41e5a56ee7f'
|
470 |
475 |
payload = {
|
471 |
476 |
'title': 'Test update',
|
472 |
477 |
'topics/0/token': 'social',
|
473 |
478 |
'image': {'filename': 'foo.jpg', 'content_type': 'image/jpeg', 'content': '...'},
|
|
479 |
'phones': [
|
|
480 |
{'label': '', 'number': '', 'type': ''},
|
|
481 |
{'label': '', 'number': '', 'type': ''},
|
|
482 |
],
|
474 |
483 |
}
|
475 |
484 |
with utils.mock_url(url=url, response='', status_code=204) as mocked:
|
476 |
485 |
resp = app.post_json(endpoint + query_string, params=payload)
|
477 |
486 |
body = json.loads(mocked.handlers[0].call['requests'][1].body)
|
478 |
487 |
assert body['topics'] == [{'token': 'social'}]
|
479 |
488 |
assert body['image'] == {
|
480 |
489 |
'filename': 'foo.jpg',
|
481 |
490 |
'content_type': 'image/jpeg',
|
482 |
491 |
'encoding': 'base64',
|
483 |
492 |
'data': '...',
|
484 |
493 |
'content-type': 'image/jpeg',
|
485 |
494 |
}
|
|
495 |
assert body['phones'] == []
|
|
496 |
|
486 |
497 |
assert not resp.json['err']
|
487 |
498 |
assert resp.json['data'] == {'uid': 'dccd85d12cf54b6899dff41e5a56ee7f', 'updated': True}
|
488 |
499 |
|
489 |
500 |
|
490 |
501 |
def test_update_wrong_payload(app, connector, token):
|
491 |
502 |
endpoint = utils.generic_endpoint_url('plone-restapi', 'update', slug=connector.slug)
|
492 |
503 |
assert endpoint == '/plone-restapi/my_connector/update'
|
493 |
504 |
url = connector.service_url + '/braine-l-alleud/dccd85d12cf54b6899dff41e5a56ee7f'
|
494 |
|
-
|