Esempio n. 1
0
 def test_formbase_with_field_widget_instance_no_id(self):
     class UserForm(FormBase):
         __entity__ = User
         user_name = Field(MyTextField())
     user_form = UserForm(session)
     widget = user_form.__widget__
     assert widget_is_type(widget_children(widget)['user_name'], MyTextField)
Esempio n. 2
0
    def test_validator_for_hidden_fields(self):
        class RegistrationForm(FormBase):
            __entity__ = Group
            __hide_fields__ = ['group_name']

        form = RegistrationForm(session)
        assert widget_children(form.__widget__)['group_name'].validator is not None
Esempio n. 3
0
    def test_require_field(self):
        class RegistrationForm(FormBase):
            __entity__ = User
            __require_fields__ = ['user_name']

        form = RegistrationForm(session)
        eq_(widget_children(form.__widget__)['user_name'].validator.not_empty, True)
Esempio n. 4
0
    def test_validator_for_hidden_fields(self):
        class RegistrationForm(FormBase):
            __entity__ = Group
            __hide_fields__ = ['group_name']

        form = RegistrationForm(session)
        assert widget_children(
            form.__widget__)['group_name'].validator is not None
Esempio n. 5
0
    def test_formbase_with_field_widget_instance_no_id(self):
        class UserForm(FormBase):
            __entity__ = User
            user_name = Field(MyTextField())

        user_form = UserForm(session)
        widget = user_form.__widget__
        assert widget_is_type(
            widget_children(widget)['user_name'], MyTextField)
Esempio n. 6
0
    def test_omit_fields(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __omit_fields__ = ['password']

        user_view = UserView()
        widget = user_view.__widget__
        assert 'password' not in list(widget_children(widget).keys())
Esempio n. 7
0
    def test_require_field(self):
        class RegistrationForm(FormBase):
            __entity__ = User
            __require_fields__ = ['user_name']

        form = RegistrationForm(session)
        eq_(
            widget_children(form.__widget__)['user_name'].validator.not_empty,
            True)
Esempio n. 8
0
    def test_bad_fieldname_in_limit(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __limit_fields__ = ['junk']

        user_view = UserView()
        widget = user_view.__widget__
        assert 'junk' not in list(widget_children(widget).keys())
Esempio n. 9
0
    def test_widget_attrs_hidden_field(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __field_widget_args__ = {'password':{'css_classes':['crazy_param']}}
            __hide_fields__ = ['password']

        user_view = UserView()
        widget = user_view.__widget__
        assert  widget_children(widget)['password'].css_classes == ['crazy_param'], widget.children['password'].css_classes
Esempio n. 10
0
    def test_bad_fieldname_in_limit(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __limit_fields__ = ['junk']


        user_view = UserView()
        widget = user_view.__widget__
        assert 'junk' not in  list(widget_children(widget).keys())
Esempio n. 11
0
    def test_omit_fields(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __omit_fields__ = ['password']


        user_view = UserView()
        widget = user_view.__widget__
        assert 'password' not in  list(widget_children(widget).keys())
Esempio n. 12
0
    def test_custom_field(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __field_widgets__ = {'password': TextField(id='password')}

        user_view = UserView()
        widget = user_view.__widget__
        child = widget_children(widget)['password']
        assert widget_is_type(child, TextField), child.__class__
Esempio n. 13
0
    def test_hidden_fields(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __hide_fields__ = ['password']

        user_view = UserView()
        widget = user_view.__widget__
        child = widget_children(widget)['password']
        assert widget_is_type(child, HiddenField), child.__class__
Esempio n. 14
0
    def test_widget_attrs(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __field_widget_args__ = {'password': {'test_param': 'crazy_param'}}
            password = DummyWidget

        user_view = UserView()
        widget = user_view.__widget__
        assert widget_children(widget)['password'].test_param == 'crazy_param'
Esempio n. 15
0
    def test_hidden_fields(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __hide_fields__ = ['password']

        user_view = UserView()
        widget = user_view.__widget__
        child = widget_children(widget)['password']
        assert widget_is_type(child, HiddenField), child.__class__
Esempio n. 16
0
    def test_widget_attrs(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __field_widget_args__ = {'password':{'test_param':'crazy_param'}}
            password = DummyWidget

        user_view = UserView()
        widget = user_view.__widget__
        assert  widget_children(widget)['password'].test_param == 'crazy_param'
Esempio n. 17
0
    def test_custom_with_none(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __add_fields__ = {'password': None}

        user_view = UserView()
        widget = user_view.__widget__
        child = widget_children(widget)['password']
        assert widget_is_type(child, Widget), str(child.__class__)
Esempio n. 18
0
    def test_custom_with_none(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __add_fields__ = {'password':None}


        user_view = UserView()
        widget = user_view.__widget__
        child = widget_children(widget)['password']
        assert widget_is_type(child, Widget), str(child.__class__)
Esempio n. 19
0
    def test_custom_field(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __field_widgets__ = {'password':TextField(id='password')}


        user_view = UserView()
        widget = user_view.__widget__
        child =  widget_children(widget)['password']
        assert widget_is_type(child, TextField), child.__class__
Esempio n. 20
0
 def test_formbase_with_field_widget_and_validator_instance(self):
     class UserForm(FormBase):
         __entity__ = User
         user_name = Field(MyTextField, OpenId)
     user_form = UserForm(session)
     widget = user_form.__widget__
     assert widget_is_type(widget_children(widget)['user_name'], MyTextField)
     try:
         widget.validate({'user_name':'something'})
     except Invalid as e:
         msg = form_error_message(e)
         assert '"something" is not a valid OpenId (it is neither an URL nor an XRI)' in msg, msg
Esempio n. 21
0
    def test_widget_with_attrs(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __field_attrs__ = {'password': {'class': 'mypassclass'}}
            __widget_selector_type__ = DummyWidgetSelector

        user_view = UserView()

        widget = user_view.__widget__
        child = widget_children(widget)['password']

        assert 'class' in child.attrs
        eq_(child.attrs['class'], 'mypassclass')
Esempio n. 22
0
    def test_formbase_with_field_widget_and_validator_instance(self):
        class UserForm(FormBase):
            __entity__ = User
            user_name = Field(MyTextField, OpenId)

        user_form = UserForm(session)
        widget = user_form.__widget__
        assert widget_is_type(
            widget_children(widget)['user_name'], MyTextField)
        try:
            widget.validate({'user_name': 'something', 'created': ''})
        except Invalid as e:
            msg = form_error_message(e)
            assert '"something" is not a valid OpenId (it is neither an URL nor an XRI)' in msg, msg
Esempio n. 23
0
    def test_widget_with_attrs(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __field_attrs__ = {'password':{'class':'mypassclass'}}
            __widget_selector_type__ = DummyWidgetSelector

        user_view = UserView()

        widget = user_view.__widget__
        child = widget_children(widget)['password']

        assert 'class' in child.attrs
        eq_(child.attrs['class'], 'mypassclass')
Esempio n. 24
0
    def test_widget_attrs_hidden_field(self):
        class UserView(ViewBase):
            __entity__ = User
            __metadata_type__ = DummyMetadata
            __field_widget_args__ = {
                'password': {
                    'css_classes': ['crazy_param']
                }
            }
            __hide_fields__ = ['password']

        user_view = UserView()
        widget = user_view.__widget__
        assert widget_children(widget)['password'].css_classes == [
            'crazy_param'
        ], widget.children['password'].css_classes