Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fixes ucfopen#584

Formatting fixes for several files

When requesting enabled features, Canvas returns a list of strings
for each feature instead of objects. This refactors the account,
course, and user modules to return JSON instead of a
`PaginatedList`.

* Update changelog. Fix missing newlines in fixtures

---------

Co-authored-by: Matthew Emond <[email protected]>
  • Loading branch information
bennettscience and Thetwam authored Apr 17, 2023
1 parent 31a3f15 commit c8c7f4b
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 136 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

- Fixed an issue where kwargs were not passed along to Canvas in `Course.get_module()`. (Thanks, [@bennettscience](https://github.com/bennettscience))
- Fixed an issue where not all functions allowed arbitrary keyword arguments. Added a test to detect and prevent this for the future.
- Fixed an issue with `Course.get_enabled_features()` where it would throw an error trying to paginate. It now returns a list of strings directly. (Thanks, [@bennettscience](https://github.com/bennettscience))

## [3.0.0] - 2022-09-21

Expand Down
10 changes: 4 additions & 6 deletions canvasapi/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,18 +979,16 @@ def get_enabled_features(self, **kwargs):
:calls: `GET /api/v1/accounts/:account_id/features/enabled \
<https://canvas.instructure.com/doc/api/feature_flags.html#method.feature_flags.enabled_features>`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.feature.Feature`
:rtype: `list` of `str`
"""
return PaginatedList(
Feature,
self._requester,
response = self._requester.request(
"GET",
"accounts/{}/features/enabled".format(self.id),
{"account_id": self.id},
_kwargs=combine_kwargs(**kwargs),
)

return response.json()

def get_enrollment(self, enrollment, **kwargs):
"""
Get an enrollment object by ID.
Expand Down
10 changes: 4 additions & 6 deletions canvasapi/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,18 +1127,16 @@ def get_enabled_features(self, **kwargs):
:calls: `GET /api/v1/courses/:course_id/features/enabled \
<https://canvas.instructure.com/doc/api/feature_flags.html#method.feature_flags.enabled_features>`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.feature.Feature`
:rtype: `list` of `str`
"""
return PaginatedList(
Feature,
self._requester,
response = self._requester.request(
"GET",
"courses/{}/features/enabled".format(self.id),
{"course_id": self.id},
_kwargs=combine_kwargs(**kwargs),
)

return response.json()

def get_enrollments(self, **kwargs):
"""
List all of the enrollments in this course.
Expand Down
10 changes: 4 additions & 6 deletions canvasapi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,18 +451,16 @@ def get_enabled_features(self, **kwargs):
:calls: `GET /api/v1/users/:user_id/features/enabled \
<https://canvas.instructure.com/doc/api/feature_flags.html#method.feature_flags.enabled_features>`_
:rtype: :class:`canvasapi.paginated_list.PaginatedList` of
:class:`canvasapi.feature.Feature`
:rtype: `list` of `str`
"""
return PaginatedList(
Feature,
self._requester,
response = self._requester.request(
"GET",
"users/{}/features/enabled".format(self.id),
{"user_id": self.id},
_kwargs=combine_kwargs(**kwargs),
)

return response.json()

def get_enrollments(self, **kwargs):
"""
List all of the enrollments for this user.
Expand Down
12 changes: 2 additions & 10 deletions tests/fixtures/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -1845,16 +1845,8 @@
"method": "GET",
"endpoint": "accounts/1/features/enabled",
"data": [
{
"name": "feature_one",
"display_name": "Feature One",
"applies_to": "Account"
},
{
"name": "feature_two",
"display_name": "Feature Two",
"applies_to": "Account"
}
"feature_one",
"feature_two"
],
"status_code": 200
},
Expand Down
12 changes: 2 additions & 10 deletions tests/fixtures/course.json
Original file line number Diff line number Diff line change
Expand Up @@ -2214,16 +2214,8 @@
"method": "GET",
"endpoint": "courses/1/features/enabled",
"data": [
{
"name": "feature_test",
"display_name": "Feature Test",
"applies_to": "Course"
},
{
"name": "feature_second",
"display_name": "Feature Second",
"applies_to": "Course"
}
"feature_one",
"feature_two"
],
"status_code": 200
},
Expand Down
190 changes: 98 additions & 92 deletions tests/fixtures/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,16 @@
"status_code": 200
},
"create_folder": {
"method": "POST",
"endpoint": "users/1/folders",
"data": {
"id": 2,
"name": "Test String",
"locked": false,
"hidden": false
},
"status_code": 200
},
"method": "POST",
"endpoint": "users/1/folders",
"data": {
"id": 2,
"name": "Test String",
"locked": false,
"hidden": false
},
"status_code": 200
},
"edit": {
"method": "PUT",
"endpoint": "users/1",
Expand Down Expand Up @@ -243,39 +243,39 @@
"size": 1024
},
"status_code": 200
},
"get_file_quota": {
"method": "GET",
"endpoint": "users/1/files/quota",
"data": {
"quota": 889234510,
"quota_used": 476231098
},
"status_code": 200
},
},
"get_file_quota": {
"method": "GET",
"endpoint": "users/1/files/quota",
"data": {
"quota": 889234510,
"quota_used": 476231098
},
"status_code": 200
},
"get_folder": {
"method": "GET",
"endpoint": "users/1/folders/1",
"data": {
"id": 1,
"files_count": 10,
"folders_count": 2,
"name": "Folder 1",
"full_name": "Folder 1"
},
"status_code": 200
},
"method": "GET",
"endpoint": "users/1/folders/1",
"data": {
"id": 1,
"files_count": 10,
"folders_count": 2,
"name": "Folder 1",
"full_name": "Folder 1"
},
"status_code": 200
},
"get_folder_2": {
"method": "GET",
"endpoint": "users/1/folders/2",
"data": {
"id": 2,
"files_count": 10,
"folders_count": 2,
"name": "Folder 2",
"full_name": "Folder 1"
},
"status_code": 200
"method": "GET",
"endpoint": "users/1/folders/2",
"data": {
"id": 2,
"files_count": 10,
"folders_count": 2,
"name": "Folder 2",
"full_name": "Folder 1"
},
"status_code": 200
},
"observer_pairing_codes": {
"method": "POST",
Expand Down Expand Up @@ -479,26 +479,26 @@
"status_code": 200
},
"list_folders": {
"method": "GET",
"endpoint": "users/1/folders",
"data": [
{
"id": 2,
"files_count": 0,
"folders_count": 0,
"name": "Folder 2",
"full_name": "user_files/Folder 2"
},
{
"id": 3,
"files_count": 0,
"folders_count": 0,
"name": "Folder 3",
"full_name": "user_files/Folder 3"
}
],
"status_code": 200
},
"method": "GET",
"endpoint": "users/1/folders",
"data": [
{
"id": 2,
"files_count": 0,
"folders_count": 0,
"name": "Folder 2",
"full_name": "user_files/Folder 2"
},
{
"id": 3,
"files_count": 0,
"folders_count": 0,
"name": "Folder 3",
"full_name": "user_files/Folder 3"
}
],
"status_code": 200
},
"merge": {
"method": "PUT",
"endpoint": "users/1/merge_into/2",
Expand Down Expand Up @@ -804,18 +804,22 @@
"method": "GET",
"endpoint": "search/recipients",
"data": [
{
"id": "group_1",
"name": "the group",
"type": "context",
"user_count": 3
},
{
"id": 2,
"name": "greg",
"common_courses": {},
"common_groups": {"1": ["Member"]}
}
{
"id": "group_1",
"name": "the group",
"type": "context",
"user_count": 3
},
{
"id": 2,
"name": "greg",
"common_courses": {},
"common_groups": {
"1": [
"Member"
]
}
}
],
"status_code": 200
},
Expand Down Expand Up @@ -915,7 +919,9 @@
"grading_type": "points",
"course_id": 1,
"name": "Test assignment",
"submission_types": ["online_text_entry"]
"submission_types": [
"online_text_entry"
]
}
],
"courses": [
Expand Down Expand Up @@ -996,7 +1002,9 @@
"grading_type": "points",
"course_id": 1,
"name": "Test assignment",
"submission_types": ["online_text_entry"]
"submission_types": [
"online_text_entry"
]
}
],
"courses": [
Expand Down Expand Up @@ -1132,16 +1140,8 @@
"method": "GET",
"endpoint": "users/1/features/enabled",
"data": [
{
"name": "feature_one",
"display_name": "Feature One",
"applies_to": "User"
},
{
"name": "feature_two",
"display_name": "Feature Two",
"applies_to": "User"
}
"feature_one",
"feature_two"
],
"status_code": 200
},
Expand Down Expand Up @@ -1196,7 +1196,10 @@
"use_justification": "fair_use",
"license": "private",
"message": "2 files updated",
"file_ids": [1,2]
"file_ids": [
1,
2
]
},
"status_code": 200
},
Expand All @@ -1205,7 +1208,10 @@
"endpoint": "users/1/usage_rights",
"data": {
"message": "2 files updated",
"file_ids": [1,2]
"file_ids": [
1,
2
]
},
"status_code": 200
},
Expand All @@ -1226,11 +1232,11 @@
],
"status_code": 200
},
"resolve_path": {
"resolve_path": {
"method": "GET",
"endpoint": "users/1/folders/by_path/Folder_Level_1/Folder_Level_2/Folder_Level_3",
"data": [
{
{
"id": 2,
"files_count": 0,
"folders_count": 1,
Expand Down Expand Up @@ -1261,18 +1267,18 @@
],
"status_code": 200
},
"resolve_path_null": {
"resolve_path_null": {
"method": "GET",
"endpoint": "users/1/folders/by_path",
"data": [
{
{
"id": 2,
"files_count": 0,
"folders_count": 1,
"name": "my_files",
"full_name": "my_files"
}
],
],
"status_code": 200
}
}
Loading

0 comments on commit c8c7f4b

Please sign in to comment.