From e6127f02d416db90d8122f64b0388d89f60dfb12 Mon Sep 17 00:00:00 2001 From: connor Bain Date: Fri, 17 Nov 2023 00:51:09 -0600 Subject: [PATCH] implement kwargs (fix #631) for upload_comment --- canvasapi/submission.py | 6 +++++- tests/test_submission.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/canvasapi/submission.py b/canvasapi/submission.py index f2d738c0..88659146 100644 --- a/canvasapi/submission.py +++ b/canvasapi/submission.py @@ -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 diff --git a/tests/test_submission.py b/tests/test_submission.py index 84b7a2dd..df4a10b2 100644 --- a/tests/test_submission.py +++ b/tests/test_submission.py @@ -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):