From 8c5099f14a0d658125c2f231e34ae60cf1e54d03 Mon Sep 17 00:00:00 2001 From: moanos Date: Sat, 9 Aug 2025 12:16:04 +0200 Subject: [PATCH] fix (test): Notification framework changed --- src/tests/test_models.py | 4 ++-- src/tests/test_search.py | 9 ++++++--- src/tests/test_tools_notifications.py | 19 +++++++++++++------ src/tests/test_views/test_advanced_views.py | 18 ++++++------------ 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/tests/test_models.py b/src/tests/test_models.py index 68882af..8508c54 100644 --- a/src/tests/test_models.py +++ b/src/tests/test_models.py @@ -85,8 +85,8 @@ class TestNotifications(TestCase): cls.test_user_1 = User.objects.create(username="Testuser1", password="SUPERSECRET", email="test@example.org") def test_mark_read(self): - not1 = Notification.objects.create(user=self.test_user_1, text="New rats to adopt", title="πŸ”” New Rat alert") - not2 = Notification.objects.create(user=self.test_user_1, + not1 = Notification.objects.create(user_to_notify=self.test_user_1, text="New rats to adopt", title="πŸ”” New Rat alert") + not2 = Notification.objects.create(user_to_notify=self.test_user_1, text="New wombat to adopt", title="πŸ”” New Wombat alert") not1.mark_read() diff --git a/src/tests/test_search.py b/src/tests/test_search.py index 7ce8705..ce95116 100644 --- a/src/tests/test_search.py +++ b/src/tests/test_search.py @@ -3,10 +3,11 @@ from time import sleep from django.test import TestCase from django.urls import reverse from fellchensammlung.models import SearchSubscription, User, TrustLevel, AdoptionNotice, Location, SexChoicesWithAll, \ - Animal, Species, AdoptionNoticeNotification, SexChoices + Animal, Species, SexChoices, Notification from model_bakery import baker from fellchensammlung.tools.geo import LocationProxy +from fellchensammlung.tools.model_helpers import NotificationTypeChoices from fellchensammlung.tools.search import Search, notify_search_subscribers @@ -100,5 +101,7 @@ class TestSearch(TestCase): """ notify_search_subscribers(self.adoption1) - self.assertTrue(AdoptionNoticeNotification.objects.filter(user=self.test_user1, adoption_notice=self.adoption1).exists()) - self.assertFalse(AdoptionNoticeNotification.objects.filter(user=self.test_user2).exists()) + self.assertTrue(Notification.objects.filter(user_to_notify=self.test_user1, + adoption_notice=self.adoption1, + notification_type=NotificationTypeChoices.AN_FOR_SEARCH_FOUND).exists()) + self.assertFalse(Notification.objects.filter(user_to_notify=self.test_user2,).exists()) diff --git a/src/tests/test_tools_notifications.py b/src/tests/test_tools_notifications.py index d570c81..e189f73 100644 --- a/src/tests/test_tools_notifications.py +++ b/src/tests/test_tools_notifications.py @@ -1,7 +1,8 @@ from django.test import TestCase from model_bakery import baker -from fellchensammlung.models import User, TrustLevel, Species, Location, AdoptionNotice, AdoptionNoticeNotification +from fellchensammlung.models import User, TrustLevel, Species, Location, AdoptionNotice, Notification +from fellchensammlung.tools.model_helpers import NotificationTypeChoices from fellchensammlung.tools.notifications import notify_of_AN_to_be_checked @@ -24,11 +25,17 @@ class TestNotifications(TestCase): cls.test_user0.trust_level = TrustLevel.ADMIN cls.test_user0.save() - cls.adoption1 = baker.make(AdoptionNotice, name="TestAdoption1", owner=cls.test_user1,) - cls.adoption1.set_unchecked() # Could also emit notification + cls.adoption1 = baker.make(AdoptionNotice, name="TestAdoption1", owner=cls.test_user1, ) + cls.adoption1.set_unchecked() # Could also emit notification def test_notify_of_AN_to_be_checked(self): notify_of_AN_to_be_checked(self.adoption1) - self.assertTrue(AdoptionNoticeNotification.objects.filter(user=self.test_user0).exists()) - self.assertTrue(AdoptionNoticeNotification.objects.filter(user=self.test_user1).exists()) - self.assertFalse(AdoptionNoticeNotification.objects.filter(user=self.test_user2).exists()) \ No newline at end of file + self.assertTrue(Notification.objects.filter(user_to_notify=self.test_user0, + adoption_notice=self.adoption1, + notification_type=NotificationTypeChoices.AN_IS_TO_BE_CHECKED).exists()) + self.assertTrue(Notification.objects.filter(user_to_notify=self.test_user1, + adoption_notice=self.adoption1, + notification_type=NotificationTypeChoices.AN_IS_TO_BE_CHECKED).exists()) + self.assertFalse(Notification.objects.filter(user_to_notify=self.test_user2, + adoption_notice=self.adoption1, + notification_type=NotificationTypeChoices.AN_IS_TO_BE_CHECKED).exists()) diff --git a/src/tests/test_views/test_advanced_views.py b/src/tests/test_views/test_advanced_views.py index 980832f..76a4182 100644 --- a/src/tests/test_views/test_advanced_views.py +++ b/src/tests/test_views/test_advanced_views.py @@ -5,8 +5,9 @@ from django.urls import reverse from model_bakery import baker from fellchensammlung.models import Animal, Species, AdoptionNotice, User, Location, AdoptionNoticeStatus, TrustLevel, \ - Animal, Subscriptions, Comment, CommentNotification, SearchSubscription + Animal, Subscriptions, Comment, Notification, SearchSubscription from fellchensammlung.tools.geo import LocationProxy +from fellchensammlung.tools.model_helpers import NotificationTypeChoices from fellchensammlung.views import add_adoption_notice @@ -34,15 +35,6 @@ class AnimalAndAdoptionTest(TestCase): species=rat, description="Eine unglaublich süße Ratte") - def test_detail_animal(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, "Rat1") - def test_detail_animal_notice(self): self.client.login(username='testuser0', password='12345') @@ -339,8 +331,10 @@ class AdoptionDetailTest(TestCase): reverse('adoption-notice-detail', args=str(an1.pk)), data={"action": "comment", "text": "Test"}) self.assertTrue(Comment.objects.filter(user__username="testuser0").exists()) - self.assertFalse(CommentNotification.objects.filter(user__username="testuser0").exists()) - self.assertTrue(CommentNotification.objects.filter(user__username="testuser1").exists()) + self.assertFalse(Notification.objects.filter(user_to_notify__username="testuser0", + notification_type=NotificationTypeChoices.NEW_COMMENT).exists()) + self.assertTrue(Notification.objects.filter(user_to_notify__username="testuser1", + notification_type=NotificationTypeChoices.NEW_COMMENT).exists()) class AdoptionEditTest(TestCase):