示例#1
0
        def make_heading_with_sort_controls(column_number, column, view):
            heading_widget = Widget(view)
            if column.sort_key:
                heading = self.create_sorter_link(column_number, column.make_heading_widget(view))
            else:
                heading = column.make_heading_widget(view)
            heading_widget.add_child(heading)

            return heading_widget
示例#2
0
    def widget_adding_error(self, fixture):
        """Passing anything other than other Widgets to .add_child or add_children results in an error."""

        widget = Widget(fixture.view)

        with expected(IsInstance):
            widget.add_child(EmptyStub())

        with expected(IsInstance):
            widget.add_children([Widget(fixture.view), EmptyStub()])
示例#3
0
def test_security_sensitive(web_fixture):
    """A Widget is security sensitive if a read_check is specified for it; one of its
       children is security sensitive, or it was explixitly marked as security sensitive."""
    fixture = web_fixture

    widget = Widget(fixture.view)

    # Case: marked explicitly
    assert not widget.is_security_sensitive
    widget.set_as_security_sensitive()
    assert widget.is_security_sensitive

    # Case: derived from children
    parent_widget = Widget(fixture.view)
    parent_widget.add_child(widget)
    assert widget.is_security_sensitive

    # Case: derived from read rights
    def allow(self): return True
    widget_with_rights = Widget(fixture.view, read_check=allow)
    assert widget.is_security_sensitive
示例#4
0
class InputRenderingScenarios(Fixture):

    def new_form(self):
        return Form(self.web_fixture.view, 'some_form')

    def new_field(self):
        field = Field(default=3, readable=self.readable, writable=self.writable)
        field.bind('field_name', EmptyStub())
        return field

    def new_event(self):
        event = Event(readable=self.readable, writable=self.writable)
        event.bind('event_name', EmptyStub())
        self.form.define_event_handler(event)
        return event

    @scenario
    def normal_rendering(self):
        self.readable = Allowed(True)
        self.writable = Allowed(True)
        self.input_widget = TextInput(self.form, self.field)

        self.expected_html = '<input name="some_form-field_name" id="id-some_form-field_name" form="some_form" type="text" value="3" class="reahl-primitiveinput reahl-textinput">'

    @scenario
    def disabled_rendering(self):
        self.readable = Allowed(True)
        self.writable = Allowed(False)
        self.input_widget = TextInput(self.form, self.field)

        self.expected_html = '<input name="some_form-field_name" id="id-some_form-field_name" disabled="disabled" form="some_form" type="text" value="3" class="reahl-primitiveinput reahl-textinput">'

    @scenario
    def valueless_rendering(self):
        self.readable = Allowed(False)
        self.writable = Allowed(True)
        self.input_widget = TextInput(self.form, self.field)

        self.expected_html = '<input name="some_form-field_name" id="id-some_form-field_name" form="some_form" type="text" value="" class="reahl-primitiveinput reahl-textinput">'

    @scenario
    def empty_rendering(self):
        self.readable = Allowed(False)
        self.writable = Allowed(False)
        self.input_widget = TextInput(self.form, self.field)

        self.expected_html = ''

    @scenario
    def normal_button_rendering(self):
        self.readable = Allowed(True)
        self.writable = Allowed(True)
        self.input_widget = ButtonInput(self.form, self.event)

        self.expected_html = '<input name="event.some_form-event_name?" id="id-event-46-some_form-event_name-63-" form="some_form" type="submit" value="event_name" class="reahl-primitiveinput">'

    @scenario
    def greyed_button_rendering(self):
        self.readable = Allowed(True)
        self.writable = Allowed(False)
        self.input_widget = ButtonInput(self.form, self.event)

        self.expected_html = '<input name="event.some_form-event_name?" id="id-event-46-some_form-event_name-63-" disabled="disabled" form="some_form" type="submit" value="event_name" class="reahl-primitiveinput">'

    @scenario
    def buttons_must_be_readable_to_be_present(self):
        self.readable = Allowed(False)
        self.writable = Allowed(True)
        self.input_widget = ButtonInput(self.form, self.event)

        self.expected_html = ''

    @scenario
    def nothing_allowed_on_button(self):
        self.readable = Allowed(False)
        self.writable = Allowed(False)
        self.input_widget = ButtonInput(self.form, self.event)

        self.expected_html = ''

    def allowed(self):
        return True
    def disallowed(self):
        return False

    @scenario
    def not_readable_widget(self):
        self.input_widget = Widget(self.web_fixture.view, read_check=self.disallowed)
        self.input_widget.add_child(P(self.web_fixture.view, text='some text in a p'))

        self.expected_html = ''

    @scenario
    def readable_but_not_writable_widget(self):
        self.input_widget = Widget(self.web_fixture.view, read_check=self.allowed, write_check=self.disallowed)
        self.input_widget.add_child(P(self.web_fixture.view, text='some text in a p'))

        self.expected_html = '<p>some text in a p</p>'

    @scenario
    def readable_and_writable_widget(self):
        self.input_widget = Widget(self.web_fixture.view, read_check=self.allowed, write_check=self.allowed)
        self.input_widget.add_child(P(self.web_fixture.view, text='some text in a p'))

        self.expected_html = '<p>some text in a p</p>'

    @scenario
    def not_readable_but_writable_widget(self):
        # Think of password field, where the input's value is not readable by a human
        self.input_widget = Widget(self.web_fixture.view, read_check=self.disallowed, write_check=self.allowed)
        self.input_widget.add_child(P(self.web_fixture.view, text='some text in a p'))

        self.expected_html = ''