Skip to content

Commit

Permalink
Don't create GradeSync with no GradeSyncGrades
Browse files Browse the repository at this point in the history
This is mostly a possibility while testing locally. GradeSync with not
GradeSyncGrades will currently stay "in_progress" forever as no
GradeSync will ever finish.

We could make changes so this type of sync is marked as finished
immediately but we are better off not creating them in the first place.
  • Loading branch information
marcospri committed Sep 25, 2024
1 parent 53f575e commit 288b5cb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lms/views/dashboard/api/grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def create_grading_sync(self):
sync_lms_users = self.db.scalars(
select(LMSUser).where(LMSUser.h_userid.in_(sync_h_user_ids))
).all()
if not sync_lms_users:
self.request.response.status_int = 400
return {
"message": "No users for this grade sync. Can't find any of the provided users"
}

sync_lms_users_by_h_userid: dict[str, LMSUser] = {
lms_user.h_userid: lms_user for lms_user in sync_lms_users
}
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/lms/views/dashboard/api/grading_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@
"dashboard_service", "ltia_http_service", "auto_grading_service"
)
class TestDashboardGradingViews:
def test_create_grading_sync_with_no_lms_users(
self,
pyramid_request,
views,
auto_grading_service,
dashboard_service,
assignment,
):
dashboard_service.get_request_assignment.return_value = assignment
auto_grading_service.get_in_progress_sync.return_value = None
pyramid_request.parsed_params["grades"] = [
{"h_userid": "NON EXISTING", "grade": 0.5},
]

views.create_grading_sync()

dashboard_service.get_request_assignment.assert_called_once_with(
pyramid_request
)
auto_grading_service.get_in_progress_sync.assert_called_once_with(
dashboard_service.get_request_assignment.return_value
)
pyramid_request.response.status_int = 400

def test_create_grading_sync_with_existing_sync(
self,
pyramid_request,
Expand Down

0 comments on commit 288b5cb

Please sign in to comment.