6562 |
6562 |
resp2 = app.get(select2_url + '?q=hell')
|
6563 |
6563 |
assert len(rsps.calls) == 1
|
6564 |
6564 |
assert rsps.calls[-1].request.url == 'http://remote.example.net/json?q=hell'
|
6565 |
|
assert resp2.json == data
|
|
6565 |
assert resp2.json == dict(data, err=0)
|
6566 |
6566 |
|
6567 |
6567 |
# check unauthorized access
|
6568 |
6568 |
resp2 = get_app(pub).get(select2_url + '?q=hell', status=403)
|
... | ... | |
6582 |
6582 |
resp2 = app.get(select2_url + '?q=hell')
|
6583 |
6583 |
assert len(rsps.calls) == 1
|
6584 |
6584 |
assert rsps.calls[-1].request.url == 'http://remote.example.net/json?q=hell'
|
6585 |
|
assert resp2.json == {'data': [], 'err': '1'}
|
|
6585 |
assert resp2.json == {'data': [], 'err': 1}
|
6586 |
6586 |
assert emails.count() == 0
|
6587 |
6587 |
|
6588 |
6588 |
data_source.notify_on_errors = True
|
... | ... | |
6641 |
6641 |
resp2 = app.get(select2_url + '?q=hell')
|
6642 |
6642 |
assert len(rsps.calls) == 1
|
6643 |
6643 |
assert rsps.calls[-1].request.url == 'http://remote.example.net/json-numeric-id?q=hell'
|
6644 |
|
assert resp2.json == data
|
|
6644 |
assert resp2.json == dict(data, err=0)
|
6645 |
6645 |
|
6646 |
6646 |
# check unauthorized access
|
6647 |
6647 |
resp2 = get_app(pub).get(select2_url + '?q=hell', status=403)
|
... | ... | |
6697 |
6697 |
assert rsps.calls[-1].request.url.startswith(
|
6698 |
6698 |
'http://remote.example.net/json?q=hell&orig=example.net&'
|
6699 |
6699 |
)
|
6700 |
|
assert resp2.json == data
|
|
6700 |
assert resp2.json == dict(data, err=0)
|
6701 |
6701 |
|
6702 |
6702 |
# simulate select2 mode, with qommon.forms.js adding an extra hidden widget
|
6703 |
6703 |
resp.form.fields['f0_display'] = Hidden(form=resp.form, tag='input', name='f0_display', pos=10)
|
... | ... | |
6764 |
6764 |
resp2 = app.get(select2_url + '?q=hell', status=403)
|
6765 |
6765 |
assert len(rsps.calls) == 0
|
6766 |
6766 |
|
|
6767 |
# check with data, id and text attribute
|
|
6768 |
data_source.data_source = {'type': 'json', 'value': 'http://remote.example.net/json'}
|
|
6769 |
data_source.data_attribute = 'x.results'
|
|
6770 |
data_source.id_attribute = 'key'
|
|
6771 |
data_source.text_attribute = 'value'
|
|
6772 |
data_source.store()
|
|
6773 |
|
|
6774 |
formdef.data_class().wipe()
|
|
6775 |
|
|
6776 |
app = get_app(pub)
|
|
6777 |
with responses.RequestsMock() as rsps:
|
|
6778 |
resp = app.get('/test/')
|
|
6779 |
pq = resp.pyquery.remove_namespaces()
|
|
6780 |
select2_url = pq('select').attr['data-select2-url']
|
|
6781 |
|
|
6782 |
with responses.RequestsMock() as rsps:
|
|
6783 |
data = {
|
|
6784 |
'x': {
|
|
6785 |
'results': [
|
|
6786 |
{'key': '1', 'value': 'hello', 'extra': 'foo'},
|
|
6787 |
]
|
|
6788 |
}
|
|
6789 |
}
|
|
6790 |
normalized_data = {
|
|
6791 |
'data': [{'id': '1', 'text': 'hello', 'extra': 'foo', 'key': '1', 'value': 'hello'}]
|
|
6792 |
}
|
|
6793 |
rsps.get('http://remote.example.net/json', json=data)
|
|
6794 |
resp2 = app.get(select2_url + '?q=hell')
|
|
6795 |
assert resp2.json == dict(normalized_data, err=0)
|
|
6796 |
|
6767 |
6797 |
|
6768 |
6798 |
def test_item_field_autocomplete_jsonp_source(http_requests, pub):
|
6769 |
6799 |
create_user(pub)
|