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


Python RegistrationForm.create_school方法代码示例

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


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

示例1: test_add_country_preferences

# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import create_school [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'])
开发者ID:jawoonkim,项目名称:huxley,代码行数:37,代码来源:test_registration.py

示例2: test_school_uniqueness

# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import create_school [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())
开发者ID:jawoonkim,项目名称:huxley,代码行数:24,代码来源:test_registration.py

示例3: test_school_uniqueness

# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import create_school [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())
开发者ID:vishalkal,项目名称:huxley,代码行数:24,代码来源:registration.py

示例4: test_add_committee_preferences

# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import create_school [as 别名]
    def test_add_committee_preferences(self):
        """ Tests that adding committee preferences works """
        params = self.valid_params.copy()
        params['school_name'] = 'CommitteeTest1'
        form = RegistrationForm(params)

        # No committee preferences
        self.assertTrue(form.is_valid())
        school = form.create_school()
        self.assertTrue(form.add_committee_preferences(school))
        self.assertEqual(len(school.committeepreferences.all()), 0)

        # Some preferences
        params['committee_prefs'] = [13, 14, 19]
        params['school_name'] = 'CommitteeTest2'
        form = RegistrationForm(params)

        self.assertTrue(form.is_valid())
        school = form.create_school()
        self.assertTrue(form.add_committee_preferences(school))
        self.assertEqual(len(school.committeepreferences.all()), 3)

        for committee in school.committeepreferences.all():
            self.assertIn(committee.id, params['committee_prefs'])
开发者ID:jawoonkim,项目名称:huxley,代码行数:26,代码来源:test_registration.py

示例5: test_create_advisor_profile

# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import create_school [as 别名]
    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,代码行数:18,代码来源:registration.py

示例6: test_create_school

# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import create_school [as 别名]
    def test_create_school(self):
        """ Tests that the form creates a school object in the DB properly """

        # Test that American schools are created properly
        params = self.valid_params.copy()
        params['school_name'] = 'GirlsGeneration'

        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        school = form.create_school()
        self.assertFalse(school is None)

        self.assertEqual(school.name, params['school_name'])
        self.assertEqual(school.address, params['school_address'])
        self.assertEqual(school.city, params['school_city'])
        self.assertEqual(school.state, params['school_state'])
        self.assertEqual(school.zip_code, str(params['school_zip']))
        self.assertEqual(school.primary_name, params['primary_name'])
        self.assertEqual(school.primary_email, params['primary_email'])
        self.assertEqual(school.primary_phone, params['primary_phone'])
        self.assertEqual(school.program_type, params['program_type'])
        self.assertEqual(school.times_attended, params['times_attended'])
        self.assertEqual(school.min_delegation_size, params['min_delegation_size'])
        self.assertEqual(school.max_delegation_size, params['max_delegation_size'])
        self.assertFalse(school.international)

        # Make sure state isn't an empty string, or a string of spaces
        # Bit unnecessary though
        matches = re.match('^\s*$', school.state)
        self.assertTrue(matches is None)

        if 'secondary_name' in params:
            self.assertEqual(school.secondary_name, params['secondary_name'])
        if 'secondary_email' in params:
            self.assertEqual(school.secondary_email, params['secondary_email'])
        if 'secondary_phone' in params:
            self.assertEqual(school.secondary_phone, params['secondary_phone'])

        # Check to see that it's in the database as well
        schools_in_db = School.objects.filter(name=params['school_name'])
        self.assertGreater(len(schools_in_db), 0)
        self.assertEqual(schools_in_db[0], school)

        # Test international school creation
        params['school_name'] = 'GirlsGenerationInternational'
        params['school_country'] = '10'
        params['school_location'] = School.LOCATION_INTERNATIONAL
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        school = form.create_school()
        self.assertFalse(school is None)
        self.assertEqual(school.name, params['school_name'])
        self.assertEqual(school.address, params['school_address'])
        self.assertEqual(school.city, params['school_city'])
        self.assertEqual(school.zip_code, str(params['school_zip']))
        self.assertEqual(school.country, params['school_country'])
        self.assertEqual(school.primary_name, params['primary_name'])
        self.assertEqual(school.primary_email, params['primary_email'])
        self.assertEqual(school.primary_phone, params['primary_phone'])
        self.assertEqual(school.program_type, params['program_type'])
        self.assertEqual(school.times_attended, params['times_attended'])
        self.assertEqual(school.min_delegation_size, params['min_delegation_size'])
        self.assertEqual(school.max_delegation_size, params['max_delegation_size'])
        self.assertTrue(school.international)

        if 'school_state' in params:
            self.assertEqual(school.state, params['school_state'])
        if 'secondary_name' in params:
            self.assertEqual(school.secondary_name, params['secondary_name'])
        if 'secondary_email' in params:
            self.assertEqual(school.secondary_email, params['secondary_email'])
        if 'secondary_phone' in params:
            self.assertEqual(school.secondary_phone, params['secondary_phone'])

        # Check to see that it's in the database as well
        schools_in_db = School.objects.filter(name=params['school_name'])
        self.assertGreater(len(schools_in_db), 0)
        self.assertEqual(schools_in_db[0], school)
开发者ID:jawoonkim,项目名称:huxley,代码行数:82,代码来源:test_registration.py

示例7: test_create_school

# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import create_school [as 别名]
    def test_create_school(self):
        """ Tests that the form creates a school object in the DB properly """

        # Test that American schools are created properly
        params = self.valid_params.copy()
        params["SchoolName"] = "GirlsGeneration"

        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        school = form.create_school()
        self.assertFalse(school is None)

        self.assertEqual(school.name, params["SchoolName"])
        self.assertEqual(school.address, params["SchoolAddress"])
        self.assertEqual(school.city, params["SchoolCity"])
        self.assertEqual(school.state, params["SchoolState"])
        self.assertEqual(school.zip_code, str(params["SchoolZip"]))
        self.assertEqual(school.primary_name, params["PrimaryName"])
        self.assertEqual(school.primary_email, params["PrimaryEmail"])
        self.assertEqual(school.primary_phone, params["PrimaryPhone"])
        self.assertEqual(school.program_type, params["program_type"])
        self.assertEqual(school.times_attended, params["howmany"])
        self.assertEqual(school.min_delegation_size, params["MinDelegation"])
        self.assertEqual(school.max_delegation_size, params["MaxDelegation"])
        self.assertFalse(school.international)

        # Make sure state isn't an empty string, or a string of spaces
        # Bit unnecessary though
        matches = re.match("^\s*$", school.state)
        self.assertTrue(matches is None)

        if "SecondaryName" in params:
            self.assertEqual(school.secondary_name, params["SecondaryName"])
        if "SecondaryEmail" in params:
            self.assertEqual(school.secondary_email, params["SecondaryEmail"])
        if "SecondaryPhone" in params:
            self.assertEqual(school.secondary_phone, params["SecondaryPhone"])

        # Check to see that it's in the database as well
        schools_in_db = School.objects.filter(name=params["SchoolName"])
        self.assertGreater(len(schools_in_db), 0)
        self.assertEqual(schools_in_db[0], school)

        # Test international school creation
        params["SchoolName"] = "GirlsGenerationInternational"
        params["SchoolCountry"] = 10
        params["us_or_int"] = "international"
        form = RegistrationForm(params)
        self.assertTrue(form.is_valid())

        school = form.create_school()
        self.assertFalse(school is None)
        self.assertEqual(school.name, params["SchoolName"])
        self.assertEqual(school.address, params["SchoolAddress"])
        self.assertEqual(school.city, params["SchoolCity"])
        self.assertEqual(school.zip_code, str(params["SchoolZip"]))
        #self.assertEqual(school.country, params["SchoolCountry"]) TODO
        self.assertEqual(school.primary_name, params["PrimaryName"])
        self.assertEqual(school.primary_email, params["PrimaryEmail"])
        self.assertEqual(school.primary_phone, params["PrimaryPhone"])
        self.assertEqual(school.program_type, params["program_type"])
        self.assertEqual(school.times_attended, params["howmany"])
        self.assertEqual(school.min_delegation_size, params["MinDelegation"])
        self.assertEqual(school.max_delegation_size, params["MaxDelegation"])
        self.assertTrue(school.international)

        if "SchoolState" in params:
            self.assertEqual(school.state, params["SchoolState"])
        if "SecondaryName" in params:
            self.assertEqual(school.secondary_name, params["SecondaryName"])
        if "SecondaryEmail" in params:
            self.assertEqual(school.secondary_email, params["SecondaryEmail"])
        if "SecondaryPhone" in params:
            self.assertEqual(school.secondary_phone, params["SecondaryPhone"])

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


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