本文整理汇总了Python中addons.forms.EditThemeOwnerForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python EditThemeOwnerForm.is_valid方法的具体用法?Python EditThemeOwnerForm.is_valid怎么用?Python EditThemeOwnerForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addons.forms.EditThemeOwnerForm
的用法示例。
在下文中一共展示了EditThemeOwnerForm.is_valid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestEditThemeOwnerForm
# 需要导入模块: from addons.forms import EditThemeOwnerForm [as 别名]
# 或者: from addons.forms.EditThemeOwnerForm import is_valid [as 别名]
class TestEditThemeOwnerForm(amo.tests.TestCase):
fixtures = ['base/users']
def setUp(self):
super(TestEditThemeOwnerForm, self).setUp()
self.instance = Addon.objects.create(
type=amo.ADDON_PERSONA,
status=amo.STATUS_PUBLIC, slug='swag-overload',
name='Bands Make Me Dance', description='tha description')
Persona.objects.create(
persona_id=0, addon_id=self.instance.id,
license=amo.LICENSE_CC_BY.id, accentcolor='C0FFEE',
textcolor='EFFFFF')
def test_initial(self):
self.form = EditThemeOwnerForm(None, instance=self.instance)
eq_(self.form.initial, {})
self.instance.addonuser_set.create(user_id=999)
eq_(self.instance.addonuser_set.all()[0].user.email,
'[email protected]')
self.form = EditThemeOwnerForm(None, instance=self.instance)
eq_(self.form.initial, {'owner': '[email protected]'})
def test_success_change_from_no_owner(self):
self.form = EditThemeOwnerForm({'owner': '[email protected]'},
instance=self.instance)
eq_(self.form.is_valid(), True, self.form.errors)
self.form.save()
eq_(self.instance.addonuser_set.all()[0].user.email,
'[email protected]')
def test_success_replace_owner(self):
self.instance.addonuser_set.create(user_id=999)
self.form = EditThemeOwnerForm({'owner': '[email protected]'},
instance=self.instance)
eq_(self.form.is_valid(), True, self.form.errors)
self.form.save()
eq_(self.instance.addonuser_set.all()[0].user.email,
'[email protected]')
def test_error_invalid_user(self):
self.form = EditThemeOwnerForm({'owner': '[email protected]'},
instance=self.instance)
eq_(self.form.is_valid(), False)
示例2: TestEditThemeOwnerForm
# 需要导入模块: from addons.forms import EditThemeOwnerForm [as 别名]
# 或者: from addons.forms.EditThemeOwnerForm import is_valid [as 别名]
class TestEditThemeOwnerForm(amo.tests.TestCase):
fixtures = ["base/users"]
def setUp(self):
self.instance = Addon.objects.create(
type=amo.ADDON_PERSONA,
status=amo.STATUS_PUBLIC,
slug="swag-overload",
name="Bands Make Me Dance",
description="tha description",
)
Persona.objects.create(
persona_id=0,
addon_id=self.instance.id,
license=amo.LICENSE_CC_BY.id,
accentcolor="C0FFEE",
textcolor="EFFFFF",
)
def test_initial(self):
self.form = EditThemeOwnerForm(None, instance=self.instance)
eq_(self.form.initial, {})
self.instance.addonuser_set.create(user_id=999)
eq_(self.instance.addonuser_set.all()[0].user.email, "[email protected]")
self.form = EditThemeOwnerForm(None, instance=self.instance)
eq_(self.form.initial, {"owner": "[email protected]"})
def test_success_change_from_no_owner(self):
self.form = EditThemeOwnerForm({"owner": "[email protected]"}, instance=self.instance)
eq_(self.form.is_valid(), True, self.form.errors)
self.form.save()
eq_(self.instance.addonuser_set.all()[0].user.email, "[email protected]")
def test_success_replace_owner(self):
self.instance.addonuser_set.create(user_id=999)
self.form = EditThemeOwnerForm({"owner": "[email protected]"}, instance=self.instance)
eq_(self.form.is_valid(), True, self.form.errors)
self.form.save()
eq_(self.instance.addonuser_set.all()[0].user.email, "[email protected]")
def test_error_invalid_user(self):
self.form = EditThemeOwnerForm({"owner": "[email protected]"}, instance=self.instance)
eq_(self.form.is_valid(), False)