本文整理汇总了Python中huxley.accounts.forms.registration.RegistrationForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python RegistrationForm.is_valid方法的具体用法?Python RegistrationForm.is_valid怎么用?Python RegistrationForm.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类huxley.accounts.forms.registration.RegistrationForm
的用法示例。
在下文中一共展示了RegistrationForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_country_preferences
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_add_country_preferences(self):
""" Tests that adding country preferences works """
# Initialization
params = self.valid_params.copy()
for i in xrange(1,11):
params['country_pref' + str(i)] = 0
# No preferences at all
params['school_name'] = 'CountryTest1'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
school = form.create_school()
self.assertTrue(form.add_country_preferences(school))
prefs = CountryPreference.objects.filter(school=school)
self.assertEqual(len(prefs), 0)
# Couple of random preferences scattered around
params['school_name'] = 'CountryTest2'
params['country_pref1'] = 2
params['country_pref3'] = 10
params['country_pref7'] = 7
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
school = form.create_school()
self.assertTrue(form.add_country_preferences(school))
prefs = CountryPreference.objects.filter(school=school)
self.assertEqual(len(prefs), 3)
self.assertEqual(prefs[0].country.id, params['country_pref1'])
self.assertEqual(prefs[1].country.id, params['country_pref3'])
self.assertEqual(prefs[2].country.id, params['country_pref7'])
示例2: test_password_len
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_password_len(self):
""" Tests for: minimum length """
params = self.valid_params.copy()
# Tests len < 6
params["Password"] = "abcde"
params["Password2"] = "abcde"
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn("Password", form.errors)
self.assertItemsEqual(form.errors["Password"], ["Ensure this value has at least 6 characters (it has 5)."])
# Tests len == 6
params["Password"] = "abcdef"
params["Password2"] = "abcdef"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# Tests len > 6
params["Password"] = "abcdefgh"
params["Password2"] = "abcdefgh"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
示例3: test_school_country
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_school_country(self):
""" Tests that school country is filled out when it's an international school """
params = self.valid_params.copy()
# Try US first (no country specified)
params["us_or_int"] = "us"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# Try US with a country (shouldn't matter)
params["SchoolCountry"] = "America"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# Try international (with no country specified)
params = self.valid_params.copy()
params["us_or_int"] = "international"
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn("SchoolCountry", form.errors)
self.assertItemsEqual(form.errors["SchoolCountry"], ["You must specify a country."])
# Try international (with a country)
params["SchoolCountry"] = "Japan"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
示例4: test_us_phone_nums
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_us_phone_nums(self):
""" Tests the US phone number validation code """
params = self.valid_params.copy()
params["us_or_int"] = "us"
# (XXX) XXX-XXXX
params["PrimaryPhone"] = "(123) 456-7890"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# (XXX) XXX-XXXX xXXXX (extension)
params["PrimaryPhone"] = "(123) 456-7890 x1234"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# 123-456-7890 (invalid)
params["PrimaryPhone"] = "123-456-7890"
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn("PrimaryPhone", form.errors)
self.assertItemsEqual(form.errors["PrimaryPhone"], ["Phone in incorrect format."])
# (123) 12a-1231 (invalid)
params["PrimaryPhone"] = "(123) 12a-1231"
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn("PrimaryPhone", form.errors)
self.assertItemsEqual(form.errors["PrimaryPhone"], ["Phone in incorrect format."])
示例5: test_school_country
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_school_country(self):
""" Tests that school country is filled out when it's an international school """
params = self.valid_params.copy()
# Try US first (no country specified)
params['school_location'] = School.LOCATION_USA
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# Try US with a country (shouldn't matter)
params['school_country'] = 'America'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# Try international (with no country specified)
params = self.valid_params.copy()
params['school_location'] = School.LOCATION_INTERNATIONAL
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('school_country', form.errors)
self.assertItemsEqual(form.errors['school_country'], ['International schools must provide a country.'])
# Try international (with a country)
params['school_country'] = 'Japan'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
示例6: test_us_phone_nums
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_us_phone_nums(self):
""" Tests the US phone number validation code """
params = self.valid_params.copy()
params['school_location'] = School.LOCATION_USA
# (XXX) XXX-XXXX
params['primary_phone'] = '(123) 456-7890'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# (XXX) XXX-XXXX xXXXX (extension)
params['primary_phone'] = '(123) 456-7890 x1234'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# 123-456-7890 (invalid)
params['primary_phone'] = '123-456-7890'
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('primary_phone', form.errors)
self.assertItemsEqual(form.errors['primary_phone'], ['Phone in incorrect format.'])
# (123) 12a-1231 (invalid)
params['primary_phone'] = '(123) 12a-1231'
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('primary_phone', form.errors)
self.assertItemsEqual(form.errors['primary_phone'], ['Phone in incorrect format.'])
示例7: test_username_chars
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_username_chars(self):
""" Tests for: valid characters (alphanumeric, hyphens, underscores) """
# All invalid characters
params = self.valid_params.copy()
params['username'] = '[email protected]#$'
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('username', form.errors)
self.assertItemsEqual(form.errors['username'], ['Usernames must be alphanumeric, underscores, and/or hyphens only.'])
# Mixture of valid and invalid characters
params['username'] = 'abc!defgh'
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('username', form.errors)
self.assertItemsEqual(form.errors['username'], ['Usernames must be alphanumeric, underscores, and/or hyphens only.'])
# Looks valid but isn't
params['username'] = 'Rick Astley'
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('username', form.errors)
self.assertItemsEqual(form.errors['username'], ['Usernames must be alphanumeric, underscores, and/or hyphens only.'])
# Just valid characters
params['username'] = 'RickAstley'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
示例8: test_username_unique
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_username_unique(self):
""" Tests for: uniqueness """
params = self.valid_params.copy()
params['username'] = 'abcdef'
# This should be valid, as 'abcdef' should be unique
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
form.create_user()
# Try again and it should throw a validation error
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('username', form.errors)
self.assertItemsEqual(form.errors['username'], ['Username \'%s\' is already in use. Please choose another one.' % (params['username'])])
示例9: test_country_preferences
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_country_preferences(self):
""" Tests that country preferences are optional """
# Initialization
params = self.valid_params.copy()
for i in xrange(1,11):
params['country_pref' + str(i)] = 0
# Should be valid even with no country preferences
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# Couple of unique country preferences; valid
params['country_pref1'] = 1
params['country_pref3'] = 10
params['country_pref7'] = 7
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
示例10: test_password_chars
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_password_chars(self):
""" Tests that password contains only valid characters (alphanumeric, underscore, ., symbols on number keys) """
# Invalid characters
params = self.valid_params.copy()
params['password'] = '~[]\[]]\[]\[\]'
params['password2'] = '~[]\[]]\[]\[\]'
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('password', form.errors)
self.assertItemsEqual(form.errors['password'], ['Password contains invalid characters.'])
# Valid characters
params['password'] = '[email protected]#$%^&*'
params['password2'] = '[email protected]#$%^&*'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
示例11: test_school_uniqueness
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_school_uniqueness(self):
""" Tests that the school name checks if it's unique """
params = self.valid_params.copy()
params["SchoolName"] = "MySchool"
# This should be valid, as "abcdef" should be unique
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
form.create_school()
# This shouldn't be valid.
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn("SchoolName", form.errors)
self.assertItemsEqual(form.errors["SchoolName"], ["A school with the name '%s' has already been registered." % (params["SchoolName"])])
# Now try another valid one
params["SchoolName"] = "MySchool2"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
示例12: test_school_uniqueness
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_school_uniqueness(self):
""" Tests that the school name checks if it's unique """
params = self.valid_params.copy()
params['school_name'] = 'MySchool'
# This should be valid, as 'abcdef' should be unique
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
form.create_school()
# This shouldn't be valid.
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('school_name', form.errors)
self.assertItemsEqual(form.errors['school_name'], ['A school with the name "%s" has already been registered.' % (params['school_name'])])
# Now try another valid one
params['school_name'] = 'MySchool2'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
示例13: test_international_phone_nums
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_international_phone_nums(self):
""" Tests the international phone number validation code """
params = self.valid_params.copy()
params["us_or_int"] = "international"
params["SchoolCountry"] = "Japan"
# 1234534653465 (just numbers; valid)
params["PrimaryPhone"] = "123434645657"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# 1-123-123-1234 (dashes; valid)
params["PrimaryPhone"] = "1-123-123-1234"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# US format (valid)
params["PrimaryPhone"] = "(123) 456-7890"
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# US format with invalid characters
params["PrimaryPhone"] = "(12a) 456-7890"
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn("PrimaryPhone", form.errors)
self.assertItemsEqual(form.errors["PrimaryPhone"], ["Phone in incorrect format."])
# Numbers with invalid characters
params["PrimaryPhone"] = "1-234-4a3-as,f"
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn("PrimaryPhone", form.errors)
self.assertItemsEqual(form.errors["PrimaryPhone"], ["Phone in incorrect format."])
示例14: test_international_phone_nums
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_international_phone_nums(self):
""" Tests the international phone number validation code """
params = self.valid_params.copy()
params['school_location'] = School.LOCATION_INTERNATIONAL
params['school_country'] = 'Japan'
# 1234534653465 (just numbers; valid)
params['primary_phone'] = '123434645657'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# 1-123-123-1234 (dashes; valid)
params['primary_phone'] = '1-123-123-1234'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# US format (valid)
params['primary_phone'] = '(123) 456-7890'
form = RegistrationForm(params)
self.assertTrue(form.is_valid())
# US format with invalid characters
params['primary_phone'] = '(12a) 456-7890'
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('primary_phone', form.errors)
self.assertItemsEqual(form.errors['primary_phone'], ['Phone in incorrect format.'])
# Numbers with invalid characters
params['primary_phone'] = '1-234-4a3-as,f'
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn('primary_phone', form.errors)
self.assertItemsEqual(form.errors['primary_phone'], ['Phone in incorrect format.'])
示例15: test_password_confirm
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import is_valid [as 别名]
def test_password_confirm(self):
""" Tests that password and password2 match """
params = self.valid_params.copy()
params["Password"] = "abcdef"
params["Password2"] = "abcdefg"
form = RegistrationForm(params)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 2)
self.assertIn("Password", form.errors)
self.assertIn("Password2", form.errors)
self.assertItemsEqual(form.errors["Password"], ["Passwords do not match!"])
self.assertItemsEqual(form.errors["Password2"], ["Passwords do not match!"])