Example #1
0
 def test_set_data_on_form(self):
     form = LoginForm('test')
     post_data = {'username': '******', 'password': '******', 'first_name': None, 'last_name': None, 'email': None}
     form.data = post_data
     assert form.data == post_data
     request = Request('GET', post={'first_name': 'data'}, files={'file': 'something'})
     form.data = request
     assert form.data['first_name'] == 'data'
Example #2
0
 def test_set_data_on_form(self):
     form = LoginForm('test')
     post_data = {
         'username': '******',
         'password': '******',
         'first_name': None,
         'last_name': None,
         'email': None}
     form.data = post_data
     assert form.data == post_data
     environ = environ_with_file()
     request = Request.from_environ(environ)
     form.data = request
     assert form.data['first_name'] == '1234'
Example #3
0
 def test_hydrate_form_to_object_with_mapping_invalid_class(self):
     with raises(AttributeError):
         form = LoginForm('test')
         form.data = {'username': '******', 'password': '******'}
         user = Contact()  # obviously not a user
         form.bind(user, {'username': ('firstname', 'test')}, hydrate=False)
         form.is_valid()
Example #4
0
 def test_set_data_on_form(self):
     form = LoginForm('test')
     post_data = {
         'username': '******',
         'password': '******',
         'first_name': None,
         'last_name': None,
         'email': None
     }
     form.data = post_data
     assert form.data == post_data
     request = Request('GET',
                       post={'first_name': 'data'},
                       files={'file': 'something'})
     form.data = request
     assert form.data['first_name'] == 'data'
Example #5
0
 def test_setting_raw_data(self):
     form = LoginForm('test')
     data = {'username': '******'}
     expected_data = {'first_name': None, 'last_name': None, 'password': None, 'username': '******', 'email': None}
     form.data = data
     assert form.username.value == 'simon'
     assert form.data == expected_data
     assert form.raw_data == expected_data
Example #6
0
 def test_ignored_fields(self):
     form = LoginForm('test')
     user = User()
     form.bind(user, ignored_fields=('username',))
     form.data = {'username': '******', 'password': '******'}
     form.is_valid()
     assert not form.username.value
     assert form.password.value
Example #7
0
 def test_hydrate_form_to_object_without_mapping(self):
     form = LoginForm('test')
     form.data = {'username': '******', 'password': '******'}
     user = User()
     form.bind(user, hydrate=False)
     form.is_valid()
     assert user.username == 'simon'
     assert user.password == 'test'
Example #8
0
 def test_filter_and_validate_input(self):
     form = LoginForm('test')
     data = {'username': '******'}
     form.data = data
     form.is_valid()
     assert form.username.value == 'simon'
     assert form.username.original_value == 'simon '
     assert form.errors == {'password': {'messages': ['Value is required'], 'label': 'password'}}
Example #9
0
 def test_bind_object_to_form_without_mapping(self):
     form = LoginForm('test')
     user = User(username='******', password='******')
     form.bind(user)
     assert form.username.value == 'simon'
     assert form.password.value == 'test'
     form.data = {'password': '******'}
     assert form.password.value == 'newpass'
Example #10
0
 def test_hydrate_form_to_object_without_mapping(self):
     form = LoginForm('test')
     form.data = {'username': '******', 'password': '******'}
     user = User()
     form.bind(user, hydrate=False)
     form.is_valid()
     assert user.username == 'simon'
     assert user.password == 'test'
Example #11
0
 def test_bind_object_to_form_without_mapping(self):
     form = LoginForm('test')
     user = User(username='******', password='******')
     form.bind(user)
     assert form.username.value == 'simon'
     assert form.password.value == 'test'
     form.data = {'password': '******'}
     assert form.password.value == 'newpass'
Example #12
0
 def test_hydrate_form_to_object_with_mapping(self):
     form = LoginForm('test')
     form.data = {'username': '******', 'password': '******', 'email': '*****@*****.**'}
     user = User()
     form.bind(user, form_user_mapping, hydrate=False)
     form.is_valid()
     assert user.username == 'simon'
     assert user.password == 'test'
     assert user.personal.contact.email == '*****@*****.**'
Example #13
0
 def test_validate_form_invalid(self):
     form = LoginForm(validators=[SampleFormValidator()])
     form.data = {'username': '******', 'password': '******'}
     valid = form.is_valid()
     assert not valid
     assert form.errors == {
         'form': {
             'messages': ['Username does not match.'],
             'label': 'Form'
         }
     }
Example #14
0
 def test_bind_object_to_form_with_mapping(self):
     form = LoginForm('test')
     user = User(username='******', password='******')
     user.personal.first_name = 'Simon'
     user.personal.contact.email = '*****@*****.**'
     form.bind(user, form_user_mapping)
     assert form.username.value == 'simon'
     assert form.first_name.value == 'Simon'
     assert form.email.value == '*****@*****.**'
     assert form.password.value == 'test'
     form.data = {'password': '******'}
     assert form.password.value == 'newpass'
Example #15
0
 def test_bind_object_to_form_with_mapping(self):
     form = LoginForm('test')
     user = User(username='******', password='******')
     user.personal.first_name = 'Simon'
     user.personal.contact.email = '*****@*****.**'
     form.bind(user, form_user_mapping)
     assert form.username.value == 'simon'
     assert form.first_name.value == 'Simon'
     assert form.email.value == '*****@*****.**'
     assert form.password.value == 'test'
     form.data = {'password': '******'}
     assert form.password.value == 'newpass'
Example #16
0
 def test_hydrate_form_to_object_with_mapping(self):
     form = LoginForm('test')
     form.data = {
         'username': '******',
         'password': '******',
         'email': '*****@*****.**'
     }
     user = User()
     form.bind(user, form_user_mapping, hydrate=False)
     form.is_valid()
     assert user.username == 'simon'
     assert user.password == 'test'
     assert user.personal.contact.email == '*****@*****.**'
Example #17
0
 def test_filter_and_validate_input(self):
     form = LoginForm('test')
     data = {'username': '******'}
     form.data = data
     form.is_valid()
     assert form.username.value == 'simon'
     assert form.username.original_value == 'simon '
     assert form.errors == {
         'password': {
             'messages': ['Value is required'],
             'label': 'password'
         }
     }
Example #18
0
 def test_setting_raw_data(self):
     form = LoginForm('test')
     data = {'username': '******'}
     expected_data = {
         'first_name': None,
         'last_name': None,
         'password': None,
         'username': '******',
         'email': None
     }
     form.data = data
     assert form.username.value == 'simon'
     assert form.data == expected_data
     assert form.raw_data == expected_data
Example #19
0
 def test_hydrate_form_to_object_with_mapping_invalid_class(self):
     form = LoginForm('test')
     form.data = {'username': '******', 'password': '******'}
     user = Contact()  # obviously not a user
     form.bind(user, {'username': ('firstname', 'test')}, hydrate=False)
     form.is_valid()
Example #20
0
 def test_validate_form_success(self):
     form = LoginForm(validators=[SampleFormValidator()])
     form.data = {'username': '******', 'password': '******'}
     valid = form.is_valid()
     assert valid
Example #21
0
 def test_validate_form_success(self):
     form = LoginForm(validators=[SampleFormValidator()])
     form.data = {'username': '******', 'password': '******'}
     valid = form.is_valid()
     assert valid
Example #22
0
 def test_validate_form_invalid(self):
     form = LoginForm(validators=[SampleFormValidator()])
     form.data = {'username': '******', 'password': '******'}
     valid = form.is_valid()
     assert not valid
     assert form.errors == {'form': {'messages': ['Username does not match.'], 'label': 'Form'}}