示例#1
0
def test_button_layouts(web_fixture):
    """A ButtonLayout can be be used on a Button to customise various visual effects."""

    event = Event(label='click me')
    event.bind('event', web_fixture)
    form = Form(web_fixture.view, 'test')
    form.define_event_handler(event)

    # Case: the defaults
    button = Button(form, event).use_layout(ButtonLayout())

    tester = WidgetTester(button)
    [button] = tester.xpath(XPath.button_labelled('click me'))
    assert button.attrib['class'] == 'btn reahl-primitiveinput'

    # Case: possible effects
    form = Form(web_fixture.view, 'test')
    form.define_event_handler(event)
    button = Button(form, event).use_layout(
        ButtonLayout(style='secondary', size='sm', active=True, wide=True))

    tester = WidgetTester(button)
    [button] = tester.xpath(XPath.button_labelled('click me'))
    assert button.attrib[
        'class'] == 'active btn btn-block btn-secondary btn-sm reahl-primitiveinput'
示例#2
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
示例#3
0
def test_arguments_to_event(fixture):
    """Only Action objects can be sent as action= when creating an Event. The arguments passed to readable and writable
       should be callable objects with correct signature."""

    # action=
    with expected(IsInstance):
        Event(action=EmptyStub())

    def check_exc(expected_message, ex):
        message = str(ex).split(':')[1][1:]
        assert message.startswith(expected_message)

        # readable/writable are callable

    with expected(IsCallable,
                  test=functools.partial(
                      check_exc, 'readable should be a callable object')):
        Event(readable=EmptyStub())
    with expected(IsCallable,
                  test=functools.partial(
                      check_exc, 'writable should be a callable object')):
        Event(writable=EmptyStub())

    # readable/writable have correct signature
    def do_nothing(a, b, c, d):
        pass

    with expected(IncorrectArgumentError):
        Event(readable=do_nothing)
    with expected(IncorrectArgumentError):
        Event(writable=do_nothing)
示例#4
0
文件: files.py 项目: xmonader/reahl
 def events(self, events):
     events.upload_file = Event(label=_('Upload'),
                                action=Action(self.upload_file))
     events.remove_file = Event(label=_('Remove'),
                                action=Action(self.remove_file,
                                              ['filename']),
                                filename=Field(required=True))
示例#5
0
 def assemble(self):
     event = Event(label='Click me', action=Action(do_something))
     event.bind('anevent', None)
     slot_definitions = {'main': FormWithButton.factory(event)}
     viewa = self.define_view('/viewa',
                              title='View a',
                              slot_definitions=slot_definitions)
     self.define_local_transition(event, viewa, guard=guard)
示例#6
0
 def assemble(self):
     event = Event(label='Click me', action=Action(do_something))
     event.bind('anevent', None)
     viewa = self.define_view('/viewa', title='View a')
     viewa.set_slot('main', FormWithButton.factory(event))
     viewb = self.define_view('/viewb', title='View b')
     viewb.set_slot('main', FormWithButton.factory(event))
     self.define_transition(event, viewa, viewb)
示例#7
0
def test_event_security_action_and_rw():
    """Supply either an action or a readable/writable to an Event, but not both."""
    def do_nothing():
        pass

    with expected(ProgrammerError):
        Event(action=Action(do_nothing), readable=Action(do_nothing))
    with expected(ProgrammerError):
        Event(action=Action(do_nothing), writable=Action(do_nothing))
示例#8
0
 def assemble(self):
     event = Event(label='Click me')
     event.bind('anevent', None)
     viewa = self.define_view('/viewa', title='View a')
     viewa.set_slot('main', FormWithButton.factory(event))
     viewb = self.define_view('/viewb', title='View b')
     viewc = self.define_view('/viewc', title='View c')
     self.define_transition(event, viewa, viewb, guard=false_guard)
     self.define_transition(event, viewa, viewc, guard=adjustable_guard)
示例#9
0
        def assemble(self):
            event = Event(label='Click me')
            event.bind('anevent', None)

            step1 = self.define_view('/firstStepOfDetour', title='Step 1', detour=True)
            step1.set_slot('main', FormWithButton.factory(event))
            step2 = self.define_view('/lastStepOfDetour', title='Step 2')
            step2.set_slot('main', FormWithButton.factory(event))

            self.define_transition(event, step1, step2)
            self.define_return_transition(event, step2)
示例#10
0
        def assemble(self):
            event = Event(label='Click me')
            event.bind('anevent', None)
            viewa = self.define_view('/viewa', title='View a')
            explicit_return_view = self.define_view('/explicitReturnView', title='Explicit Return View')

            detour = self.define_view('/detour', title='Detour')
            detour.set_slot('main', FormWithButton.factory(event))

            viewa.add_precondition(ViewPreCondition(lambda: False, exception=Detour(detour.as_bookmark(self), return_to=explicit_return_view.as_bookmark(self))))
            self.define_return_transition(event, detour)
示例#11
0
        def assemble(self):
            event = Event(label='Click me')
            event.bind('anevent', None)
            viewa = self.define_view('/viewa', title='View a')

            step1 = self.define_view('/firstStepOfDetour', title='Step 1')
            step1.set_slot('main', FormWithButton.factory(event))
            step2 = self.define_view('/lastStepOfDetour', title='Step 2')
            step2.set_slot('main', FormWithButton.factory(event))

            viewa.add_precondition(ViewPreCondition(lambda: fixture.make_precondition_pass, exception=Detour(step1.as_bookmark(self))))
            self.define_transition(event, step1, step2)
            self.define_return_transition(event, step2)
示例#12
0
 def events(self, events):
     events.verify_event = Event(label=_('Verify'), action=Action(self.verify_email))
     events.register_event = Event(label=_('Register'), action=Action(self.register))
     events.change_email_event = Event(label=_('Change email address'), action=Action(self.request_email_change))
     events.investigate_event = Event(label=_('Investigate'))
     events.choose_password_event = Event(label=_('Set new password'), action=Action(self.choose_new_password))
     events.reset_password_event = Event(label=_('Reset password'), action=Action(self.request_password_reset))
     events.login_event = Event(label=_('Log in'), action=Action(self.log_in))
     events.resend_event = Event(label=_('Send'), action=Action(self.send_activation_notification))
     events.log_out_event = Event(label=_('Log out'), action=Action(self.log_out))
示例#13
0
 def events(self, events):
     events.take_task = Event(label=_('Take'), 
                              action=Action(Task.reserve_for, ['task', 'party']),
                              task=PersistedField(Task, required=True),
                              party=CurrentUser())
     events.defer_task = Event(label=_('Defer'))
     events.go_to_task = Event(label=_('Go to'),
                               task=PersistedField(Task, required=True),
                               party=CurrentUser(),
                               readable=Action(Task.is_reserved_for, ['task', 'party']))
     events.release_task = Event(label=_('Release'),
                                 action=Action(Task.release, ['task']),
                                 task=PersistedField(Task, required=True),
                                 party=CurrentUser())
示例#14
0
            def assemble(self):
                event = Event(label='Click me')
                event.bind('anevent', None)
                slot_with_button = {'main': FormWithButton.factory(event)}

                step1 = self.define_view('/firstStepOfDetour',
                                         title='Step 1',
                                         slot_definitions=slot_with_button,
                                         detour=True)
                step2 = self.define_view('/lastStepOfDetour',
                                         title='Step 2',
                                         slot_definitions=slot_with_button)

                self.define_transition(event, step1, step2)
                self.define_return_transition(event, step2)
示例#15
0
 def events(self, events):
     events.an_event = Event(one_argument=IntegerField(required=True),
                             another_argument=IntegerField(),
                             unused_argument=IntegerField(),
                             action=Action(
                                 self.do_something, ['one_argument'],
                                 dict(a_kwarg='another_argument')))
示例#16
0
 def events(self, events):
     events.an_event = Event(
         label='click me',
         action=Action(self.handle_event,
                       ['one_argument', 'another_argument']),
         one_argument=IntegerField(),
         another_argument=Field())
 def events(self, events):
     events.save = Event(label='Perform Tr')
示例#18
0
 def events(self, events):
     events.submit = Event(label='Submit',
                           action=Action(self.submit))
示例#19
0
 def events(self, events):
     events.submit = Event(label='Submit')
示例#20
0
 def events(self, events):
     events.an_event = Event(label='click me', writable=Allowed(False),
                             disallowed_message='you cannot do this')
示例#21
0
 def events(self, events):
     events.an_event = Event(label='Click me')
示例#22
0
 def events(self, events):
     events.an_event = Event(label='click me',
                             action=Action(self.handle_event))
示例#23
0
 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
示例#24
0
 def events(self, events):
     events.an_event = Event(
         label='click me',
         action=Action(self.handle_event, ['some_argument']),
         some_argument=Field(default='default value'))
示例#25
0
 def events(self, events):
     events.save = Event(label='Save', action=Action(self.save))
     events.update = Event(label='Update')
示例#26
0
 def events(self, events):
     events.outer_event = Event(label='click outer',
                                action=Action(self.handle_event))
示例#27
0
 def events(self, events):
     events.nested_event = Event(label='click nested',
                                 action=Action(self.handle_event))
示例#28
0
 def events(self, events):
     events.an_event = Event()
示例#29
0
 def events(self, events):
     events.submit = Event(label='Submit')
     events.submit_break = Event(label='Submit break',
                                 action=Action(self.always_break))
示例#30
0
 def events(self, events):
     events.an_event = Event(label='Click me',
                             argument=Field(required=True))