Commit f99dadff authored by Romain Courteaud's avatar Romain Courteaud

erp5_hal_json_style: ensure select list result can be sent as JSON

parent 486c7327
Pipeline #12988 failed with stage
in 0 seconds
...@@ -2017,7 +2017,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -2017,7 +2017,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
elif isinstance(default_field_value, datetime.date): elif isinstance(default_field_value, datetime.date):
default_field_value = formatdate(time.mktime(default_field_value.timetuple())) default_field_value = formatdate(time.mktime(default_field_value.timetuple()))
contents_item[select] = default_field_value contents_item[select] = ensureUTF8(default_field_value)
else: else:
# If the contents_item has field rendering in it, better is to add an # If the contents_item has field rendering in it, better is to add an
......
...@@ -81,9 +81,9 @@ def createIndexedDocument(quantity=1): ...@@ -81,9 +81,9 @@ def createIndexedDocument(quantity=1):
def decorator(func): def decorator(func):
def wrapped(self, *args, **kwargs): def wrapped(self, *args, **kwargs):
wipeFolder(self.portal.foo_module) wipeFolder(self.portal.foo_module)
if quantity <= 1: if quantity == 1:
kwargs.update(document=self._makeDocument()) kwargs.update(document=self._makeDocument())
else: elif quantity > 1:
kwargs.update(document_list=[self._makeDocument() for _ in range(quantity)]) kwargs.update(document_list=[self._makeDocument() for _ in range(quantity)])
self.portal.portal_caches.clearAllCache() self.portal.portal_caches.clearAllCache()
self.tic() self.tic()
...@@ -2332,6 +2332,31 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id ...@@ -2332,6 +2332,31 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id
self.assertEqual(result_dict['_embedded']['_view']['listbox']['selection_name'], selection_name) self.assertEqual(result_dict['_embedded']['_view']['listbox']['selection_name'], selection_name)
self.assertEqual(result_dict['_embedded']['_view']['listbox']['checked_uid_list'], [9876, 1234]) self.assertEqual(result_dict['_embedded']['_view']['listbox']['checked_uid_list'], [9876, 1234])
@simulate('Base_getRequestUrl', '*args, **kwargs', 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs', 'return "application/hal+json"')
@createIndexedDocument(quantity=1)
@changeSkin('Hal')
def test_getHateoas_property_corrupted_encoding(self, document):
# this sequence of bytes does not encode to UTF-8
document.setTitle('\xe9\xcf\xf3\xaf')
# self.tic()
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
query='uid:"%s"' % document.getUid(),
select_list=['title'],
)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
self.assertEqual(len(result_dict['_embedded']['contents']), 1)
self.assertEqual(result_dict['_embedded']['contents'][0]["title"], u'\ufffd\ufffd\ufffd')
class TestERP5Person_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin): class TestERP5Person_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
"""Test HAL_JSON operations on cataloged Persons and other allowed content types of Person Module.""" """Test HAL_JSON operations on cataloged Persons and other allowed content types of Person Module."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment