本文整理汇总了Python中iktomi.web.app.AppEnvironment.create方法的典型用法代码示例。如果您正苦于以下问题:Python AppEnvironment.create方法的具体用法?Python AppEnvironment.create怎么用?Python AppEnvironment.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iktomi.web.app.AppEnvironment
的用法示例。
在下文中一共展示了AppEnvironment.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_clean_value
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_clean_value(self):
class AssertConv(convs.Int):
def to_python(conv, value):
value = convs.Int.to_python(conv, value)
if value is not None:
field = conv.field.form.get_field('num')
self.assertEqual(field.clean_value, value)
return value
class F(Form):
fields = [FieldBlock('', fields=[
Field('num',
conv=convs.Int()),
Field('f2',
conv=AssertConv())
])]
env = AppEnvironment.create()
form = F(env)
self.assertEqual(form.get_field('num').clean_value, None)
form = F(env, initial={'num': 2})
self.assertEqual(form.get_field('num').clean_value, 2)
form = F(env)
form.accept({'num': '4', 'f2': '4'})
self.assertEqual(form.get_field('num').clean_value, 4)
self.assertEqual(form.get_field('f2').clean_value, 4)
示例2: test_get_field
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_get_field(self):
class F(Form):
fields = [
FieldSet('fieldset', fields=[
FieldList('fieldlist',
field=FieldSet(None, fields=[
Field('subfield')
])
)
]),
FieldBlock('field block', [
Field('blocksubfield')
], name='block')
]
env = AppEnvironment.create()
form = F(env)
for nm, cls in [('fieldset', FieldSet),
('fieldset.fieldlist', FieldList),
('fieldset.fieldlist.1', FieldSet),
('fieldset.fieldlist.1.subfield', Field),
('block', FieldBlock),
('blocksubfield', Field),
]:
self.assert_(isinstance(form.get_field(nm), cls),
'%s is not instance of %s' % (nm, cls))
self.assertEqual(form.get_field(nm).input_name, nm)
nm, cls = ('block.blocksubfield', Field)
self.assert_(isinstance(form.get_field(nm), cls),
'%s is not instance of %s' % (nm, cls))
self.assertEqual(form.get_field(nm).input_name,
'blocksubfield')
示例3: test_fieldblock_readonly
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_fieldblock_readonly(self):
class _Form(Form):
fields=[
FieldBlock('field block',
fields=[
Field('number',
convs.Int()),
Field('title',
convs.Char()),
],
permissions='r'),
]
env = AppEnvironment.create()
form = _Form(env)
self.assertEqual(form.raw_data, MultiDict([('number', ''),
('title', '')]))
self.assertEqual(form.python_data, {'number': None,
'title': None})
self.assert_(form.accept({'number': '4', 'title': 'Hello'}),
form.errors)
self.assertEqual(form.python_data, {'number': None,
'title': None})
self.assertEqual(form.get_field('number').raw_value, '')
self.assertEqual(form.get_field('title').raw_value, '')
self.assertEqual(form.errors, {})
示例4: test_get_initial
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_get_initial(self):
Form = self.get_form(required=True)
env = AppEnvironment.create()
form = Form(env)
conv = form.get_field('pass').conv
self.assertEqual(conv.get_initial(), '')
示例5: test_accept
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_accept(self):
'Method accept of bound field returns cleaned value'
class _Form(Form):
fields=[Field('input', convs.Char())]
env = AppEnvironment.create()
form = _Form(env)
self.assert_(form.accept(MultiDict(input='value')))
self.assertEqual(form.python_data['input'], 'value')
示例6: test_id
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_id(self):
class _Form(Form):
fields=[Field('input', convs.Char())]
env = AppEnvironment.create()
form = _Form(env)
self.assertEqual(form.get_field('input').id, 'input')
form.id = 'myform'
self.assertEqual(form.get_field('input').id, 'myform-input')
示例7: test_required
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_required(self):
Form = self.get_form(required=True)
env = AppEnvironment.create()
form = Form(env)
form.accept(MultiDict({'pass.pass': '',
'pass.conf': ''}))
self.assertEqual(form.errors.keys(), ['pass'])
示例8: setUp
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def setUp(self):
self.transient_root = tempfile.mkdtemp()
self.persistent_root = tempfile.mkdtemp()
self.transient_url = "/transient/"
self.persistent_url = "/media/"
self.file_manager = FileManager(
self.transient_root, self.persistent_root, self.transient_url, self.persistent_url
)
self.env = AppEnvironment.create(file_manager=self.file_manager)
示例9: test_mismatch
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_mismatch(self):
class _Form(Form):
fields=[PasswordSet()]
env = AppEnvironment.create()
form = _Form(env)
accept = form.accept({'password.pass':'first', 'password.conf':'second'})
self.assertEqual(dict(password='password and confirm mismatch').items(),
form.errors.items())
self.assertFalse(accept)
示例10: test_check_value_type
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_check_value_type(self):
'''Pass file value to ordinary Field'''
class F(Form):
fields = [Field('inp')]
request = Request.blank('/', POST=dict(inp=('foo.txt', 'ggg')))
env = AppEnvironment.create()
form = F(env)
self.assertEqual(form.accept(request.POST), False)
self.assertEqual(form.errors.keys(), ['inp'])
示例11: test_mismatch
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_mismatch(self):
Form = self.get_form()
env = AppEnvironment.create()
form = Form(env)
form.accept(MultiDict({'pass.pass': '123123',
'pass.conf': '123'}))
self.assertEqual(form.python_data, {'pass': None})
self.assertEqual(form.errors.keys(), ['pass'])
示例12: test_accept_multiple
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_accept_multiple(self):
class F(Form):
fields = [
Field('name', conv=convs.ListOf(convs.Int))
]
env = AppEnvironment.create()
form = F(env)
form.accept(MultiDict([('name', '1'), ('name', '2')]))
self.assertEqual(form.python_data['name'], [1, 2])
示例13: test_prefix
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_prefix(self):
class F(Form):
fields=[
Field('first', convs.Int()),
]
env = AppEnvironment.create()
form = F(env)
self.assertEqual(form.get_field('first').input_name, 'first')
form = F(env, name="pref")
self.assertEqual(form.get_field('first').input_name, 'pref:first')
示例14: test_get_perms
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_get_perms(self):
class F(Form):
fields = [Field("first", permissions="rw"), Field("second")]
env = AppEnvironment.create()
form = F(env, permissions="rwx")
first = form.get_field("first")
second = form.get_field("second")
self.assertEqual(first.perm_getter.get_perms(first), set("rw"))
self.assertEqual(second.perm_getter.get_perms(second), set("rwx"))
示例15: test_field_block_existing_value
# 需要导入模块: from iktomi.web.app import AppEnvironment [as 别名]
# 或者: from iktomi.web.app.AppEnvironment import create [as 别名]
def test_field_block_existing_value(self):
class f(Form):
fields = [FieldBlock('block', fields=[Field('number', conv=convs.Int)])]
env = AppEnvironment.create()
form = f(env)
field = form.fields[0]
conv = field.conv
form.accept({'number':'123'})
self.assertEqual(conv._existing_value, {'number':123})
conv.field = None
self.assertEqual(conv._existing_value, {})