diff --git a/autograder/api/submission/remove.py b/autograder/api/submission/remove.py new file mode 100644 index 00000000..339d2fb1 --- /dev/null +++ b/autograder/api/submission/remove.py @@ -0,0 +1,25 @@ +import autograder.api.common +import autograder.api.config + +API_ENDPOINT = 'submission/remove' +API_PARAMS = [ + autograder.api.config.PARAM_COURSE_ID, + autograder.api.config.PARAM_USER_EMAIL, + autograder.api.config.PARAM_USER_PASS, + autograder.api.config.PARAM_ASSIGNMENT_ID, + + autograder.api.config.PARAM_TARGET_EMAIL_OR_SELF, + autograder.api.config.PARAM_TARGET_SUBMISSION_OR_RECENT, +] + +DESCRIPTION = 'Remove a specified submission. Defaults to the most recent submission.' + +def send(arguments, **kwargs): + return autograder.api.common.handle_api_request(arguments, API_PARAMS, API_ENDPOINT, **kwargs) + +def _get_parser(): + parser = autograder.api.config.get_argument_parser( + description = DESCRIPTION, + params = API_PARAMS) + + return parser diff --git a/autograder/cli/submission/remove.py b/autograder/cli/submission/remove.py new file mode 100644 index 00000000..0c68ab58 --- /dev/null +++ b/autograder/cli/submission/remove.py @@ -0,0 +1,27 @@ +import sys + +import autograder.api.submission.remove + +def run(arguments): + result = autograder.api.submission.remove.send(arguments, exit_on_error = True) + + if (not result['found-user']): + print("No matching user found.") + return 1 + + if (not result['found-submission']): + print("No matching submission found.") + return 2 + + print("Submission removed.") + return 0 + +def main(): + return run(_get_parser().parse_args()) + +def _get_parser(): + parser = autograder.api.submission.remove._get_parser() + return parser + +if (__name__ == '__main__'): + sys.exit(main()) diff --git a/tests/api/data/test_submission_remove_submission_other_missing.json b/tests/api/data/test_submission_remove_submission_other_missing.json new file mode 100644 index 00000000..997a6d97 --- /dev/null +++ b/tests/api/data/test_submission_remove_submission_other_missing.json @@ -0,0 +1,10 @@ +{ + "endpoint": "submission/remove", + "arguments": { + "target-email": "ZZZ" + }, + "output": { + "found-user": false, + "found-submission": false + } +} diff --git a/tests/api/data/test_submission_remove_submission_other_recent.json b/tests/api/data/test_submission_remove_submission_other_recent.json new file mode 100644 index 00000000..8a7a0dfa --- /dev/null +++ b/tests/api/data/test_submission_remove_submission_other_recent.json @@ -0,0 +1,10 @@ +{ + "endpoint": "submission/remove", + "arguments": { + "target-email": "student@test.com" + }, + "output": { + "found-user": true, + "found-submission": true + } +} diff --git a/tests/api/data/test_submission_remove_submission_other_specific.json b/tests/api/data/test_submission_remove_submission_other_specific.json new file mode 100644 index 00000000..9111a152 --- /dev/null +++ b/tests/api/data/test_submission_remove_submission_other_specific.json @@ -0,0 +1,11 @@ +{ + "endpoint": "submission/remove", + "arguments": { + "target-email": "student@test.com", + "target-submission": "1697406265" + }, + "output": { + "found-user": true, + "found-submission": true + } +} diff --git a/tests/api/data/test_submission_remove_submission_self_missing.json b/tests/api/data/test_submission_remove_submission_self_missing.json new file mode 100644 index 00000000..69b6d9c9 --- /dev/null +++ b/tests/api/data/test_submission_remove_submission_self_missing.json @@ -0,0 +1,8 @@ +{ + "endpoint": "submission/remove", + "arguments": {}, + "output": { + "found-user": true, + "found-submission": false + } +}