7648 |
7648 |
assert live_resp.json['result']['3']['items'][0]['foo'] == 'bar'
|
7649 |
7649 |
|
7650 |
7650 |
|
|
7651 |
def test_field_live_timetable_select(pub, http_requests):
|
|
7652 |
NamedDataSource.wipe()
|
|
7653 |
data_source = NamedDataSource(name='foobar')
|
|
7654 |
data_source.data_source = {
|
|
7655 |
'type': 'json',
|
|
7656 |
'value': 'http://remote.example.net/api/datetimes{% if form_var_bar2 %}?{% endif %}',
|
|
7657 |
}
|
|
7658 |
data_source.store()
|
|
7659 |
|
|
7660 |
FormDef.wipe()
|
|
7661 |
formdef = FormDef()
|
|
7662 |
formdef.name = 'Foo'
|
|
7663 |
formdef.fields = [
|
|
7664 |
fields.StringField(type='string', id='2', label='Bar2', size='40', required=True, varname='bar2'),
|
|
7665 |
fields.ItemField(
|
|
7666 |
id='3', type='item', label='datetime', display_mode='timetable', data_source={'type': 'foobar'}
|
|
7667 |
),
|
|
7668 |
]
|
|
7669 |
formdef.store()
|
|
7670 |
formdef.data_class().wipe()
|
|
7671 |
|
|
7672 |
app = get_app(pub)
|
|
7673 |
|
|
7674 |
with mock.patch('wcs.qommon.misc.urlopen') as urlopen:
|
|
7675 |
data = {
|
|
7676 |
"data": [
|
|
7677 |
{"id": "1", "datetime": "2021-01-12 10:00:00", "text": "event 1", "api": {}},
|
|
7678 |
{"id": "2", "datetime": "2021-01-13 10:20:00", "text": "event 2", "api": {}},
|
|
7679 |
{"id": "3", "datetime": "2021-01-14 10:40:00", "text": "event 3", "api": {}},
|
|
7680 |
]
|
|
7681 |
}
|
|
7682 |
urlopen.side_effect = lambda *args: io.StringIO(json.dumps(data))
|
|
7683 |
|
|
7684 |
resp = app.get('/foo/')
|
|
7685 |
assert resp.html.find('div', {'data-field-id': '2'}).attrs['data-live-source'] == 'true'
|
|
7686 |
assert resp.html.find('div', {'data-field-id': '3'}).find('select')
|
|
7687 |
resp.form['f2'] = 'plop'
|
|
7688 |
live_resp = app.post('/foo/live?modified_field_id=2', params=resp.form.submit_fields())
|
|
7689 |
assert 'datetime' in live_resp.json['result']['3']['items'][0]
|
|
7690 |
assert 'api' not in live_resp.json['result']['3']['items'][0]
|
|
7691 |
|
|
7692 |
|
7651 |
7693 |
def test_field_live_comment_content(pub, http_requests):
|
7652 |
7694 |
FormDef.wipe()
|
7653 |
7695 |
formdef = FormDef()
|