diff --git a/crowdsourcer/tests/test_right_of_reply_views.py b/crowdsourcer/tests/test_right_of_reply_views.py index c73f4d3..5567492 100644 --- a/crowdsourcer/tests/test_right_of_reply_views.py +++ b/crowdsourcer/tests/test_right_of_reply_views.py @@ -157,6 +157,24 @@ def test_council_homepage(self): self.assertEqual(first.authority.name, "Aberdeen City Council") self.assertEqual(second.authority.name, "Aberdeenshire Council") + def test_bad_assignments_ignored(self): + Assigned.objects.create( + marking_session=MarkingSession.objects.get(label="Default"), + user=self.user, + ) + url = reverse("authority_ror_authorities") + response = self.client.get(url) + + context = response.context + assignments = context["assignments"] + + self.assertEqual(len(assignments), 2) + + first = assignments[0] + second = assignments[1] + self.assertEqual(first.authority.name, "Aberdeen City Council") + self.assertEqual(second.authority.name, "Aberdeenshire Council") + def test_council_section_list(self): url = reverse("authority_ror_sections", args=("Aberdeenshire Council",)) response = self.client.get(url) diff --git a/crowdsourcer/views/rightofreply.py b/crowdsourcer/views/rightofreply.py index 65ff9c7..7d4ebd5 100644 --- a/crowdsourcer/views/rightofreply.py +++ b/crowdsourcer/views/rightofreply.py @@ -50,7 +50,9 @@ def get_queryset(self): if user.is_anonymous: return None - qs = Assigned.objects.filter(user=user).order_by("authority__name") + qs = Assigned.objects.filter(user=user, authority__isnull=False).order_by( + "authority__name" + ) return qs