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'
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'
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()
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'
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
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
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'
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'}}
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'
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 == '*****@*****.**'
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' } }
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'
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 == '*****@*****.**'
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' } }
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
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()
def test_validate_form_success(self): form = LoginForm(validators=[SampleFormValidator()]) form.data = {'username': '******', 'password': '******'} valid = form.is_valid() assert valid
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'}}