Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement kwargs (fix #631) for upload_comment #639

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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