From e98540a2a81327966a61010438af4dc6cfd4a28b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 3 Nov 2020 15:12:33 +0100 Subject: [PATCH] Test search participation objects --- apps/participation/tests.py | 22 ++++++++++++++++++- .../templatetags/search_results_tables.py | 3 +-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/participation/tests.py b/apps/participation/tests.py index eee362f..f242211 100644 --- a/apps/participation/tests.py +++ b/apps/participation/tests.py @@ -1,6 +1,7 @@ from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site +from django.core.management import call_command from django.test import TestCase from django.urls import reverse from registration.models import StudentRegistration @@ -508,7 +509,7 @@ class TestStudentParticipation(TestCase): self.assertEqual(resp.status_code, 403) -class TestAdminForbidden(TestCase): +class TestAdmin(TestCase): def setUp(self) -> None: self.user = User.objects.create_superuser( username="admin@example.com", @@ -517,6 +518,25 @@ class TestAdminForbidden(TestCase): ) self.client.force_login(self.user) + def test_research(self): + """ + Try to search some things. + """ + team = Team.objects.create( + name="Best team ever", + trigram="BTE", + ) + + call_command("rebuild_index", "--noinput", "--verbosity", 0) + + response = self.client.get(reverse("haystack_search") + "?q=" + team.name) + self.assertEqual(response.status_code, 200) + self.assertTrue(response.context["object_list"]) + + response = self.client.get(reverse("haystack_search") + "?q=" + team.trigram) + self.assertEqual(response.status_code, 200) + self.assertTrue(response.context["object_list"]) + def test_create_team_forbidden(self): """ Ensure that an admin can't create a team. diff --git a/apps/registration/templatetags/search_results_tables.py b/apps/registration/templatetags/search_results_tables.py index 840ebac..18825e8 100644 --- a/apps/registration/templatetags/search_results_tables.py +++ b/apps/registration/templatetags/search_results_tables.py @@ -9,6 +9,7 @@ from ..tables import RegistrationTable def search_table(results): model_class = results[0].object.__class__ + table_class = Table if issubclass(model_class, Registration): table_class = RegistrationTable elif issubclass(model_class, Team): @@ -17,8 +18,6 @@ def search_table(results): table_class = ParticipationTable elif issubclass(model_class, Video): table_class = VideoTable - else: - table_class = Table return table_class([result.object for result in results], prefix=model_class._meta.model_name)