def test_form_values_are_not_persisted_until_form_is_submitted(web_fixture, responsive_disclosure_fixture, sql_alchemy_fixture, query_string_fixture): """Values submitted via ajax are used only to redraw the screen; they are only changed on the underlying domain once the form is submitted.""" fixture = responsive_disclosure_fixture class ModelObject(Base): __tablename__ = 'test_responsive_disclosure_rollback' id = Column(Integer, primary_key=True) choice = Column(Integer, default=1) @exposed def fields(self, fields): fields.choice = ChoiceField([Choice(1, IntegerField(label='One')), Choice(2, IntegerField(label='Two')), Choice(3, IntegerField(label='Three'))], label='Choice') fixture.ModelObject = ModelObject class FormWithButton(fixture.MyForm): def __init__(self, view, an_object): super(FormWithButton, self).__init__(view, an_object) self.define_event_handler(self.events.submit) self.add_child(ButtonInput(self, self.events.submit)) @exposed def events(self, events): events.submit = Event(label='Submit') fixture.MyForm = FormWithButton with sql_alchemy_fixture.persistent_test_classes(ModelObject): fixture.model_object = ModelObject() Session.add(fixture.model_object) class MainWidgetWithPersistentModelObject(Widget): def __init__(self, view): super(MainWidgetWithPersistentModelObject, self).__init__(view) an_object = fixture.model_object self.add_child(fixture.MyForm(view, an_object)) wsgi_app = web_fixture.new_wsgi_app(enable_js=True, child_factory=MainWidgetWithPersistentModelObject.factory()) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') assert fixture.model_object.choice == 1 browser.click(XPath.option().with_text('Three')) assert browser.wait_for(query_string_fixture.is_state_now, 3) # The screen was updated, assert fixture.model_object.choice == 1 # but the database not. browser.click(XPath.button_labelled('Submit')) assert browser.wait_for(query_string_fixture.is_state_now, 3) assert fixture.model_object.choice == 3 # Now the database is updated too.
def test_the_form_is_blocked_while_the_widget_is_being_refreshed(web_fixture, blocking_refresh_fixture, query_string_fixture): """The form is blocked until the responsive widget has refreshed it contents.""" fixture = blocking_refresh_fixture wsgi_app = web_fixture.new_wsgi_app(enable_js=True, child_factory=fixture.MainWidget.factory()) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser fixture.should_pause_to_simulate_long_refresh = False browser.open('/') fixture.should_pause_to_simulate_long_refresh = True with web_fixture.reahl_server.in_background(wait_till_done_serving=False): browser.click(XPath.option().with_text('Three'), wait_for_ajax=False) assert fixture.is_form_blocked(browser) fixture.simulate_long_refresh_done() assert browser.wait_for(query_string_fixture.is_state_now, 3) assert not fixture.is_form_blocked(browser)
def select_input(self): self.input_type = SelectInput self.xpath_function_to_choice = XPath.option().with_text