def test_clear_form_inputs_on_optimistic_concurrency(web_fixture, sql_alchemy_fixture, concurrency_fixture, scenario): """A concurrency error is detected upon submit after an exception. When a user resets inputs upon such a concurrency error, previous form exceptions and input data are cleared. """ fixture = concurrency_fixture with sql_alchemy_fixture.persistent_test_classes(fixture.ModelObject): Session.add(fixture.model_object) wsgi_app = web_fixture.new_wsgi_app( child_factory=fixture.MyForm.factory()) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') # Concurrency error is detected on submit after an exception scenario.cause_exception_on_submit(browser) assert fixture.is_any_error_displayed() assert not fixture.is_concurrency_error_displayed() fixture.make_concurrent_change_in_backend() browser.type(XPath.input_labelled('Some field'), 'valid input') browser.click(XPath.button_labelled('Submit')) assert fixture.is_concurrency_error_displayed() # Previous error and inputs are cleared browser.click(XPath.button_labelled('Reset input')) assert browser.get_value( XPath.input_labelled('Some field')) == 'changed by someone else' assert not fixture.is_any_error_displayed()
def test_async_validation(web_fixture, per_file_constrained_file_upload_input_fixture): """Validations are checked in JavaScript before uploading. """ # Only tested for the FileUploadInput, as it uses the FileInput # in its own implementation, in a NestedForm, and has to pass on the # filesize constraint all the way. This way, we test all of that. fixture = per_file_constrained_file_upload_input_fixture web_fixture.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True)) browser = web_fixture.driver_browser browser.open('/') assert not fixture.uploaded_file_is_listed(fixture.valid_file.name) assert not fixture.uploaded_file_is_listed(fixture.invalid_file.name) browser.type(XPath.input_labelled('Choose file(s)'), fixture.invalid_file.name) assert not fixture.uploaded_file_is_listed(fixture.invalid_file.name) assert browser.is_element_present(XPath.span().including_text( fixture.validation_error_message)) browser.type(XPath.input_labelled('Choose file(s)'), fixture.valid_file.name) assert fixture.uploaded_file_is_listed(fixture.valid_file.name)
def test_required_constraint_js(web_fixture, constraint_rendering_fixture): fixture = constraint_rendering_fixture constraint = RequiredConstraint() class MyForm(Form): def __init__(self, view, name): super().__init__(view, name) self.use_layout(FormLayout()) field = fixture.model_object.fields.an_attribute.with_validation_constraint( constraint) self.layout.add_input(TextInput(self, field)) wsgi_app = web_fixture.new_wsgi_app(child_factory=MyForm.factory('myform'), enable_js=True) web_fixture.reahl_server.set_app(wsgi_app) web_fixture.driver_browser.open('/') web_fixture.driver_browser.type(XPath.input_labelled('an attribute'), 'something', trigger_blur=False, wait_for_ajax=False) web_fixture.driver_browser.press_tab() web_fixture.driver_browser.wait_for_element_not_visible( fixture.error_xpath) web_fixture.driver_browser.type(XPath.input_labelled('an attribute'), '') web_fixture.driver_browser.press_keys( web_fixture.driver_browser.Keys.BACK_SPACE, locator=XPath.input_labelled( 'an attribute')) # To trigger validation on the field web_fixture.driver_browser.wait_for_element_visible(fixture.error_xpath)
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_marshalling_of_radio_button_select_input(web_fixture, input_fixture, field_scenario): """When a form is submitted, the value of the selected radio button is persisted.""" fixture = input_fixture choices = [Choice(1, IntegerField(label='One')), Choice(2, IntegerField(label='Two'))] fixture.field = field_scenario.field_class(choices) model_object = fixture.model_object model_object.an_attribute = field_scenario.default_domain_value wsgi_app = web_fixture.new_wsgi_app(child_factory=fixture.new_Form(input_widget_class=RadioButtonSelectInput).factory('myform')) web_fixture.reahl_server.set_app(wsgi_app) web_fixture.driver_browser.open('/') radio_one = XPath.input_labelled('One') radio_two = XPath.input_labelled('Two') # One is pre selected assert web_fixture.driver_browser.is_selected(radio_one) assert not web_fixture.driver_browser.is_selected(radio_two) # click on Two web_fixture.driver_browser.click(radio_two) assert not web_fixture.driver_browser.is_selected(radio_one) web_fixture.driver_browser.click(XPath.button_labelled('click me')) assert model_object.an_attribute == field_scenario.selected_domain_value
def test_verify_from_menu(web_fixture, party_account_fixture, accounts_web_fixture): fixture = accounts_web_fixture account = party_account_fixture.new_system_account(activated=False) activation_request = VerifyEmailRequest( email=account.email, subject_config='accounts.activation_subject', email_config='accounts.activation_email') Session.add(activation_request) deferred_activation = ActivateAccount(system_account=account, requirements=[activation_request]) Session.add(deferred_activation) secret_key = activation_request.as_secret_key() assert not account.status.is_active() fixture.browser.open('/a_ui/verify') fixture.browser.type(XPath.input_labelled('Email'), account.email) fixture.browser.type(XPath.input_labelled('Secret key'), secret_key) fixture.browser.type(XPath.input_labelled('Password'), account.password) fixture.browser.click(XPath.button_labelled('Verify')) assert fixture.browser.current_url.path == '/a_ui/thanks' assert account.status.is_active()
def test_file_upload_input_list_files(web_fixture, file_upload_input_fixture): """The FileUploadInput displays a list of files that were uploaded so far.""" fixture = file_upload_input_fixture web_fixture.reahl_server.set_app(fixture.wsgi_app) browser = web_fixture.driver_browser browser.open('/') # Upload one file browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) browser.click(XPath.button_labelled('Upload')) assert fixture.uploaded_file_is_listed(fixture.file_to_upload1.name) assert not fixture.uploaded_file_is_listed(fixture.file_to_upload2.name) # Upload a second file browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload2.name) browser.click(XPath.button_labelled('Upload')) assert fixture.uploaded_file_is_listed(fixture.file_to_upload1.name) assert fixture.uploaded_file_is_listed(fixture.file_to_upload2.name)
def test_prevent_duplicate_upload_js(web_fixture, file_upload_input_fixture): """The user is prevented from uploading more than one file with the same name on the client side. """ fixture = file_upload_input_fixture web_fixture.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True)) browser = web_fixture.driver_browser error_locator = XPath.span().including_text( 'uploaded files should all have different names') def error_is_visible(): return browser.is_visible(error_locator) browser.open('/') browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) browser.wait_for_not(error_is_visible) browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload2.name) browser.wait_for_not(error_is_visible) with web_fixture.reahl_server.paused(): browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) assert not fixture.upload_file_is_queued(fixture.file_to_upload1.name) browser.wait_for(error_is_visible) browser.click( XPath.button_labelled('Remove', filename=fixture.file_to_upload2_name)) browser.wait_for_not(error_is_visible)
def test_file_upload_input_remove_files(web_fixture, file_upload_input_fixture): """A user can remove files that were uploaded but not yet submitted.""" fixture = file_upload_input_fixture web_fixture.reahl_server.set_app(fixture.wsgi_app) browser = web_fixture.driver_browser browser.open('/') # Upload two files browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) browser.click(XPath.button_labelled('Upload')) browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload2.name) browser.click(XPath.button_labelled('Upload')) # Remove file1 browser.click( XPath.button_labelled('Remove', filename=fixture.file_to_upload1_name)) assert not fixture.uploaded_file_is_listed(fixture.file_to_upload1.name) assert fixture.uploaded_file_is_listed(fixture.file_to_upload2.name) # Only the one file is submitted browser.click(XPath.button_labelled('Submit')) assert list(fixture.domain_object.submitted_file_info.keys()) == [ fixture.file_to_upload2_name ]
def test_input_validation_cues(sql_alchemy_fixture, validation_scenarios): """Visible cues are inserted to indicate the current validation state and possible validation error messages to a user. """ fixture = validation_scenarios browser = fixture.browser with sql_alchemy_fixture.persistent_test_classes(fixture.ModelObject): fixture.domain_object = fixture.ModelObject() Session.add(fixture.domain_object) browser.open('/') assert not fixture.get_form_group_highlight_marks(browser, index=0) assert not fixture.get_form_group_errors(browser, index=0) browser.type(XPath.input_labelled('Some input'), '') browser.click(XPath.button_labelled('Submit')) assert ['is-invalid' ] == fixture.get_form_group_highlight_marks(browser, index=0) [error] = fixture.get_form_group_errors(browser, index=0) assert error.text == 'Some input is required' browser.type(XPath.input_labelled('Some input'), 'valid value') browser.click(XPath.button_labelled('Submit')) assert ['is-valid'] == fixture.get_form_group_highlight_marks(browser, index=0) assert not fixture.get_form_group_errors(browser, index=0) browser.type(XPath.input_labelled('Another input'), 'valid value') browser.click(XPath.button_labelled('Submit')) assert not fixture.get_form_group_highlight_marks(browser, index=0) assert not fixture.get_form_group_errors(browser, index=0)
def test_queueing_async_uploads(web_fixture, large_file_upload_input_fixture): """Asynchronous uploads do not happen concurrently, they are queued one after another. """ fixture = large_file_upload_input_fixture fixture.run_hook_after = True web_fixture.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True)) browser = web_fixture.driver_browser browser.open('/') assert not fixture.file_was_uploaded(fixture.file_to_upload1.name) assert not fixture.uploaded_file_is_listed(fixture.file_to_upload1.name) with web_fixture.reahl_server.in_background(wait_till_done_serving=False): browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name, wait_for_ajax=False) # Upload will block, see fixture browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload2.name, wait_for_ajax=False) # Upload will block, see fixture progress1 = browser.get_attribute('//ul/li[1]/progress', 'value') assert progress1 == '100' progress2 = browser.get_attribute('//ul/li[2]/progress', 'value') assert progress2 == '0' fixture.simulate_large_file_upload_done() browser.wait_for(fixture.uploaded_file_is_listed, fixture.file_to_upload2.name) assert fixture.uploaded_file_is_listed(fixture.file_to_upload1.name) assert fixture.uploaded_file_is_listed(fixture.file_to_upload2.name) assert fixture.file_was_uploaded(fixture.file_to_upload1.name) assert fixture.file_was_uploaded(fixture.file_to_upload2.name)
def test_edit_and_add_own(web_fixture, access_domain_fixture, access_ui_fixture): """The owner of an AddressBook can add and edit Addresses to the owned AddressBook.""" browser = access_ui_fixture.browser fixture = access_domain_fixture account = fixture.account address_book = fixture.address_book web_fixture.log_in(browser=browser, system_account=account) browser.open('/') browser.click(XPath.link().with_text('Address book of [email protected]')) # add browser.click(XPath.link().with_text('Add address')) browser.type(XPath.input_labelled('Name'), 'Someone') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.click(XPath.button_labelled('Save')) assert browser.is_element_present( XPath.paragraph().including_text('Someone: [email protected]')) # edit browser.click(XPath.button_labelled('Edit')) browser.type(XPath.input_labelled('Name'), 'Else') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.click(XPath.button_labelled('Update')) assert browser.is_element_present( XPath.paragraph().including_text('Else: [email protected]'))
def test_addressbook2(web_fixture, addressbook2_scenario): browser = Browser(addressbook2_scenario.wsgi_app) browser.open('/') browser.type(XPath.input_labelled('Name'), 'John') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.click(XPath.button_labelled('Save')) assert browser.is_element_present(XPath.paragraph().including_text('John: [email protected]'))
def test_addressbook2bootstrap(web_fixture, addressbook2bootstrap_scenario): fixture = addressbook2bootstrap_scenario fixture.start_example_app() web_fixture.driver_browser.open('/') web_fixture.driver_browser.set_window_size('xs') web_fixture.driver_browser.type(XPath.input_labelled('Name'), 'John') web_fixture.driver_browser.type(XPath.input_labelled('Email'), '*****@*****.**') web_fixture.driver_browser.capture_cropped_screenshot(fixture.new_screenshot_path('bootstrapform.png'))
def test_marshalling_of_checkbox_select_input(web_fixture, checkbox_fixture): """CheckboxSelectInput is used to choose many things from a list.""" fixture = checkbox_fixture choices = [Choice(1, IntegerField(label='One')), Choice(2, IntegerField(label='Two')), Choice(3, IntegerField(label='Three'))] fixture.field = MultiChoiceField(choices) model_object = fixture.model_object model_object.an_attribute = [1] wsgi_app = web_fixture.new_wsgi_app(child_factory=fixture.new_Form(input_widget_class=CheckboxSelectInput).factory('myform')) web_fixture.reahl_server.set_app(wsgi_app) web_fixture.driver_browser.open('/') assert web_fixture.driver_browser.is_selected(XPath.input_labelled('One')) assert not web_fixture.driver_browser.is_selected(XPath.input_labelled('Two')) assert not web_fixture.driver_browser.is_selected(XPath.input_labelled('Three')) # Case: checkbox is submitted with form (ie checked) web_fixture.driver_browser.set_deselected(XPath.input_labelled('One')) web_fixture.driver_browser.set_selected(XPath.input_labelled('Two')) web_fixture.driver_browser.set_selected(XPath.input_labelled('Three')) web_fixture.driver_browser.click(XPath.button_labelled('click me')) assert model_object.an_attribute == [2, 3] assert fixture.checkbox.value == '2,3' assert not web_fixture.driver_browser.is_selected(XPath.input_labelled('One')) assert web_fixture.driver_browser.is_selected(XPath.input_labelled('Two')) assert web_fixture.driver_browser.is_selected(XPath.input_labelled('Three'))
def test_add_address(web_fixture, jobs_fixture): """A user can add an address, after which the address is listed.""" browser = jobs_fixture.browser browser.open('/') browser.type(XPath.input_labelled('Name'), 'John') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.click(XPath.button_labelled('Save')) assert jobs_fixture.address_is_listed_as('John', '*****@*****.**', True)
def test_alert_for_domain_exception(web_fixture): """FormLayout can be used to add an Alert with error messages to a form. This includes a 'Reset input' button which clears the form input. """ class ModelObject: @exposed def fields(self, fields): fields.some_field = Field(label='Some field', default='not changed') @exposed def events(self, events): events.submit_break = Event(label='Submit', action=Action(self.always_break)) def always_break(self): raise ValidationException(message='designed to break') class MyForm(Form): def __init__(self, view): super().__init__(view, 'myform') self.use_layout(FormLayout()) model_object = ModelObject() if self.exception: self.layout.add_alert_for_domain_exception(self.exception) self.layout.add_input( TextInput(self, model_object.fields.some_field)) self.define_event_handler(model_object.events.submit_break) self.add_child(Button(self, model_object.events.submit_break)) wsgi_app = web_fixture.new_wsgi_app(child_factory=MyForm.factory()) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') browser.type(XPath.input_labelled('Some field'), 'some input given') browser.click(XPath.button_labelled('Submit')) alert = XPath.div().including_class('alert') assert browser.is_element_present(alert) assert browser.get_text(alert) == 'designed to break' assert browser.get_value( XPath.input_labelled('Some field')) == 'some input given' browser.click(XPath.button_labelled('Reset input')) assert not browser.is_element_present(alert) assert browser.get_value( XPath.input_labelled('Some field')) == 'not changed'
def test_example(web_fixture, responsive_example_fixture): fixture = responsive_example_fixture wsgi_application = web_fixture.new_wsgi_app(site_root=ResponsiveUI, enable_js=True) web_fixture.reahl_server.set_app(wsgi_application) browser = fixture.browser browser.open('/') # Reveal sections for new investors assert not browser.is_visible(fixture.investor_information) browser.set_selected(XPath.input_labelled('New')) browser.wait_for_element_visible(fixture.investor_information) browser.wait_for_element_visible(fixture.new_investor_specific_information) # Reveal and complete sections for existing investors browser.set_selected(XPath.input_labelled('Existing')) browser.wait_for_element_visible(fixture.investor_information) browser.wait_for_element_not_visible( fixture.new_investor_specific_information) browser.type(XPath.input_labelled('Existing account number'), '1234') # Reveal sections for Investment allocation details assert not browser.is_visible(fixture.investment_allocation_details) browser.click( XPath.label().with_text('I agree to the terms and conditions')) browser.wait_for_element_visible(fixture.investment_allocation_details) browser.type(XPath.input_labelled('Total amount'), '10000') # Check calculating totals browser.type(fixture.percentage_input_for('Fund A'), '80') browser.wait_for(fixture.percentage_total_is, '80') browser.type(fixture.percentage_input_for('Fund B'), '80') browser.wait_for(fixture.percentage_total_is, '160') # Check DomainException upon submit with incorrect totals browser.click(XPath.button_labelled('Submit')) browser.wait_for_element_visible(fixture.domain_exception_alert) browser.type(fixture.percentage_input_for('Fund B'), '20') browser.wait_for(fixture.percentage_total_is, '100') # Check successful submit browser.click(XPath.button_labelled('Submit')) browser.wait_for_element_not_visible(fixture.domain_exception_alert)
def test_responsivedisclosure(web_fixture, responsivedisclosure_scenario): fixture = responsivedisclosure_scenario browser = web_fixture.driver_browser fixture.start_example_app() browser.open('/') browser.capture_cropped_screenshot(fixture.new_screenshot_path('responsivedisclosure_1.png')) browser.set_selected(XPath.input_labelled('Existing')) browser.capture_cropped_screenshot(fixture.new_screenshot_path('responsivedisclosure_2.png')) browser.set_selected(XPath.input_labelled('New')) browser.capture_cropped_screenshot(fixture.new_screenshot_path('responsivedisclosure_3.png'))
def test_detour_to_login(web_fixture, party_account_fixture, workflow_web_fixture): fixture = workflow_web_fixture browser = Browser(fixture.wsgi_app) browser.open('/inbox/') assert browser.current_url.path == '/accounts/login' browser.type(XPath.input_labelled('Email'), party_account_fixture.system_account.email) browser.type(XPath.input_labelled('Password'), party_account_fixture.system_account.password) browser.click(XPath.button_labelled('Log in')) assert browser.current_url.path == '/inbox/'
def test_input_validation_cues_javascript_interaction( web_fixture, sql_alchemy_fixture, javascript_validation_scenario): """The visual cues rendered server-side can subsequently be manipulated via javascript.""" fixture = javascript_validation_scenario web_fixture.reahl_server.set_app( web_fixture.new_wsgi_app(child_factory=fixture.Form.factory(), enable_js=False)) browser = fixture.browser with sql_alchemy_fixture.persistent_test_classes(fixture.ModelObject): fixture.domain_object = fixture.ModelObject() Session.add(fixture.domain_object) browser.open('/') browser.type(XPath.input_labelled('Some input'), '') browser.click(XPath.button_labelled('Submit')) assert ['is-invalid' ] == fixture.get_form_group_highlight_marks(browser, index=0) [error] = fixture.get_form_group_errors(browser, index=0) assert error.text == 'Some input is required' web_fixture.reahl_server.set_app( web_fixture.new_wsgi_app(child_factory=fixture.Form.factory(), enable_js=True)) browser.open('/') browser.click(XPath.button_labelled('Submit')) assert ['is-invalid' ] == fixture.get_form_group_highlight_marks(browser, index=0) [error] = fixture.get_form_group_errors(browser, index=0) assert error.text == 'Some input is required' browser.type(XPath.input_labelled('Some input'), 'valid value', trigger_blur=False, wait_for_ajax=False) browser.press_tab() def form_group_is_marked_success(index): return ['is-valid' ] == fixture.get_form_group_highlight_marks(browser, index=index) assert web_fixture.driver_browser.wait_for( form_group_is_marked_success, 0) assert not fixture.get_form_group_errors(browser, index=0)
def test_file_upload_input_basics(web_fixture, file_upload_input_fixture): """A FileUploadInput allows its user to upload multiple files one by one before the Form that contains the FileUploadInput is submitted. When the Form is finally submitted the FileField of the FileUploadInput receives all the files uploaded as UploadFile objects. """ fixture = file_upload_input_fixture web_fixture.reahl_server.set_app(fixture.wsgi_app) browser = web_fixture.driver_browser browser.open('/') assert not fixture.domain_object.submitted assert not fixture.file_was_uploaded(fixture.file_to_upload1.name) assert not fixture.file_was_uploaded(fixture.file_to_upload2.name) # Upload one file browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) browser.click(XPath.button_labelled('Upload')) assert not fixture.domain_object.submitted assert fixture.file_was_uploaded(fixture.file_to_upload1.name) assert not fixture.file_was_uploaded(fixture.file_to_upload2.name) # Upload a second file browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload2.name) browser.click(XPath.button_labelled('Upload')) assert not fixture.domain_object.submitted assert fixture.file_was_uploaded(fixture.file_to_upload1.name) assert fixture.file_was_uploaded(fixture.file_to_upload2.name) # Submit the form browser.click(XPath.button_labelled('Submit')) assert fixture.domain_object.submitted # All uploaded files were submitted assert sorted(fixture.domain_object.submitted_file_info.keys()) == sorted([ os.path.basename(f.name) for f in [fixture.file_to_upload1, fixture.file_to_upload2] ]) # Files that were submitted are correct file1_content, file1_mime_type = fixture.domain_object.submitted_file_info[ os.path.basename(fixture.file_to_upload1.name)] assert file1_content == fixture.file_to_upload1_content assert file1_mime_type == 'text/html'
def test_see_other(web_fixture, access_domain_fixture, access_ui_fixture): """If allowed, an account may see another account's AddressBook, and could edit or add Addresses, depending on the allowed rights.""" browser = access_ui_fixture.browser account = access_domain_fixture.account address_book = access_domain_fixture.address_book other_address_book = access_domain_fixture.other_address_book other_address_book.allow(account) Address(address_book=other_address_book, email_address='*****@*****.**', name='Friend').save() web_fixture.log_in(browser=browser, system_account=account) browser.open('/') browser.click(XPath.link().with_text('Address book of [email protected]')) assert browser.is_element_present( XPath.paragraph().including_text('Friend: [email protected]')) # Case: can only see assert not browser.is_element_enabled( XPath.link().with_text('Add address')) assert not browser.is_element_enabled(XPath.button_labelled('Edit')) # Case: can edit only other_address_book.allow(account, can_edit_addresses=True, can_add_addresses=False) browser.refresh() assert not browser.is_element_enabled( XPath.link().with_text('Add address')) assert browser.is_element_enabled(XPath.button_labelled('Edit')) # Case: can add, and therefor also edit other_address_book.allow(account, can_add_addresses=True) browser.refresh() assert browser.is_element_enabled(XPath.link().with_text('Add address')) assert browser.is_element_enabled(XPath.button_labelled('Edit')) browser.click(XPath.button_labelled('Edit')) browser.type(XPath.input_labelled('Name'), 'Else') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.click(XPath.button_labelled('Update')) assert browser.is_element_present( XPath.paragraph().including_text('Else: [email protected]'))
def test_domain_exception(web_fixture, session_scope_fixture): """Typing the wrong password results in an error message being shown to the user.""" browser = Browser(web_fixture.new_wsgi_app(site_root=SessionScopeUI)) user = session_scope_fixture.user browser.open('/') browser.click(XPath.link().with_text('Log in')) browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.type(XPath.input_labelled('Password'), 'wrong password') browser.click(XPath.button_labelled('Log in')) assert browser.is_element_present( XPath.div().including_text('The email/password given do not match'))
def test_domain_exception(web_fixture, login_fixture): """Typing the wrong password results in an error message being shown to the user.""" browser = login_fixture.browser login_fixture.new_account() browser.open('/') browser.click(XPath.link().with_text('Log in')) browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.type(XPath.input_labelled('Password'), 'wrong password') browser.click(XPath.button_labelled('Log in')) assert browser.is_element_present( XPath.div().including_text('Invalid login credentials'))
def test_dynamiccontent(web_fixture, dynamiccontent_scenario): fixture = dynamiccontent_scenario browser = web_fixture.driver_browser fixture.start_example_app() browser.open('/') browser.capture_cropped_screenshot(fixture.new_screenshot_path('dynamiccontent_1.png')) browser.type(XPath.input_labelled('Total amount'), '3000') percentage_input = XPath.input().inside_of(XPath.table_cell_aligned_to('Percentage', 'Fund', 'Fund A')) browser.type(percentage_input, '80') browser.capture_cropped_screenshot(fixture.new_screenshot_path('dynamiccontent_2.png')) browser.set_selected(XPath.input_labelled('Amount')) browser.capture_cropped_screenshot(fixture.new_screenshot_path('dynamiccontent_3.png'))
def test_async_in_progress(web_fixture, large_file_upload_input_fixture): """While a large file is being uploaded, a progress bar and a Cancel button are displayed. Clicking on the Cancel button stops the upload and clears the file name from the list of uploaded files. """ fixture = large_file_upload_input_fixture fixture.run_hook_before = True web_fixture.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True)) browser = web_fixture.driver_browser browser.open('/') assert not fixture.file_was_uploaded(fixture.file_to_upload1.name) assert not fixture.uploaded_file_is_listed(fixture.file_to_upload1.name) with web_fixture.reahl_server.in_background(wait_till_done_serving=False): browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name, wait_for_ajax=False) # Upload will block, see fixture assert browser.is_element_present('//ul/li/progress') progress = browser.get_attribute('//ul/li/progress', 'value') assert progress == '100' browser.click(XPath.button_labelled('Cancel'), wait_for_ajax=False) assert not fixture.uploaded_file_is_listed(fixture.file_to_upload1.name) assert not fixture.file_was_uploaded(fixture.file_to_upload1.name)
def test_register_help_pending(web_fixture, party_account_fixture, accounts_web_fixture): fixture = accounts_web_fixture verification_requests = Session.query(VerifyEmailRequest) unactivated_account = party_account_fixture.new_system_account( email='*****@*****.**', activated=False) activation_request = VerifyEmailRequest( email=unactivated_account.email, subject_config='accounts.activation_subject', email_config='accounts.activation_email') Session.add(activation_request) deferred_activation = ActivateAccount(system_account=unactivated_account, requirements=[activation_request]) Session.add(deferred_activation) fixture.browser.open('/a_ui/registerHelp') fixture.browser.type(XPath.input_labelled('Email'), unactivated_account.email) fixture.browser.click(XPath.button_labelled('Investigate')) assert fixture.browser.current_url.path == '/a_ui/registerHelp/pending' assert verification_requests.count() == 1 party_account_fixture.mailer.reset() fixture.browser.click(XPath.button_labelled('Send')) assert verification_requests.count() == 1 assert party_account_fixture.mailer.mail_sent assert fixture.browser.current_url.path == '/a_ui/registerHelp/pending/sent'
def test_file_upload_input_list_files_clearing(web_fixture, file_upload_input_fixture, exception_scenario): """The list of uploaded files displayed by the FileUploadInput is cleared once the Form is successfully submitted.""" fixture = file_upload_input_fixture web_fixture.reahl_server.set_app(fixture.wsgi_app) browser = web_fixture.driver_browser browser.open('/') # Upload one file browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) browser.click(XPath.button_labelled('Upload')) assert fixture.uploaded_file_is_listed(fixture.file_to_upload1.name) # Submit the form: browser.click(XPath.button_labelled('Submit')) if fixture.domain_object.throws_exception: assert fixture.uploaded_file_is_listed(fixture.file_to_upload1.name) else: assert not fixture.uploaded_file_is_listed( fixture.file_to_upload1.name)
def test_reset_password_from_url(web_fixture, party_account_fixture, accounts_web_fixture): fixture = accounts_web_fixture account = party_account_fixture.system_account new_password_request = NewPasswordRequest(system_account=account) Session.add(new_password_request) fixture.browser.open('/a_ui/choosePassword?choose_password-email=%s&choose_password-secret=%s' % \ (account.email, new_password_request.as_secret_key())) new_password = '******' fixture.browser.type(XPath.input_labelled('Password'), new_password) fixture.browser.type(XPath.input_labelled('Re-type password'), new_password) fixture.browser.click(XPath.button_labelled('Set new password')) assert fixture.browser.current_url.path == '/a_ui/passwordChanged'