autograder.api.courses.assignments.submissions.submit

Submit an assignment submission to the autograder.

 1"""
 2Submit an assignment submission to the autograder.
 3"""
 4
 5import typing
 6
 7import autograder.api.common
 8import autograder.api.config
 9import autograder.assignment
10import autograder.error
11import autograder.model.config
12
13# Params have been split up so others can use these base params.
14BASE_API_PARAMS: typing.List[autograder.api.config.APIParam] = [
15    autograder.api.config.PARAM_SERVER,
16    autograder.api.config.PARAM_USER_EMAIL,
17    autograder.api.config.PARAM_USER_PASS,
18
19    autograder.api.config.PARAM_COURSE,
20    autograder.api.config.PARAM_ASSIGNMENT,
21
22    autograder.api.config.PARAM_SUBMISSION_MESSAGE,
23    autograder.api.config.PARAM_ALLOW_LATE,
24]
25
26API_ENDPOINT: str = 'courses/assignments/submissions/submit'
27API_WRITE: bool = True
28API_PARAMS: typing.List[autograder.api.config.APIParam] = BASE_API_PARAMS + [
29    autograder.api.config.PARAM_SUBMISSION_FILES,
30]
31
32def send(config: autograder.model.config.Config, post_paths: typing.Union[typing.List[str], None] = None, **kwargs: typing.Any) -> typing.Tuple[
33        typing.Dict[str, typing.Any], typing.Union[autograder.assignment.GradedAssignment, None]]:
34    """
35    Send a request to the autograder.
36    Return the raw response and graded assignment (if grading was successful).
37    """
38
39    if ((post_paths is None) or len(post_paths) == 0):
40        raise autograder.error.AutograderError("No files provided for submission.")
41
42    response = autograder.api.common.make_api_request(API_ENDPOINT, config, API_PARAMS, write = API_WRITE, post_paths = post_paths, **kwargs)
43
44    assignment = None
45    result = response.get('result', None)
46    if (result is not None):
47        assignment = autograder.assignment.GradedAssignment.from_dict(result)
48
49    return response, assignment
API_ENDPOINT: str = 'courses/assignments/submissions/submit'
API_WRITE: bool = True
def send( config: autograder.model.config.Config, post_paths: Optional[List[str]] = None, **kwargs: Any) -> Tuple[Dict[str, Any], Optional[autograder.assignment.GradedAssignment]]:
33def send(config: autograder.model.config.Config, post_paths: typing.Union[typing.List[str], None] = None, **kwargs: typing.Any) -> typing.Tuple[
34        typing.Dict[str, typing.Any], typing.Union[autograder.assignment.GradedAssignment, None]]:
35    """
36    Send a request to the autograder.
37    Return the raw response and graded assignment (if grading was successful).
38    """
39
40    if ((post_paths is None) or len(post_paths) == 0):
41        raise autograder.error.AutograderError("No files provided for submission.")
42
43    response = autograder.api.common.make_api_request(API_ENDPOINT, config, API_PARAMS, write = API_WRITE, post_paths = post_paths, **kwargs)
44
45    assignment = None
46    result = response.get('result', None)
47    if (result is not None):
48        assignment = autograder.assignment.GradedAssignment.from_dict(result)
49
50    return response, assignment

Send a request to the autograder. Return the raw response and graded assignment (if grading was successful).