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_list_groups(self, m):
register_uris({"group": ["category_list_groups"]}, m)
with warnings.catch_warnings(record=True) as warning_list:
response = self.group_category.list_groups()
group_list = [group for group in response]
self.assertEqual(len(group_list), 2)
self.assertIsInstance(group_list[0], Group)
self.assertTrue(hasattr(group_list[0], "id"))
self.assertEqual(len(warning_list), 1)
self.assertEqual(warning_list[-1].category, DeprecationWarning)
def test_get_groups(self, m):
requires = {"course": ["list_groups_context", "list_groups_context2"]}
register_uris(requires, m)
groups = self.course.get_groups()
group_list = [group for group in groups]
self.assertIsInstance(group_list[0], Group)
self.assertEqual(len(group_list), 4)
def test_get_parent_group(self, m):
register_uris({'content_migration': ['get_parent_group']}, m)
group = self.content_migration_group.get_parent()
self.assertIsInstance(group, Group)
self.assertTrue(hasattr(group, 'id'))
self.assertEqual(group.id, 1)
def test_get_groups(self, m):
register_uris({'current_user': ['list_groups', 'list_groups2']}, m)
groups = self.user.get_groups()
group_list = [group for group in groups]
self.assertEqual(len(group_list), 4)
self.assertIsInstance(group_list[0], Group)
def test_get_parent_group(self, m):
register_uris({'group': ['get_by_id']}, m)
self.assertIsInstance(self.discussion_topic_group.get_parent(), Group)
def test_create_group(self, m):
register_uris({"group": ["create"]}, m)
group = self.canvas.create_group()
self.assertIsInstance(group, Group)
self.assertTrue(hasattr(group, "name"))
self.assertTrue(hasattr(group, "description"))
def edit(self, **kwargs):
"""
Edit a group.
:calls: `PUT /api/v1/groups/:group_id \
`_
:rtype: :class:`canvasapi.group.Group`
"""
response = self._requester.request(
"PUT", "groups/{}".format(self.id), _kwargs=combine_kwargs(**kwargs)
)
return Group(self._requester, response.json())
def create_group(self, **kwargs):
"""
Create a group.
:calls: `POST /api/v1/group_categories/:group_category_id/groups \
`_
:rtype: :class:`canvasapi.group.Group`
"""
response = self._requester.request(
"POST",
"group_categories/{}/groups".format(self.id),
_kwargs=combine_kwargs(**kwargs),
)
return Group(self._requester, response.json())
def get_groups(self, **kwargs):
"""
List groups in group category.
:calls: `GET /api/v1/group_categories/:group_category_id/groups \
`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.group.Group`
"""
return PaginatedList(
Group, self._requester, "GET", "group_categories/{}/groups".format(self.id)
)
`_
or :calls: `GET /api/v1/courses/:id \
`_
:rtype: :class:`canvasapi.group.Group` or :class:`canvasapi.course.Course`
"""
from canvasapi.group import Group
from canvasapi.course import Course
response = self._requester.request(
'GET',
'{}s/{}'.format(self.parent_type, self.parent_id)
)
if self.parent_type == 'group':
return Group(self._requester, response.json())
elif self.parent_type == 'course':
return Course(self._requester, response.json())