예제 #1
0
    def test_user_modification(self):
        class UserModelTest(MetaUserAdmin):
            form = MyChangeUserForm

            class Meta:
                model = User
                fields = ("user_level", )

        user_b = User.objects.create_user(email='*****@*****.**',
                                          password='******')
        self.assertIs(user_b.admin, False)
        user_change_model = UserModelTest(User, self.site)
        data = {'user_level': 'Admin'}
        for elt in user_change_model.get_fields(self.request):
            field = getattr(user_b, elt, None)
            if field:
                data.update({elt: field})
        data.update({"password": "******"})
        my_form = MyChangeUserForm(instance=user_b, data=data)
        my_form.is_valid()
        user_change_model.save_model(request=self.request,
                                     obj=user_b,
                                     form=my_form,
                                     change=True)
        self.assertIs(user_b.admin, True)
 def test_staff(self):
     test_user = User.objects.get(email="*****@*****.**")
     test_user.is_staff = True
     MyChangeUserForm({"email": "*****@*****.**"}, instance=test_user)
 def test_blocked(self):
     test_user = User.objects.get(email="*****@*****.**")
     test_user.is_active = False
     MyChangeUserForm({"email": "*****@*****.**"}, instance=test_user)
 def test_simple_user(self):
     test_user = User.objects.get(email="*****@*****.**")
     MyChangeUserForm({"email": "*****@*****.**"}, instance=test_user)