Skip to content

Commit e6127f0

Browse files
committed
implement kwargs (fix ucfopen#631) for upload_comment
1 parent 02d42cb commit e6127f0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

canvasapi/submission.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ def upload_comment(self, file: FileOrPathLike, **kwargs):
177177
).start()
178178

179179
if response[0]:
180-
self.edit(comment={"file_ids": [response[1]["id"]]})
180+
if "comment" in kwargs:
181+
kwargs["comment"].update({"file_ids": [response[1]["id"]]})
182+
else:
183+
kwargs["comment"] = {"file_ids": [response[1]["id"]]}
184+
self.edit(**kwargs)
181185
return response
182186

183187

tests/test_submission.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ def test_upload_comment(self, m):
122122
finally:
123123
cleanup_file(filename)
124124

125+
def test_upload_comment_with_kwargs(self, m):
126+
register_uris(
127+
{"submission": ["upload_comment", "upload_comment_final", "edit"]}, m
128+
)
129+
130+
filename = "testfile_submission_{}".format(uuid.uuid4().hex)
131+
132+
try:
133+
with open(filename, "w+") as file:
134+
response = self.submission.upload_comment(
135+
file, comment={"attempt": 1, "text_comment": "This is just a test."}
136+
)
137+
138+
self.assertTrue(response[0])
139+
self.assertIsInstance(response[1], dict)
140+
self.assertIn("url", response[1])
141+
finally:
142+
cleanup_file(filename)
143+
125144

126145
class TestGroupedSubmission(unittest.TestCase):
127146
def setUp(self):

0 commit comments

Comments
 (0)