def prevent_duplicate_upload_js(fixture): """The user is prevented from uploading more than one file with the same name on the client side. """ error_locator = XPath.span_containing( 'uploaded files should all have different names') def error_is_visible(): return browser.is_visible(error_locator) fixture.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True)) browser = fixture.driver_browser 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 fixture.reahl_server.paused(): browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) vassert( 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 async_upload_domain_exception(fixture): """When a DomainException happens upon uploading via JavaScript, the form is replaced with a rerendered version from the server.""" fixture.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True)) browser = fixture.driver_browser browser.open('/') fixture.make_validation_fail = False browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) fixture.make_validation_fail = True fixture.mark_nested_form() with browser.no_page_load_expected(): browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload2.name) vassert(fixture.nested_form_was_reloaded()) # JS Stuff on re-rendered form still work # 1: Server-rendered validation message has been cleared vassert( browser.is_visible(XPath.span_containing('test validation message'))) fixture.make_validation_fail = False with browser.no_page_load_expected(): browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload2.name) browser.wait_for_not(browser.is_visible, XPath.span_containing('test validation message')) # 2: The remove button still happens via ajax with browser.no_page_load_expected(): browser.click( XPath.button_labelled('Remove', filename=fixture.file_to_upload1_name)) browser.click( XPath.button_labelled('Remove', filename=fixture.file_to_upload2_name))
def async_number_files_validation(fixture): """A Field set to only allow a maximum number of files is checked for validity before uploading in JS. """ # 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.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True)) browser = fixture.driver_browser browser.open('/') vassert(not fixture.uploaded_file_is_listed(fixture.file_to_upload1.name)) vassert(not fixture.uploaded_file_is_listed(fixture.file_to_upload2.name)) browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) vassert(fixture.uploaded_file_is_listed(fixture.file_to_upload1.name)) # Corner case: max are uploaded, but you've not asked to add to them yet: vassert( browser.wait_for_not( browser.is_visible, XPath.span_containing('a maximum of 1 files may be uploaded'))) # Normal case: max are uploaded, and you're asking to upload another: browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload2.name) vassert(not fixture.uploaded_file_is_listed(fixture.file_to_upload2.name)) vassert( browser.wait_for( browser.is_visible, XPath.span_containing('a maximum of 1 files may be uploaded'))) browser.click( XPath.button_labelled('Remove', filename=fixture.file_to_upload1_name)) vassert( browser.wait_for_not( browser.is_visible, XPath.span_containing('a maximum of 1 files may be uploaded')))
def async_upload_error(fixture): """If an error happens during (ajax) upload, the user is notified.""" fixture.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True)) fixture.config.reahlsystem.debug = False # So that we don't see the exception output while testing browser = fixture.driver_browser browser.open('/') vassert(not browser.is_element_present( XPath.label_with_text('an error ocurred, please try again later.'))) with expected(Exception): browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) vassert( browser.wait_for_element_present( XPath.span_containing( 'an error occurred, please try again later.'))) vassert(not browser.is_element_enabled(XPath.button_labelled('Cancel')))
def async_validation(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.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True)) browser = fixture.driver_browser browser.open('/') vassert(not fixture.uploaded_file_is_listed(fixture.valid_file.name)) vassert(not fixture.uploaded_file_is_listed(fixture.invalid_file.name)) browser.type(XPath.input_labelled('Choose file(s)'), fixture.invalid_file.name) vassert(not fixture.uploaded_file_is_listed(fixture.invalid_file.name)) vassert( browser.is_element_present( XPath.span_containing(fixture.validation_error_message))) browser.type(XPath.input_labelled('Choose file(s)'), fixture.valid_file.name) vassert(fixture.uploaded_file_is_listed(fixture.valid_file.name))
def error_is_displayed(self, text): return self.driver_browser.is_element_present( XPath.span_containing(text))