Skip to content

Commit

Permalink
fix: filter cancel/remind-all querysets explicitly
Browse files Browse the repository at this point in the history
ENT-8156 | Previous related change didn't include calls
to `self.filter_queryset()`.
  • Loading branch information
iloveagent57 committed Jan 2, 2024
1 parent f8a2333 commit ef48d3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions enterprise_access/apps/api/v1/tests/test_assignment_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@ def test_cancel_all_filter_multiple_learner_states(self):
[mock.call(assignment.uuid) for assignment in expected_cancelled_assignments],
any_order=True,
)
assert mock_cancel_task.delay.call_count == len(expected_cancelled_assignments)
for assignment in expected_cancelled_assignments:
assignment.refresh_from_db()
self.assertEqual(assignment.state, LearnerContentAssignmentStateChoices.CANCELLED)
Expand Down Expand Up @@ -1170,6 +1171,7 @@ def test_cancel_all_filter_single_learner_state(self):
[mock.call(assignment.uuid) for assignment in expected_cancelled_assignments],
any_order=True,
)
assert mock_cancel_task.delay.call_count == len(expected_cancelled_assignments)
for assignment in expected_cancelled_assignments:
assignment.refresh_from_db()
self.assertEqual(assignment.state, LearnerContentAssignmentStateChoices.CANCELLED)
Expand Down Expand Up @@ -1207,6 +1209,7 @@ def test_remind_all_filter_multiple_learner_states(self):
[mock.call(assignment.uuid) for assignment in expected_reminded_assignments],
any_order=True,
)
assert mock_remind_task.delay.call_count == len(expected_reminded_assignments)
for assignment in expected_reminded_assignments:
assignment.refresh_from_db()
self.assertEqual(assignment.state, LearnerContentAssignmentStateChoices.ALLOCATED)
Expand Down Expand Up @@ -1237,6 +1240,7 @@ def test_remind_all_filter_single_learner_state(self):
[mock.call(assignment.uuid) for assignment in expected_reminded_assignments],
any_order=True,
)
assert mock_remind_task.delay.call_count == len(expected_reminded_assignments)
for assignment in expected_reminded_assignments:
assignment.refresh_from_db()
self.assertEqual(assignment.state, LearnerContentAssignmentStateChoices.ALLOCATED)
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ def cancel_all(self, request, *args, **kwargs):
```
Raises:
404 if any of the assignments were not found
404 if no cancelable assignments were found
422 if any of the assignments threw an error (not found or not cancelable)
```
"""
assignments = self.get_queryset().filter(
base_queryset = self.get_queryset().filter(
state__in=LearnerContentAssignmentStateChoices.CANCELABLE_STATES,
)
assignments = self.filter_queryset(base_queryset)
if not assignments:
return Response(status=status.HTTP_404_NOT_FOUND)

Expand Down Expand Up @@ -320,13 +321,14 @@ def remind_all(self, request, *args, **kwargs):
```
Raises:
404 if any of the assignments were not found
404 if no cancelable assignments were found
422 if any of the assignments threw an error (not found or not remindable)
```
"""
assignments = self.get_queryset().filter(
base_queryset = self.get_queryset().filter(
state__in=LearnerContentAssignmentStateChoices.REMINDABLE_STATES,
)
assignments = self.filter_queryset(base_queryset)
if not assignments:
return Response(status=status.HTTP_404_NOT_FOUND)

Expand Down

0 comments on commit ef48d3f

Please sign in to comment.