def test_add_collaborator(web_fixture, access_domain_fixture, access_ui_fixture): """A user may add other users as collaborators to his address book, specifying the privileges in the process.""" browser = access_ui_fixture.browser address_book = access_domain_fixture.address_book account = access_domain_fixture.account other_address_book = access_domain_fixture.other_address_book other_account = access_domain_fixture.other_account web_fixture.log_in(browser=browser, system_account=account) browser.open('/') assert address_book not in AddressBook.address_books_visible_to( other_account) assert not address_book.can_be_edited_by(other_account) assert not address_book.can_be_added_to_by(other_account) browser.click(XPath.link().with_text('Address book of [email protected]')) browser.click(XPath.link().with_text('Add collaborator')) browser.select(XPath.select_labelled('Choose collaborator'), '*****@*****.**') browser.click(XPath.input_labelled('May add new addresses')) browser.click(XPath.input_labelled('May edit existing addresses')) browser.click(XPath.button_labelled('Share')) assert access_ui_fixture.is_on_address_book_page_of('*****@*****.**') assert address_book in AddressBook.address_books_visible_to(other_account) assert address_book.can_be_edited_by(other_account) assert address_book.can_be_added_to_by(other_account)
def test_refresh_widget_with_expired_csrf_token(web_fixture, csrf_fixture): """An Ajax request done with a valid expired token, shows a validation exception. After refresh, a new token is received and submit works.""" fixture = csrf_fixture wsgi_app = web_fixture.new_wsgi_app(child_factory=fixture.MyForm.factory(), enable_js=True) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser wsgi_app.config.reahlsystem.debug = False #causes redirect to the error page and not stacktrace browser.open('/') select_widget_path = XPath.select_labelled('choice') assert browser.get_value(select_widget_path) == '1' wsgi_app.config.web.csrf_timeout_seconds = 0.5 time.sleep(wsgi_app.config.web.csrf_timeout_seconds + 0.1) browser.select(select_widget_path, '2', wait_for_ajax=False) wsgi_app.config.web.csrf_timeout_seconds = 300 with browser.alert_expected() as js_alert: assert js_alert.text == 'This page has expired. For security reasons, please review your input and retry.' js_alert.accept() #case: new csrftoken received in GET assert browser.get_value(select_widget_path) == '1' assert browser.wait_for_element_not_present( XPath.paragraph().with_text('Chosen: 2')) browser.select(select_widget_path, '2') assert browser.wait_for_element_present( XPath.paragraph().with_text('Chosen: 2')) assert browser.wait_for_not(browser.is_alert_present)
def test_submit_form_with_expired_csrf_token(web_fixture, csrf_fixture): """A form submitted with a valid expired token, shows a validation exception. After refresh, a new token is received and submit works.""" fixture = csrf_fixture wsgi_app = web_fixture.new_wsgi_app(child_factory=fixture.MyForm.factory(), enable_js=True) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') select_widget_path = XPath.select_labelled('choice') assert browser.get_value(select_widget_path) == '1' browser.select(select_widget_path, '2') wsgi_app.config.web.csrf_timeout_seconds = 0.5 time.sleep(wsgi_app.config.web.csrf_timeout_seconds + 0.1) browser.click(XPath.button_labelled('Submit')) wsgi_app.config.web.csrf_timeout_seconds = 300 error_message = XPath.paragraph().including_text( 'This page has expired. For security reasons, please review your input and retry.' ) assert browser.is_element_present(error_message) #case: submit again should work now - new csrftoken received in GET browser.click(XPath.button_labelled('Submit')) assert not browser.is_element_present(error_message)
def test_refreshing_chart_data_only(web_fixture): """You can update the chart without refreshing the whole Chart""" class MyForm(Form): def __init__(self, view): super().__init__(view, 'my_form') self.choice = 'one title' self.use_layout(FormLayout()) select = self.layout.add_input( SelectInput(self, self.fields.choice)) fig = go.Figure() fig.update_layout(title=self.choice) chart = self.add_child(Chart(view, fig, 'thechart')) select.set_refresh_widget(chart.contents) @exposed def fields(self, fields): fields.choice = ChoiceField([ Choice('one title', Field(label='One')), Choice('another title', Field(label='Two')) ], label='Choice') wsgi_app = web_fixture.new_wsgi_app(child_factory=MyForm.factory(), enable_js=True) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') assert browser.is_element_present(chart) with browser.refresh_expected_for('#thechart', False), \ browser.refresh_expected_for('#thechart-data', True): select_input = XPath.select_labelled('Choice') browser.select(select_input, 'Two')
def test_chartplotly2(web_fixture, plotly_scenario): fixture = plotly_scenario browser = web_fixture.driver_browser fixture.start_example_app() browser.open('/') with browser.refresh_expected_for('#thechart-data', True): select_input = XPath.select_labelled('factor') browser.select(select_input, '2')
def test_adding_chart_with_ajax(web_fixture): """If a page is first rendered without any Charts, and a Chart appears via refresh, the necessary library code is activated""" class MyForm(Form): def __init__(self, view): self.choice = 1 super().__init__(view, 'my_form') self.enable_refresh() self.use_layout(FormLayout()) self.layout.add_input( SelectInput(self, self.fields.choice, refresh_widget=self)) if self.choice == 2: self.add_child(Chart(view, go.Figure(), 'thechart')) @exposed def fields(self, fields): fields.choice = ChoiceField([ Choice(1, IntegerField(label='Hide chart')), Choice(2, IntegerField(label='Show chart')) ], label='Choice') wsgi_app = web_fixture.new_wsgi_app(child_factory=MyForm.factory(), enable_js=True) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') # Case: no chart assert not browser.is_element_present(chart) assert not browser.is_element_present(plotly_js) select_input = XPath.select_labelled('Choice') browser.select(select_input, 'Show chart') #Case: chart appears assert browser.is_element_present(chart) assert browser.is_element_present(plotly_js)