当前位置: 首页>>代码示例>>Python>>正文


Python registration.RegistrationForm类代码示例

本文整理汇总了Python中huxley.accounts.forms.registration.RegistrationForm的典型用法代码示例。如果您正苦于以下问题:Python RegistrationForm类的具体用法?Python RegistrationForm怎么用?Python RegistrationForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RegistrationForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_add_country_preferences

    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'])
开发者ID:jawoonkim,项目名称:huxley,代码行数:35,代码来源:test_registration.py

示例2: test_school_country

    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())
开发者ID:vishalkal,项目名称:huxley,代码行数:28,代码来源:registration.py

示例3: test_us_phone_nums

    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.'])
开发者ID:jawoonkim,项目名称:huxley,代码行数:32,代码来源:test_registration.py

示例4: test_school_country

    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())
开发者ID:jawoonkim,项目名称:huxley,代码行数:28,代码来源:test_registration.py

示例5: test_us_phone_nums

    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."])
开发者ID:vishalkal,项目名称:huxley,代码行数:32,代码来源:registration.py

示例6: test_username_chars

    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())
开发者ID:jawoonkim,项目名称:huxley,代码行数:35,代码来源:test_registration.py

示例7: test_password_confirm

    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!"])
开发者ID:vishalkal,项目名称:huxley,代码行数:15,代码来源:registration.py

示例8: test_create_advisor_profile

    def test_create_advisor_profile(self):
        """ Tests that an advisor profile for a user and a school is successfully created upon registration """
        params = self.valid_params.copy()
        params["Username"] = "advisor_profile_test"
        params["SchoolName"] = "advisor_profile_test"
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        user = form.create_user()
        school = form.create_school()

        profile = form.create_advisor_profile(user, school)
        self.assertFalse(profile is None)

        self.assertEqual(profile.user, user)
        self.assertEqual(profile.school, school)
开发者ID:vishalkal,项目名称:huxley,代码行数:16,代码来源:registration.py

示例9: test_required

    def test_required(self):
        """ Make sure all fields except for the optional ones are present
            in the parameters. """
        params = {'first_name':'', 'school_location': School.LOCATION_USA} # Empty string is not valid
        form = RegistrationForm(params)

        valid = form.is_valid()
        self.assertFalse(valid)

        for name, field in form.fields.items():
            if field.required and name != 'school_location':
                self.assertIn(name, form.errors)
            elif name == 'school_state':
                # State is only required if the school is in the US
                self.assertIn('school_state', form.errors)
            else:
                self.assertNotIn(name, form.errors)
开发者ID:jawoonkim,项目名称:huxley,代码行数:17,代码来源:test_registration.py

示例10: test_create_user

    def test_create_user(self):
        """ Tests parameters and db insertion """

        params = self.valid_params.copy()
        params['username'] = 'ajummaTaeng'
        form = RegistrationForm(params)

        self.assertTrue(form.is_valid())
        user = form.create_user()

        # Check return value
        self.assertEqual(user.username, params['username'])
        self.assertEqual(user.first_name, params['first_name'])
        self.assertEqual(user.last_name, params['last_name'])

        # Check to see that it's in the database as well
        self.assertTrue(HuxleyUser.objects.filter(id=user.id).exists())
开发者ID:jawoonkim,项目名称:huxley,代码行数:17,代码来源:test_registration.py

示例11: test_country_preferences

    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())
开发者ID:jawoonkim,项目名称:huxley,代码行数:18,代码来源:test_registration.py

示例12: test_required

    def test_required(self):
        """ Make sure all fields except for the optional ones are present
            in the parameters. """
        params = {"FirstName":""} # Empty string is not valid
        form = RegistrationForm(params)

        valid = form.is_valid()
        self.assertFalse(valid)

        # Check that all required fields are in form.errors.
        for name, field in form.fields.items():
            if field.required:
                self.assertIn(name, form.errors)
            else:
                if name == "SchoolState":
                    # State is only required if the school is in the US
                    self.assertIn("SchoolState", form.errors)
                else:
                    self.assertNotIn(name, form.errors)
开发者ID:vishalkal,项目名称:huxley,代码行数:19,代码来源:registration.py

示例13: test_create_user

    def test_create_user(self):
        """ Tests parameters and db insertion """

        params = self.valid_params.copy()
        params["Username"] = "ajummaTaeng"
        form = RegistrationForm(params)

        self.assertTrue(form.is_valid())
        user = form.create_user()

        # Check return value
        self.assertEqual(user.username, params["Username"])
        self.assertEqual(user.first_name, params["FirstName"])
        self.assertEqual(user.last_name, params["LastName"])

        # Check to see that it's in the database as well
        users_in_db = User.objects.filter(username=params["Username"])
        self.assertGreater(len(users_in_db), 0)
        self.assertEqual(users_in_db[0], user)
开发者ID:vishalkal,项目名称:huxley,代码行数:19,代码来源:registration.py

示例14: test_password_chars

    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())
开发者ID:jawoonkim,项目名称:huxley,代码行数:20,代码来源:test_registration.py

示例15: test_password_len

    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())
开发者ID:jawoonkim,项目名称:huxley,代码行数:25,代码来源:test_registration.py


注:本文中的huxley.accounts.forms.registration.RegistrationForm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。