From 20ad9fe6d23a5795d0562dcc0914c6a9bd546f24 Mon Sep 17 00:00:00 2001 From: Eli Chadwick Date: Mon, 6 Nov 2023 11:24:17 +0000 Subject: [PATCH] remove subtag field from knowledge domain lookup --- amy/workshops/lookups.py | 11 +--------- amy/workshops/tests/test_lookups.py | 31 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/amy/workshops/lookups.py b/amy/workshops/lookups.py index 9015aa87b..dfa4bf70e 100644 --- a/amy/workshops/lookups.py +++ b/amy/workshops/lookups.py @@ -332,20 +332,11 @@ def get_queryset(self): class KnowledgeDomainLookupView(OnlyForAdminsNoRedirectMixin, AutoResponseView): - def dispatch(self, request, *args, **kwargs): - self.subtag = "subtag" in request.GET.keys() - return super().dispatch(request, *args, **kwargs) - def get_queryset(self): results = models.KnowledgeDomain.objects.all() if self.term: - results = results.filter( - Q(name__icontains=self.term) | Q(subtag__icontains=self.term) - ) - - if self.subtag: - return results.filter(subtag__iexact=self.term) + results = results.filter(Q(name__icontains=self.term)) results = results.annotate(person_count=Count("person")).order_by( "-person_count" diff --git a/amy/workshops/tests/test_lookups.py b/amy/workshops/tests/test_lookups.py index 2acf3ffbc..d44bad239 100644 --- a/amy/workshops/tests/test_lookups.py +++ b/amy/workshops/tests/test_lookups.py @@ -12,6 +12,7 @@ EventLookupForAwardsView, EventLookupView, GenericObjectLookupView, + KnowledgeDomainLookupView, TTTEventLookupView, urlpatterns, ) @@ -19,6 +20,7 @@ Award, Badge, Event, + KnowledgeDomain, Lesson, Person, Role, @@ -56,6 +58,35 @@ def test_login_regression(self): self.assertEqual(rv.status_code, 200, pattern.name) # OK +class TestKnowledgeDomainLookupView(TestBase): + def setUpView(self, term: str = "") -> KnowledgeDomainLookupView: + # path doesn't matter + request = RequestFactory().get("/") + view = KnowledgeDomainLookupView(request=request, term=term) + return view + + def test_get_queryset_no_term(self): + # Arrange + view = self.setUpView() + # Act + queryset = view.get_queryset() + # Assert + self.assertQuerysetEqual(queryset, KnowledgeDomain.objects.all(), ordered=False) + + def test_get_queryset_simple_term(self): + # Arrange + term = "ed" + view = self.setUpView(term=term) + # Act + queryset = view.get_queryset() + # Assert + self.assertQuerysetEqual( + queryset, + KnowledgeDomain.objects.filter(name__icontains=term), + ordered=False, + ) + + class TestAwardLookupView(TestBase): def setUpView(self, term: str = "", badge: Optional[int] = None) -> AwardLookupView: # path doesn't matter