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'
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
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)
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))
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)
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)
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))
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)
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)
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)
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)
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))
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())
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)
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')))
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')
def events(self, events): events.submit = Event(label='Submit', action=Action(self.submit))
def events(self, events): events.submit = Event(label='Submit')
def events(self, events): events.an_event = Event(label='click me', writable=Allowed(False), disallowed_message='you cannot do this')
def events(self, events): events.an_event = Event(label='Click me')
def events(self, events): events.an_event = Event(label='click me', action=Action(self.handle_event))
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
def events(self, events): events.an_event = Event( label='click me', action=Action(self.handle_event, ['some_argument']), some_argument=Field(default='default value'))
def events(self, events): events.save = Event(label='Save', action=Action(self.save)) events.update = Event(label='Update')
def events(self, events): events.outer_event = Event(label='click outer', action=Action(self.handle_event))
def events(self, events): events.nested_event = Event(label='click nested', action=Action(self.handle_event))
def events(self, events): events.an_event = Event()
def events(self, events): events.submit = Event(label='Submit') events.submit_break = Event(label='Submit break', action=Action(self.always_break))
def events(self, events): events.an_event = Event(label='Click me', argument=Field(required=True))