示例#1
0
    def test_create_as_unprivileged(self):
        unpriv_user = factory.make_User()
        handler = UserHandler(unpriv_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))

        with self.assertRaises(HandlerPermissionError):
            handler.create(params)
示例#2
0
    def test_create_as_admin_event_log(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": False,
        }
        password = factory.make_string()
        params.update(make_password_params(password))

        handler.create(params)

        event = Event.objects.get(type__level=AUDIT)
        self.assertIsNotNone(event)
        self.assertEqual(event.description,
                         "Created user '{username}'.".format(**params))
示例#3
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)