From 31187018971ed3236df063aeeaacb456a7017c78 Mon Sep 17 00:00:00 2001 From: moanos Date: Thu, 30 May 2024 10:56:46 +0200 Subject: [PATCH] tests: Add basic test --- src/tests/__init__.py | 0 src/tests/test_views.py | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/tests/__init__.py create mode 100644 src/tests/test_views.py diff --git a/src/tests/__init__.py b/src/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/test_views.py b/src/tests/test_views.py new file mode 100644 index 0000000..7632192 --- /dev/null +++ b/src/tests/test_views.py @@ -0,0 +1,53 @@ +from django.test import TestCase +from django.contrib.auth.models import Permission +from django.urls import reverse + +from model_bakery import baker + +from fellchensammlung.models import Animal, Species, AdoptionNotice, User + +class AnimalTest(TestCase): + @classmethod + def setUpTestData(cls): + test_user0 = User.objects.create_user(username='testuser0', + first_name="Admin", + last_name="BOFH", + password='12345') + permission_view_user = Permission.objects.get(codename='view_member') + test_user0.user_permissions.add(permission_view_user) + + test_user1 = User.objects.create_user(username='testuser1', + first_name="Max", + last_name="Müller", + password='12345') + test_user1.save() + + adoption1 = baker.make(AdoptionNotice, name="TestAdoption1") + rat = baker.make(Species, name="Farbratte") + + rat1 = baker.make(Animal, + name="Rat1", + adoption_notice=adoption1, + species=rat, + description="Eine unglaublich süße Ratte") + + def test_detail(self): + self.client.login(username='testuser0', password='12345') + + response = self.client.post(reverse('animal-detail', args="1")) + self.assertEqual(response.status_code, 200) + # Check our user is logged in + self.assertEqual(str(response.context['user']), 'testuser0') + self.assertContains(response, "Max") + self.assertContains(response, "Mia-Mo") + + """Allows Max to be present, has to find Mia-Mo""" + response = self.client.post(reverse('library:search'), data={'q': "Mia-Mo Michael Müller"}) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "Mia-Mo") + + """Has to find Mia-Mo and not Max""" + response = self.client.post(reverse('library:search'), {'q': "Mia-Mo"}) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "Mia-Mo") + self.assertNotContains(response, "Max") \ No newline at end of file