本文整理汇总了Python中huxley.accounts.forms.registration.RegistrationForm.add_country_preferences方法的典型用法代码示例。如果您正苦于以下问题:Python RegistrationForm.add_country_preferences方法的具体用法?Python RegistrationForm.add_country_preferences怎么用?Python RegistrationForm.add_country_preferences使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类huxley.accounts.forms.registration.RegistrationForm
的用法示例。
在下文中一共展示了RegistrationForm.add_country_preferences方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_country_preferences
# 需要导入模块: from huxley.accounts.forms.registration import RegistrationForm [as 别名]
# 或者: from huxley.accounts.forms.registration.RegistrationForm import add_country_preferences [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'])