Skip to content

Commit

Permalink
implement kwargs (fix ucfopen#631) for upload_comment
Browse files Browse the repository at this point in the history
  • Loading branch information
bainco committed Nov 17, 2023
1 parent 02d42cb commit e6127f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion canvasapi/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ def upload_comment(self, file: FileOrPathLike, **kwargs):
).start()

if response[0]:
self.edit(comment={"file_ids": [response[1]["id"]]})
if "comment" in kwargs:
kwargs["comment"].update({"file_ids": [response[1]["id"]]})
else:
kwargs["comment"] = {"file_ids": [response[1]["id"]]}
self.edit(**kwargs)
return response


Expand Down
19 changes: 19 additions & 0 deletions tests/test_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ def test_upload_comment(self, m):
finally:
cleanup_file(filename)

def test_upload_comment_with_kwargs(self, m):
register_uris(
{"submission": ["upload_comment", "upload_comment_final", "edit"]}, m
)

filename = "testfile_submission_{}".format(uuid.uuid4().hex)

try:
with open(filename, "w+") as file:
response = self.submission.upload_comment(
file, comment={"attempt": 1, "text_comment": "This is just a test."}
)

self.assertTrue(response[0])
self.assertIsInstance(response[1], dict)
self.assertIn("url", response[1])
finally:
cleanup_file(filename)


class TestGroupedSubmission(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit e6127f0

Please sign in to comment.