How to use the canvasapi.user.User function in canvasapi

To help you get started, we’ve selected a few canvasapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ucfopen / canvasapi / tests / test_user.py View on Github external
def test_edit(self, m):
        register_uris({"user": ["edit"]}, m)

        new_name = "New User Name"
        self.user.edit(user={"name": new_name})

        self.assertIsInstance(self.user, User)
        self.assertTrue(hasattr(self.user, "name"))
        self.assertEqual(self.user.name, new_name)
github ucfopen / canvasapi / tests / test_group.py View on Github external
def test_remove_user(self, m):
        register_uris({"group": ["list_users", "list_users_p2", "remove_user"]}, m)

        from canvasapi.user import User

        user_by_id = self.group.remove_user(1)
        self.assertIsInstance(user_by_id, User)

        users = self.group.get_users()
        user_by_obj = self.group.remove_user(users[0])
        self.assertIsInstance(user_by_obj, User)
github ucfopen / canvasapi / tests / test_course.py View on Github external
def test_get_user_id_type(self, m):
        register_uris({"course": ["get_user_id_type"]}, m)

        user = self.course.get_user("LOGINID", "login_id")

        self.assertIsInstance(user, User)
        self.assertTrue(hasattr(user, "name"))
github ucfopen / canvasapi / tests / test_canvas.py View on Github external
def test_get_user(self, m):
        register_uris({"user": ["get_by_id"]}, m)

        user_by_id = self.canvas.get_user(1)
        self.assertIsInstance(user_by_id, User)
        self.assertTrue(hasattr(user_by_id, "name"))

        user_by_obj = self.canvas.get_user(user_by_id)
        self.assertIsInstance(user_by_obj, User)
        self.assertTrue(hasattr(user_by_obj, "name"))
github ucfopen / canvasapi / tests / test_paginated_list.py View on Github external
def test_paginated_list_empty(self, m):
        register_uris({'paginated_list': ['empty']}, m)

        pag_list = PaginatedList(
            User,
            self.requester,
            'GET',
            'empty_list'
        )
        item_list = [item for item in pag_list]
        self.assertEqual(len(item_list), 0)
github ucfopen / canvasapi / canvasapi / account.py View on Github external
:type pseudonym: dict
        :rtype: :class:`canvasapi.user.User`
        """
        from canvasapi.user import User

        if isinstance(pseudonym, dict) and "unique_id" in pseudonym:
            kwargs["pseudonym"] = pseudonym
        else:
            raise RequiredFieldMissing("Dictionary with key 'unique_id' is required.")

        response = self._requester.request(
            "POST",
            "accounts/{}/users".format(self.id),
            _kwargs=combine_kwargs(**kwargs),
        )
        return User(self._requester, response.json())
github ucfopen / canvasapi / canvasapi / group.py View on Github external
:calls: `DELETE /api/v1/groups/:group_id/users/:user_id \
        `_

        :param user: The user object or ID to remove from the group.
        :type user: :class:`canvasapi.user.User` or int

        :rtype: :class:`canvasapi.user.User`
        """
        from canvasapi.user import User

        user_id = obj_or_id(user, "user", (User,))

        response = self._requester.request(
            "DELETE", "groups/{}/users/{}".format(self.id, user_id)
        )
        return User(self._requester, response.json())
github ucfopen / canvasapi / canvasapi / user.py View on Github external
def remove_observee(self, observee_id):
        """
        Unregisters a user as being observed by the given user.

        :calls: `DELETE /api/v1/users/:user_id/observees/:observee_id \
        `_

        :param observee_id: The login id for the user to observe.
        :type observee_id: int
        :rtype: :class: `canvasapi.user.User`
        """

        response = self._requester.request(
            "DELETE", "users/{}/observees/{}".format(self.id, observee_id)
        )
        return User(self._requester, response.json())
github ucfopen / canvasapi / canvasapi / util.py View on Github external
or an object. If it is an int, return it. If it is an object and
    the object is of correct type, return the object's id. Otherwise,
    throw an exception.

    :param parameter: int, str, long, or object
    :param param_name: str
    :param object_types: tuple
    :rtype: int
    """
    from canvasapi.user import User

    try:
        return int(parameter)
    except (ValueError, TypeError):
        # Special case where 'self' is a valid ID of a User object
        if User in object_types and parameter == "self":
            return parameter

        for obj_type in object_types:
            if isinstance(parameter, obj_type):
                try:
                    return int(parameter.id)
                except Exception:
                    break

        obj_type_list = ",".join([obj_type.__name__ for obj_type in object_types])
        message = "Parameter {} must be of type {} or int.".format(
            param_name, obj_type_list
        )
        raise TypeError(message)
github ucfopen / canvasapi / canvasapi / user.py View on Github external
def show_observee(self, observee_id):
        """
        Gets information about an observed user.

        :calls: `GET /api/v1/users/:user_id/observees/:observee_id \
        `_

        :param observee_id: The login id for the user to observe.
        :type observee_id: int
        :rtype: :class: `canvasapi.user.User`
        """

        response = self._requester.request(
            "GET", "users/{}/observees/{}".format(self.id, observee_id)
        )
        return User(self._requester, response.json())