Skip to content

Commit

Permalink
Expose auto grading config on the assigment API
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Sep 9, 2024
1 parent d89aab8 commit 96de0c2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lms/product/canvas/_plugin/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_assignment_configuration(
if auto_grading_config := self.get_deep_linked_assignment_configuration(
request
).get("auto_grading_config"):
# Auto grading is a complex structure, deserialize it before hand
# Auto grading is a complex structure, deserialize it beforehand
assignment_config["auto_grading_config"] = cast(
AutoGradingConfig, json.loads(auto_grading_config)
)
Expand Down
13 changes: 12 additions & 1 deletion lms/views/dashboard/api/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
APIAssignment,
APIAssignments,
APICourse,
AutoGradingConfig,
)
from lms.models import Assignment, RoleScope, RoleType
from lms.security import Permissions
Expand Down Expand Up @@ -98,7 +99,7 @@ def assignments(self) -> APIAssignments:
)
def assignment(self) -> APIAssignment:
assignment = self.dashboard_service.get_request_assignment(self.request)
return APIAssignment(
api_assignment = APIAssignment(
id=assignment.id,
title=assignment.title,
created=assignment.created.isoformat(),
Expand All @@ -108,6 +109,16 @@ def assignment(self) -> APIAssignment:
),
)

if auto_grading_config := assignment.auto_grading_config:
api_assignment["auto_grading_config"] = AutoGradingConfig(
grading_type=auto_grading_config.grading_type,
activity_calculation=auto_grading_config.activity_calculation,
required_annotations=auto_grading_config.required_annotations,
required_replies=auto_grading_config.required_replies,
)

return api_assignment

@view_config(
route_name="api.dashboard.course.assignments.metrics",
request_method="GET",
Expand Down
35 changes: 34 additions & 1 deletion tests/unit/lms/views/dashboard/api/assignment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from sqlalchemy import select

from lms.models import Assignment, RoleScope, RoleType, User
from lms.models import Assignment, AutoGradingConfig, RoleScope, RoleType, User
from lms.views.dashboard.api.assignment import AssignmentViews
from tests import factories

Expand Down Expand Up @@ -65,6 +65,39 @@ def test_assignment(
"course": {"id": assignment.course.id, "title": assignment.course.lms_name},
}

def test_assignment_with_auto_grading(
self, views, pyramid_request, assignment, db_session, dashboard_service
):
assignment.auto_grading_config = AutoGradingConfig(
activity_calculation="separate",
grading_type="scaled",
required_annotations=1,
required_replies=1,
)

db_session.flush()
pyramid_request.matchdict["assignment_id"] = sentinel.id
dashboard_service.get_request_assignment.return_value = assignment

response = views.assignment()

dashboard_service.get_request_assignment.assert_called_once_with(
pyramid_request
)

assert response == {
"id": assignment.id,
"title": assignment.title,
"created": assignment.created.isoformat(),
"course": {"id": assignment.course.id, "title": assignment.course.lms_name},
"auto_grading_config": {
"activity_calculation": "separate",
"grading_type": "scaled",
"required_annotations": 1,
"required_replies": 1,
},
}

def test_course_assignments(
self,
views,
Expand Down

0 comments on commit 96de0c2

Please sign in to comment.