feat: Add basic tests for search

This commit is contained in:
moanos [he/him] 2024-10-29 06:53:02 +01:00
parent efecfc910d
commit 66a0b42718

View File

@ -6,6 +6,7 @@ from model_bakery import baker
from fellchensammlung.models import Animal, Species, AdoptionNotice, User
class AnimalAndAdoptionTest(TestCase):
@classmethod
def setUpTestData(cls):
@ -47,3 +48,44 @@ class AnimalAndAdoptionTest(TestCase):
self.assertEqual(str(response.context['user']), 'testuser0')
self.assertContains(response, "TestAdoption1")
self.assertContains(response, "Rat1")
class SearchTest(TestCase):
@classmethod
def setUpTestData(cls):
test_user0 = User.objects.create_user(username='testuser0',
first_name="Admin",
last_name="BOFH",
password='12345')
test_user0.save()
# Location of Berlin: lat 52.5170365 lon 13.3888599 PLZ 10115 (Mitte)
adoption1 = baker.make(AdoptionNotice, name="TestAdoption1")
adoption2 = baker.make(AdoptionNotice, name="TestAdoption2")
adoption1.set_active()
adoption2.set_to_review()
adoption1.save()
adoption2.save()
def test_basic_view(self):
response = self.client.get(reverse('search'))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "TestAdoption1")
self.assertNotContains(response, "TestAdoption2")
def test_basic_view_logged_in(self):
self.client.login(username='testuser0', password='12345')
response = self.client.get(reverse('search'))
self.assertEqual(response.status_code, 200)
# Check our user is logged in
self.assertEqual(str(response.context['user']), 'testuser0')
self.assertContains(response, "TestAdoption1")
self.assertNotContains(response, "TestAdoption2")
def test_plz_search(self):
response = self.client.post(reverse('search'), {"max_distance": 50, "postcode": 10115})