tests: start tests for data sources
This commit is contained in:
parent
b55acfdf9d
commit
afafdcdb25
|
@ -0,0 +1,52 @@
|
|||
import sys
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from quixote import cleanup
|
||||
from wcs import publisher
|
||||
from wcs.qommon.http_request import HTTPRequest
|
||||
from wcs.qommon.form import *
|
||||
from wcs import fields
|
||||
|
||||
from test_widgets import MockHtmlForm, mock_form_submission
|
||||
|
||||
def setup_module(module):
|
||||
cleanup()
|
||||
|
||||
global pub, req
|
||||
|
||||
publisher.WcsPublisher.APP_DIR = tempfile.mkdtemp()
|
||||
pub = publisher.WcsPublisher.create_publisher()
|
||||
|
||||
req = HTTPRequest(None, {})
|
||||
pub._set_request(req)
|
||||
|
||||
|
||||
def teardown_module(module):
|
||||
shutil.rmtree(pub.APP_DIR)
|
||||
|
||||
|
||||
def test_item_field_python_datasource():
|
||||
field = fields.ItemField()
|
||||
field.id = 1
|
||||
field.data_source = {
|
||||
'type': 'formula',
|
||||
'value': '''[('1', 'un'), ('2', 'deux')]'''
|
||||
}
|
||||
form = Form()
|
||||
field.add_to_form(form)
|
||||
widget = form.get_widget('f1')
|
||||
assert widget is not None
|
||||
assert widget.options == [('1', 'un', 'un'), ('2', 'deux', 'deux')]
|
||||
|
||||
form = MockHtmlForm(widget)
|
||||
mock_form_submission(req, widget, {'f1': ['un']})
|
||||
assert widget.parse() == '1'
|
||||
|
||||
form = Form()
|
||||
field.add_to_view_form(form, value='1')
|
||||
widget = form.get_widget('f1')
|
||||
|
||||
form = MockHtmlForm(widget)
|
||||
mock_form_submission(req, widget)
|
||||
assert widget.parse() == '1'
|
Loading…
Reference in New Issue