Beispiel #1
0
def test_min_length_constraint_js(web_fixture, constraint_rendering_fixture):
    fixture = constraint_rendering_fixture

    min_required_length = 5
    constraint = MinLengthConstraint(min_length=min_required_length)

    class MyForm(Form):
        def __init__(self, view, name):
            super().__init__(view, name)
            field = fixture.model_object.fields.an_attribute.with_validation_constraint(
                constraint)
            self.add_child(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('//input[@type="text"]',
                                    '1234',
                                    trigger_blur=False,
                                    wait_for_ajax=False)
    web_fixture.driver_browser.press_tab()
    web_fixture.driver_browser.wait_for_element_visible(fixture.error_xpath)
Beispiel #2
0
 def min_length_constraint(self, fixture):
     min_required_length = 5
     min_length_constraint = MinLengthConstraint(min_length=min_required_length)
     
     #min length is returned as parameter
     vassert( min_length_constraint.parameters == '%s' % min_required_length )
     
     #case: just enough characters, exact number of
     with expected(NoException):
         min_length_constraint.validate_input('⁵'*min_required_length)
     
     #case: more than enough
     with expected(NoException):
         min_length_constraint.validate_input('ê'*(min_required_length+1))
         
     #case: just not enough characters
     with expected(MinLengthConstraint):
         min_length_constraint.validate_input('ś'*(min_required_length-1))
     
     #case: empty string
     with expected(MinLengthConstraint):
         min_length_constraint.validate_input('')
Beispiel #3
0
    def min_length_constraint_js(self, fixture):
        min_required_length = 5
        constraint = MinLengthConstraint(min_length=min_required_length)

        class MyForm(Form):
            def __init__(self, view, name):
                super(MyForm, self).__init__(view, name)
                field = fixture.model_object.fields.an_attribute
                field.add_validation_constraint(constraint)
                self.add_child(TextInput(self, field))

        wsgi_app = fixture.new_wsgi_app(child_factory=MyForm.factory('myform'),
                                        enable_js=True)
        fixture.reahl_server.set_app(wsgi_app)

        fixture.driver_browser.open('/')

        fixture.driver_browser.type('//input[@type="text"]', '1234')
        fixture.driver_browser.press_tab('//input')
        fixture.driver_browser.wait_for_element_visible(fixture.error_xpath)