Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter cancel/remind-all querysets explicitly #375

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading