tests: extend basic item data source check with json&numeric cases (#47974)

This commit is contained in:
Frédéric Péters 2020-10-22 18:03:06 +02:00
parent 015af97502
commit 6f97cef2b7
1 changed files with 21 additions and 0 deletions

View File

@ -2511,6 +2511,27 @@ def test_form_item_data_source_field_submit(pub):
assert submit_item_data_source_field(ds) == {
'0': '1', '0_display': 'un', '0_structured': {'id': '1', 'text': 'un', 'more': 'foo'}}
# numeric identifiers
ds['value'] = repr([{'id': 1, 'text': 'un'}, {'id': 2, 'text': 'deux'}])
assert submit_item_data_source_field(ds) == {'0': '1', '0_display': 'un'}
# json source
ds = {
'type': 'json',
'value': 'http://www.example.net/plop',
}
with mock.patch('wcs.qommon.misc.urlopen') as urlopen:
data = {'data': [{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}]}
urlopen.side_effect = lambda *args: StringIO(json.dumps(data))
assert submit_item_data_source_field(ds) == {'0': '1', '0_display': 'un'}
# numeric identifiers
with mock.patch('wcs.qommon.misc.urlopen') as urlopen:
data = {'data': [{'id': 1, 'text': 'un'}, {'id': 2, 'text': 'deux'}]}
urlopen.side_effect = lambda *args: StringIO(json.dumps(data))
assert submit_item_data_source_field(ds) == {'0': '1', '0_display': 'un'}
def test_form_items_data_source_field_submit(pub):
def submit_items_data_source_field(ds):