1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2024-12-05 02:06:52 +00:00

Test search participation objects

This commit is contained in:
Yohann D'ANELLO 2020-11-03 15:12:33 +01:00
parent 7353ecfd5f
commit e98540a2a8
2 changed files with 22 additions and 3 deletions

View File

@ -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.

View File

@ -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)