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_create_discussion_topic(self, m):
register_uris({"group": ["create_discussion_topic"]}, m)
title = "Topic 1"
discussion = self.group.create_discussion_topic()
self.assertTrue(hasattr(discussion, "group_id"))
self.assertIsInstance(discussion, DiscussionTopic)
self.assertEqual(discussion.title, title)
self.assertEqual(discussion.group_id, 1)
def test_create_discussion_topic(self, m):
register_uris({"course": ["create_discussion_topic"]}, m)
title = "Topic 1"
discussion = self.course.create_discussion_topic()
self.assertIsInstance(discussion, DiscussionTopic)
self.assertTrue(hasattr(discussion, "course_id"))
self.assertEqual(title, discussion.title)
self.assertEqual(discussion.course_id, 1)
def test_parent_type_no_id(self, m):
discussion = DiscussionTopic(self.canvas._Canvas__requester, {'id': 1})
with self.assertRaises(ValueError):
discussion._parent_type
def test_get_announcements(self, m):
register_uris({"announcements": ["list_announcements"]}, m)
announcements = self.canvas.get_announcements()
announcement_list = [announcement for announcement in announcements]
self.assertIsInstance(announcements, PaginatedList)
self.assertIsInstance(announcement_list[0], DiscussionTopic)
self.assertEqual(len(announcement_list), 2)
def test_parent_id_no_id(self, m):
discussion = DiscussionTopic(self.canvas._Canvas__requester, {'id': 1})
with self.assertRaises(ValueError):
discussion._parent_id
def get_discussion_topics(self, **kwargs):
"""
Returns the paginated list of discussion topics for this course or group.
:calls: `GET /api/v1/groups/:group_id/discussion_topics \
`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.discussion_topic.DiscussionTopic`
"""
return PaginatedList(
DiscussionTopic,
self._requester,
"GET",
"groups/{}/discussion_topics".format(self.id),
{"group_id": self.id},
_kwargs=combine_kwargs(**kwargs),
)
:calls: `POST /api/v1/courses/:course_id/discussion_topics \
`_
:rtype: :class:`canvasapi.discussion_topic.DiscussionTopic`
"""
response = self._requester.request(
"POST",
"courses/{}/discussion_topics".format(self.id),
_kwargs=combine_kwargs(**kwargs),
)
response_json = response.json()
response_json.update({"course_id": self.id})
return DiscussionTopic(self._requester, response_json)
:param topic: The object or ID of the discussion topic.
:type topic: :class:`canvasapi.discussion_topic.DiscussionTopic` or int
:rtype: :class:`canvasapi.discussion_topic.DiscussionTopic`
"""
topic_id = obj_or_id(topic, "topic", (DiscussionTopic,))
response = self._requester.request(
"GET", "groups/{}/discussion_topics/{}".format(self.id, topic_id)
)
response_json = response.json()
response_json.update({"group_id": self.id})
return DiscussionTopic(self._requester, response_json)
def get_announcements(self, **kwargs):
"""
List announcements.
:calls: `GET /api/v1/announcements \
`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.discussion_topic.DiscussionTopic`
"""
from canvasapi.discussion_topic import DiscussionTopic
return PaginatedList(
DiscussionTopic,
self.__requester,
"GET",
"announcements",
_kwargs=combine_kwargs(**kwargs),
)