From f1d9f7ad227b4649a9b84f17132b84a438fb4396 Mon Sep 17 00:00:00 2001 From: moanos Date: Wed, 6 Nov 2024 08:03:45 +0100 Subject: [PATCH] test: Add test for deactivate_404_adoption_notices --- src/tests/test_admin_tasks.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/tests/test_admin_tasks.py b/src/tests/test_admin_tasks.py index d25011d..b8451ff 100644 --- a/src/tests/test_admin_tasks.py +++ b/src/tests/test_admin_tasks.py @@ -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) +