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)
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
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)
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
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)
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())
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)
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())
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
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__
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__
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'
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'
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__)
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__)
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__
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
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')
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
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')
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