Source code for intranet.apps.search.tests

from django.contrib.auth import get_user_model
from django.urls import reverse
from django.utils import timezone

from ...test.ion_test import IonTestCase
from ...utils.date import get_senior_graduation_year
from ..announcements.models import Announcement
from ..eighth.models import EighthActivity
from ..events.models import Event


[docs]class SearchTestCase(IonTestCase):
[docs] def test_search_grad_year(self): self.login() user = get_user_model().objects.get_or_create( username=f"{get_senior_graduation_year()}hthere", student_id=1234567, first_name="Hello", last_name="There", graduation_year=get_senior_graduation_year(), user_type="student", )[0] user2 = get_user_model().objects.get_or_create( username=f"{get_senior_graduation_year() + 1}hthere", student_id=1234568, first_name="Hello", last_name="There", graduation_year=get_senior_graduation_year() + 1, user_type="student", )[0] user3 = get_user_model().objects.get_or_create( username=f"{get_senior_graduation_year()}hhello", student_id=1234569, first_name="Hello", last_name="Hello", graduation_year=get_senior_graduation_year(), user_type="student", )[0] user4 = get_user_model().objects.get_or_create( username=f"{get_senior_graduation_year() + 2}hhello", student_id=1234570, first_name="Hello", last_name="Hello", graduation_year=get_senior_graduation_year() + 2, user_type="student", )[0] response = self.client.get(reverse("search"), data={"q": f"gradyear>{get_senior_graduation_year() + 1}"}) self.assertEqual(200, response.status_code) self.assertNotIn(user, response.context["search_results"]) self.assertNotIn(user3, response.context["search_results"]) self.assertIn(user4, response.context["search_results"]) self.assertIn(user2, response.context["search_results"]) response = self.client.get(reverse("search"), data={"q": f"gradyear={get_senior_graduation_year()}"}) self.assertEqual(200, response.status_code) self.assertIn(user, response.context["search_results"]) self.assertIn(user3, response.context["search_results"]) self.assertNotIn(user4, response.context["search_results"]) self.assertNotIn(user2, response.context["search_results"])