Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_parent_course(self, m):
register_uris({'course': ['get_by_id']}, m)
self.assertIsInstance(self.ext_tool_course.get_parent(), Course)
def test_reset(self, m):
register_uris({"course": ["reset"]}, m)
course = self.course.reset()
self.assertIsInstance(course, Course)
self.assertTrue(hasattr(course, "name"))
def test_get_parent_course(self, m):
register_uris({'course': ['get_by_id']}, m)
self.assertIsInstance(self.discussion_topic.get_parent(), Course)
def test_get_course(self, m):
register_uris({"course": ["get_by_id"]}, m)
course_by_id = self.canvas.get_course(1)
self.assertIsInstance(course_by_id, Course)
self.assertTrue(hasattr(course_by_id, "name"))
course_by_obj = self.canvas.get_course(course_by_id)
self.assertIsInstance(course_by_obj, Course)
self.assertTrue(hasattr(course_by_obj, "name"))
def get_courses(self, **kwargs):
"""
Retrieve all courses this user is enrolled in.
:calls: `GET /api/v1/users/:user_id/courses \
`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.course.Course`
"""
from canvasapi.course import Course
return PaginatedList(
Course,
self._requester,
"GET",
"users/{}/courses".format(self.id),
_kwargs=combine_kwargs(**kwargs),
)
Defaults to `False`.
:type use_sis_id: bool
:rtype: :class:`canvasapi.course.Course`
"""
if use_sis_id:
course_id = course
uri_str = "courses/sis_course_id:{}"
else:
course_id = obj_or_id(course, "course", (Course,))
uri_str = "courses/{}"
response = self.__requester.request(
"GET", uri_str.format(course_id), _kwargs=combine_kwargs(**kwargs)
)
return Course(self.__requester, response.json())
def get_associated_courses(self, **kwargs):
"""
Return a list of courses associated with the given blueprint.
:calls: `GET /api/v1/courses/:course_id/blueprint_templates/:template_id/ \
associated_courses \
`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.course.Course`
"""
from canvasapi.course import Course
return PaginatedList(
Course,
self._requester,
'GET',
'courses/{}/blueprint_templates/{}/associated_courses'.format(
self.course_id,
self.id
),
_kwargs=combine_kwargs(**kwargs)
)
def update(self, **kwargs):
"""
Update this course.
:calls: `PUT /api/v1/courses/:id \
`_
:returns: True if the course was updated, False otherwise.
:rtype: bool
"""
response = self._requester.request(
"PUT", "courses/{}".format(self.id), _kwargs=combine_kwargs(**kwargs)
)
if response.json().get("name"):
super(Course, self).set_attributes(response.json())
return response.json().get("name")
course's name in the output of subsequent API calls, as
well as in selected places in the Canvas web user interface.
:calls: `PUT /api/v1/users/self/course_nicknames/:course_id \
`_
:param course: The ID of the course.
:type course: :class:`canvasapi.course.Course` or int
:param nickname: The nickname for the course.
:type nickname: str
:rtype: :class:`canvasapi.course.CourseNickname`
"""
from canvasapi.course import CourseNickname
course_id = obj_or_id(course, "course", (Course,))
response = self.__requester.request(
"PUT", "users/self/course_nicknames/{}".format(course_id), nickname=nickname
)
return CourseNickname(self.__requester, response.json())
def cross_list_section(self, new_course):
"""
Move the Section to another course.
:calls: `POST /api/v1/sections/:id/crosslist/:new_course_id \
`_
:param new_course: The object or ID of the new course.
:type new_course: :class:`canvasapi.course.Course` or int
:rtype: :class:`canvasapi.section.Section`
"""
from canvasapi.course import Course
new_course_id = obj_or_id(new_course, "new_course", (Course,))
response = self._requester.request(
'POST',
'sections/{}/crosslist/{}'.format(self.id, new_course_id)
)
return Section(self._requester, response.json())