Exemplo n.º 1
0
def test_async_number_files_validation(web_fixture, max_number_of_files_file_upload_input_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 = max_number_of_files_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.file_to_upload1.name ) 
    assert not fixture.uploaded_file_is_listed( fixture.file_to_upload2.name ) 

    browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name)
    assert 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:
    assert browser.wait_for_not(browser.is_visible, XPath.span().including_text('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)
    assert not fixture.uploaded_file_is_listed( fixture.file_to_upload2.name ) 
    assert browser.wait_for(browser.is_visible, XPath.span().including_text('a maximum of 1 files may be uploaded')) 

    browser.click(XPath.button_labelled('Remove', filename=fixture.file_to_upload1_name))
    assert browser.wait_for_not(browser.is_visible, XPath.span().including_text('a maximum of 1 files may be uploaded')) 
Exemplo n.º 2
0
def test_async_upload_domain_exception(web_fixture, toggle_validation_fixture):
    """When a DomainException happens upon uploading via JavaScript, 
       the form is replaced with a rerendered version from the server."""

    fixture = toggle_validation_fixture

    web_fixture.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True))
    browser = web_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, trigger_blur=False)
    assert fixture.nested_form_was_reloaded()

    # JS Stuff on re-rendered form still work

    # 1: Server-rendered validation message has been cleared
    assert browser.is_visible(XPath.span().including_text('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().including_text('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))
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def test_async_upload_error(web_fixture, broken_file_upload_input_fixture):
    """If an error happens during (ajax) upload, the user is notified."""
    fixture = broken_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 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)

    assert browser.wait_for_element_present(XPath.span().including_text('an error occurred, please try again later.')) 
    assert not browser.is_element_enabled(XPath.button_labelled('Cancel')) 
Exemplo n.º 6
0
 def error_is_displayed(self, text):
     return self.web_fixture.driver_browser.is_element_present(XPath.span().including_text(text))