当前位置: 首页>>代码示例>>Python>>正文


Python app.AppEnvironment类代码示例

本文整理汇总了Python中iktomi.web.app.AppEnvironment的典型用法代码示例。如果您正苦于以下问题:Python AppEnvironment类的具体用法?Python AppEnvironment怎么用?Python AppEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AppEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_clean_value

    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)
开发者ID:mymikhail,项目名称:iktomi,代码行数:28,代码来源:fields.py

示例2: test_get_field

    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')
开发者ID:mymikhail,项目名称:iktomi,代码行数:33,代码来源:fields.py

示例3: test_fieldblock_readonly

 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, {})
开发者ID:Lehych,项目名称:iktomi,代码行数:25,代码来源:fields.py

示例4: test_get_initial

    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(), '')
开发者ID:SmartTeleMax,项目名称:iktomi,代码行数:7,代码来源:convs.py

示例5: test_accept

 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')
开发者ID:mymikhail,项目名称:iktomi,代码行数:8,代码来源:fields.py

示例6: test_id

 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')
开发者ID:mymikhail,项目名称:iktomi,代码行数:8,代码来源:fields.py

示例7: test_required

    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'])
开发者ID:mymikhail,项目名称:iktomi,代码行数:8,代码来源:convs.py

示例8: setUp

 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)
开发者ID:SmartTeleMax,项目名称:iktomi,代码行数:9,代码来源:files.py

示例9: test_mismatch

 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)
开发者ID:SmartTeleMax,项目名称:iktomi,代码行数:9,代码来源:fields.py

示例10: test_check_value_type

 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'])
开发者ID:mymikhail,项目名称:iktomi,代码行数:9,代码来源:fields.py

示例11: test_mismatch

    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'])
开发者ID:mymikhail,项目名称:iktomi,代码行数:9,代码来源:convs.py

示例12: test_accept_multiple

    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])
开发者ID:mymikhail,项目名称:iktomi,代码行数:10,代码来源:fields.py

示例13: test_prefix

 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')
开发者ID:SmartTeleMax,项目名称:iktomi,代码行数:10,代码来源:forms.py

示例14: test_get_perms

    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"))
开发者ID:SmartTeleMax,项目名称:iktomi,代码行数:10,代码来源:perms.py

示例15: test_field_block_existing_value

 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,  {})
开发者ID:SmartTeleMax,项目名称:iktomi,代码行数:11,代码来源:convs.py


注:本文中的iktomi.web.app.AppEnvironment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。