diff --git a/src/tests/test_views.py b/src/tests/test_views.py index cfdca8f..deca8f1 100644 --- a/src/tests/test_views.py +++ b/src/tests/test_views.py @@ -4,7 +4,7 @@ from django.urls import reverse from model_bakery import baker -from fellchensammlung.models import Animal, Species, AdoptionNotice, User +from fellchensammlung.models import Animal, Species, AdoptionNotice, User, Location class AnimalAndAdoptionTest(TestCase): @@ -63,11 +63,18 @@ class SearchTest(TestCase): adoption1 = baker.make(AdoptionNotice, name="TestAdoption1") adoption2 = baker.make(AdoptionNotice, name="TestAdoption2") + adoption3 = baker.make(AdoptionNotice, name="TestAdoption3") + + berlin = Location.get_location_from_string("Berlin") + adoption1.location = berlin + adoption1.save() + stuttgart = Location.get_location_from_string("Tübingen") + adoption3.location = stuttgart + adoption3.save() adoption1.set_active() + adoption3.set_active() adoption2.set_to_review() - adoption1.save() - adoption2.save() def test_basic_view(self): response = self.client.get(reverse('search')) @@ -75,6 +82,7 @@ class SearchTest(TestCase): self.assertContains(response, "TestAdoption1") self.assertNotContains(response, "TestAdoption2") + self.assertContains(response, "TestAdoption3") def test_basic_view_logged_in(self): self.client.login(username='testuser0', password='12345') @@ -84,8 +92,11 @@ class SearchTest(TestCase): self.assertEqual(str(response.context['user']), 'testuser0') self.assertContains(response, "TestAdoption1") + self.assertContains(response, "TestAdoption3") self.assertNotContains(response, "TestAdoption2") - def test_plz_search(self): - response = self.client.post(reverse('search'), {"max_distance": 50, "postcode": 10115}) + response = self.client.post(reverse('search'), {"max_distance": 100, "location": "Berlin"}) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "TestAdoption1") + self.assertNotContains(response, "TestAdoption3")