test: Add test for deactivate_404_adoption_notices

This commit is contained in:
moanos [he/him] 2024-11-06 08:03:45 +01:00
parent 4e71ac7866
commit f1d9f7ad22

View File

@ -1,7 +1,8 @@
from datetime import timedelta
from django.utils import timezone
from fellchensammlung.tools.admin import get_unchecked_adoption_notices, deactivate_unchecked_adoption_notices
from fellchensammlung.tools.admin import get_unchecked_adoption_notices, deactivate_unchecked_adoption_notices, \
deactivate_404_adoption_notices
from fellchensammlung.tools.misc import is_404
from django.test import TestCase
@ -53,8 +54,38 @@ class DeactiviationTest(TestCase):
class PingTest(TestCase):
@classmethod
def setUpTestData(cls):
link_active = "https://hyteck.de/"
link_inactive = "https://hyteck.de/maxwell"
now = timezone.now()
less_than_three_weeks_ago = now - timedelta(weeks=1, days=2)
cls.adoption1 = baker.make(AdoptionNotice,
name="TestAdoption1",
created_at=less_than_three_weeks_ago,
last_checked=less_than_three_weeks_ago,
further_information=link_active)
cls.adoption2 = baker.make(AdoptionNotice,
name="TestAdoption1",
created_at=less_than_three_weeks_ago,
last_checked=less_than_three_weeks_ago,
further_information=link_inactive)
cls.adoption1.set_active()
cls.adoption2.set_active()
def test_is_404(self):
urls = [("https://hyteck.de/maxwell", True),
("https://hyteck.de", False)]
for url, expected_result in urls:
self.assertEqual(is_404(url), expected_result)
def test_deactivate_404_adoption_notices(self):
self.assertTrue(self.adoption1.is_active)
self.assertTrue(self.adoption2.is_active)
deactivate_404_adoption_notices()
self.adoption1.refresh_from_db()
self.adoption2.refresh_from_db()
self.assertTrue(self.adoption1.is_active)
self.assertFalse(self.adoption2.is_active)