Beispiel #1
0
    def test_create_as_admin(self):
        admin_user = factory.make_admin()
        handler = UserHandler(admin_user, {}, None)

        params = {
            "username": factory.make_string(),
            "last_name": factory.make_string(30),
            "email": factory.make_email_address(),
            "is_superuser": factory.pick_bool(),
        }
        password = factory.make_string()
        params.update(make_password_params(password))

        handler.create(params)

        user = User.objects.get(username=params["username"])
        self.assertAttributes(user, subset_dict(params, user_attributes))
        self.assertTrue(user.check_password(password))
        self.assertTrue(user.userprofile.is_local)
Beispiel #2
0
    def test_update_self_as_unprivileged(self):
        user = factory.make_User()
        handler = UserHandler(user, {}, None)
        params = make_user_attribute_params(user)
        params.update({
            "id":
            user.id,
            "last_name":
            factory.make_name("Newname"),
            "email":
            "new-{}@example.com".format(factory.make_string()),
            "is_superuser":
            True,
            "username":
            factory.make_name("newname"),
        })

        handler.update(params)
        self.assertAttributes(reload_object(user),
                              subset_dict(params, user_attributes))
Beispiel #3
0
    def test_update_self_as_unprivileged(self):
        user = factory.make_User()
        handler = UserHandler(user, {}, None)
        params = make_user_attribute_params(user)
        params.update({
            'id':
            user.id,
            'last_name':
            factory.make_name('Newname'),
            'email':
            'new-{}@example.com'.format(factory.make_string()),
            'is_superuser':
            True,
            'username':
            factory.make_name('newname'),
        })

        handler.update(params)
        self.assertAttributes(reload_object(user),
                              subset_dict(params, user_attributes))