def test_at_limit__user_role(self): """ Even if no more admins are allowed, the user role can be set. """ tier = self.create_tier(admin_limit=1) self.create_tier_info(tier) form = AuthorForm({'role': 'user'}, instance=self.user) form.cleaned_data = {'role': 'user'} self.assertEqual(form.clean_role(), 'user')
def test_no_limit(self): """ Admin assignment is allowed if there's no limit. """ tier = self.create_tier(admin_limit=None) self.create_tier_info(tier) form = AuthorForm({'role': 'admin'}, instance=self.user) form.cleaned_data = {'role': 'admin'} self.assertEqual(form.clean_role(), 'admin')
def test_at_limit(self): """ If they're not an admin and there isn't room for more admins, it's a validation error. """ tier = self.create_tier(admin_limit=1) self.create_tier_info(tier) form = AuthorForm({'role': 'admin'}, instance=self.user) form.cleaned_data = {'role': 'admin'} self.assertRaises(ValidationError, form.clean_role)
def test_at_limit__already_admin(self): """ Even if no more admins are allowed, anyone who is an admin can stay that way (as far as this form is concerned.) """ tier = self.create_tier(admin_limit=1) self.create_tier_info(tier) form = AuthorForm({'role': 'admin'}, instance=self.user, initial={'role': 'admin'}) form.cleaned_data = {'role': 'admin'} self.assertEqual(form.clean_role(), 'admin')