コード例 #1
0
ファイル: test_eventhandling.py プロジェクト: diopib/reahl
 def assemble(self):
     self.define_page(HTML5Page).use_layout(
         PageLayout(contents_layout=ColumnLayout(
             'main', 'secondary').with_slots()))
     home = self.define_view('/', title='Home page')
     home.set_slot('main', Form.factory('myform'))
     home.set_slot('secondary', Form.factory('myform'))
コード例 #2
0
ファイル: test_files.py プロジェクト: diopib/reahl
    def form_encoding(self, fixture):
        """The enctype of a Form changes to multipart/form-data if it contains an input for a file."""
        class DomainObject(object):
            @exposed
            def fields(self, fields):
                fields.file = FileField(allow_multiple=False, label='Attached files')

        domain_object = DomainObject()

        form = Form(fixture.view, 'testform')
        vassert( 'enctype' not in form.attributes.v )
        
        form.add_child(SimpleFileInput(form, domain_object.fields.file))
        vassert( form.attributes.v['enctype'] == 'multipart/form-data' )
コード例 #3
0
 def __init__(self, view):
     super(TestPanel, self).__init__(view)
     form = self.add_child(Form(view, 'some_form'))
     form.define_event_handler(model_object.events.an_event)
     form.add_child(ButtonInput(form, model_object.events.an_event))
     form.add_child(TextInput(form, model_object.fields.field_name))
     fixture.form = form
コード例 #4
0
def test_rendering_of_form(web_fixture):
    """A Form is always set up to POST to its EventChannel url.  The current page's query string is
       propagated with the POST url if any.  The Form has an id and class to help style it etc."""

    fixture = web_fixture

    form = Form(fixture.view, 'test_channel')
    tester = WidgetTester(form)

    fixture.context.request = Request.blank('/a/b?x=y', charset='utf8')
    actual = tester.render_html()

    expected = '''<form id="test_channel" action="/a/b/_test_channel_method?x=y" data-formatter="/__test_channel_format_method" method="POST" class="reahl-form">''' \
               '''<div id="test_channel_hashes">'''\
               '''<input name="test_channel-_reahl_client_concurrency_digest" id="id-test_channel-_reahl_client_concurrency_digest" form="test_channel" type="hidden" value="" class="reahl-primitiveinput">''' \
               '''<input name="test_channel-_reahl_database_concurrency_digest" id="id-test_channel-_reahl_database_concurrency_digest" form="test_channel" type="hidden" value="" class="reahl-primitiveinput">''' \
               '''</div>''' \
               '''</form>'''
    assert actual == expected

    # Case: without querystring
    fixture.context.request = Request.blank('/a/b', charset='utf8')
    actual = tester.render_html_tree()

    action = actual.xpath('//form')[0].attrib['action']
    assert action == '/a/b/_test_channel_method'
コード例 #5
0
 def assemble(self):
     self.define_page(HTML5Page).use_layout(BasicPageLayout())
     view = self.define_view('/', title='Hello')
     view.set_slot('main', Form.factory('the_form'))
     failing_precondition = ViewPreCondition(lambda: False, exception=SomeException)
     passing_precondition = ViewPreCondition(lambda: True)
     view.add_precondition(passing_precondition)
     view.add_precondition(failing_precondition)
コード例 #6
0
ファイル: test_security.py プロジェクト: craig-reahl/reahl
 def __init__(self, view):
     super().__init__(view)
     form = self.add_child(Form(view, 'some_form'))
     form.define_event_handler(model_object.events.an_event)
     button = form.add_child(ButtonInput(form, model_object.events.an_event))
     if button.validation_error:
         form.add_child(form.create_error_label(button))
     fixture.form = form
コード例 #7
0
    def tailored_access_make_inputs_security_sensitive(self, fixture):
        """An Input is sensitive if explicitly set as sensitive, or if its Fields has non-defaulted
           mechanisms for determiing access rights."""

        form = Form(fixture.view, 'some_form')
        field = Field(default=3, readable=Allowed(True))
        field.bind('field_name', EmptyStub())
        input_widget = TextInput(form, field)

        vassert(input_widget.is_security_sensitive)
コード例 #8
0
ファイル: test_eventhandling.py プロジェクト: diopib/reahl
def validation_of_event_arguments(fixture):
    """Buttons cannot be created for Events with invalid default arguments."""
    class ModelObject(object):
        @exposed
        def events(self, events):
            events.an_event = Event(label='Click me',
                                    argument=Field(required=True))

    model_object = ModelObject()

    form = Form(fixture.view, 'test')
    form.define_event_handler(model_object.events.an_event)

    with expected(ProgrammerError):
        ButtonInput(form, model_object.events.an_event)

    with expected(NoException):
        ButtonInput(
            form,
            model_object.events.an_event.with_arguments(argument='something'))
コード例 #9
0
 def new_form(self):
     form = Form(self.web_fixture.view, 'some_form')
     event = Event(label='click me', action=Action(self.action))
     event.bind('an_event', None)
     form.define_event_handler(event, target=self.target)
     form.add_child(ButtonInput(form, event))
     return form
コード例 #10
0
 def assemble(self):
     self.define_page(HTML5Page).use_layout(
         PageLayout(
             contents_layout=ColumnLayout('main').with_slots()))
     slot_definitions = {'main': Form.factory('the_form')}
     view = self.define_view('/',
                             title='Hello',
                             slot_definitions=slot_definitions)
     failing_precondition = ViewPreCondition(
         lambda: False, exception=SomeException)
     passing_precondition = ViewPreCondition(lambda: True)
     view.add_precondition(passing_precondition)
     view.add_precondition(failing_precondition)
コード例 #11
0
ファイル: test_input.py プロジェクト: dli7428/reahl
def test_checkbox_select_input_allowed_fields(web_fixture):
    """A CheckboxSelectInput can only be used with a MultiChoiceField."""

    model_object = web_fixture
    form = Form(web_fixture.view, 'test')

    choice_field = ChoiceField([])
    choice_field.bind('an_attribute', model_object)

    with expected(ProgrammerError, test='<class \'reahl.component.modelinterface.ChoiceField\'> is not allowed to be used with <class \'reahl.web.ui.CheckboxSelectInput\'>'):
        CheckboxSelectInput(form, choice_field)

    multi_choice_field = MultiChoiceField([])
    multi_choice_field.bind('another_attribute', model_object)

    with expected(NoException):
        CheckboxSelectInput(form, multi_choice_field)
コード例 #12
0
ファイル: test_input.py プロジェクト: dli7428/reahl
def test_checkbox_input_restricted_to_use_with_boolean(web_fixture):
    """CheckboxInput is for toggling a true or false answer."""
    model_object = web_fixture
    form = Form(web_fixture.view, 'test')

    # case: with BooleanField
    boolean_field = BooleanField(label='Boolean')
    boolean_field.bind('a_choice', model_object)
    with expected(NoException):
        CheckboxInput(form, boolean_field)

    # case: with disallowed field
    not_a_boolean_field = IntegerField(label='Other')
    not_a_boolean_field.bind('not_a_boolean', model_object)

    with expected(IsInstance):
        CheckboxInput(form, not_a_boolean_field)
コード例 #13
0
ファイル: test_eventhandling.py プロジェクト: diopib/reahl
def rendering_of_form(fixture):
    """A Form is always set up to POST to its EventChannel url.  The current page's query string is
       propagated with the POST url if any.  The Form has an id and class to help style it etc."""

    form = Form(fixture.view, 'test_channel')
    tester = WidgetTester(form)

    fixture.context.set_request(Request.blank('/a/b?x=y', charset='utf8'))
    actual = tester.render_html()

    expected = '<form id="test_channel" action="/a/b/_test_channel_method?x=y" data-formatter="/__test_channel_format_method" method="POST" class="reahl-form"></form>'
    vassert(actual == expected)

    # Case: without querystring
    fixture.context.set_request(Request.blank('/a/b', charset='utf8'))
    actual = tester.render_html_tree()

    action = actual.xpath('//form')[0].attrib['action']
    vassert(action == '/a/b/_test_channel_method')
コード例 #14
0
ファイル: test_security.py プロジェクト: craig-reahl/reahl
 def new_form(self):
     return Form(self.web_fixture.view, 'some_form')
コード例 #15
0
 def __init__(self, view):
     super(MyPanel, self).__init__(view)
     model_object = ModelObject()
     forgotten_form = Form(view, 'myform')
     self.add_child(TextInput(forgotten_form, model_object.fields.name))
コード例 #16
0
 def assemble(self):
     self.define_page(HTML5Page).use_layout(
         BasicPageLayout(slots=['main', 'secondary']))
     home = self.define_view('/', title='Home page')
     home.set_slot('main', Form.factory('myform'))
     home.set_slot('secondary', Form.factory('myform'))
コード例 #17
0
ファイル: test_input.py プロジェクト: diopib/reahl
 def new_form(self):
     return Form(self.view, 'test')
コード例 #18
0
 def new_form(self):
     return Form(self.view, 'some_form')
コード例 #19
0
ファイル: test_input.py プロジェクト: dli7428/reahl
 def new_form(self):
     return Form(self.web_fixture.view, 'test')