From fd481fef2e8eb634722619f73935a4d4b6f61162 Mon Sep 17 00:00:00 2001 From: moanos Date: Sun, 31 Aug 2025 10:52:48 +0200 Subject: [PATCH] feat: Fully replace the Adoption Notice Status model with the field --- src/fellchensammlung/admin.py | 16 +- src/fellchensammlung/api/views.py | 4 +- ...nnotice_adoption_notice_status_and_more.py | 21 +++ src/fellchensammlung/models.py | 166 +----------------- src/fellchensammlung/tools/admin.py | 5 +- src/fellchensammlung/tools/metrics.py | 8 +- src/fellchensammlung/tools/model_helpers.py | 1 + src/fellchensammlung/tools/notifications.py | 4 +- src/fellchensammlung/tools/search.py | 6 +- src/fellchensammlung/views.py | 26 ++- src/tests/test_admin_tasks.py | 17 +- src/tests/test_search.py | 6 +- src/tests/test_tools_notifications.py | 4 +- src/tests/test_views/test_advanced_views.py | 15 +- src/tests/test_views/test_basic_views.py | 7 +- src/tests/test_views/test_search.py | 15 +- 16 files changed, 102 insertions(+), 219 deletions(-) create mode 100644 src/fellchensammlung/migrations/0062_alter_adoptionnotice_adoption_notice_status_and_more.py diff --git a/src/fellchensammlung/admin.py b/src/fellchensammlung/admin.py index 37a901f..87ecf9a 100644 --- a/src/fellchensammlung/admin.py +++ b/src/fellchensammlung/admin.py @@ -7,30 +7,26 @@ from django.utils.html import format_html from django.urls import reverse from django.utils.http import urlencode -from .models import User, Language, Text, ReportComment, ReportAdoptionNotice, Log, Timestamp, SearchSubscription, \ +from .models import Language, Text, ReportComment, ReportAdoptionNotice, Log, Timestamp, SearchSubscription, \ SpeciesSpecificURL, ImportantLocation, SocialMediaPost from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location, Rule, Image, ModerationAction, \ - Comment, Report, Announcement, AdoptionNoticeStatus, User, Subscriptions, Notification + Comment, Announcement, User, Subscriptions, Notification from django.utils.translation import gettext_lazy as _ - -class StatusInline(admin.StackedInline): - model = AdoptionNoticeStatus +from .tools.model_helpers import AdoptionNoticeStatusChoices @admin.register(AdoptionNotice) class AdoptionNoticeAdmin(admin.ModelAdmin): search_fields = ("name__icontains", "description__icontains") list_filter = ("owner",) - inlines = [ - StatusInline, - ] actions = ("activate",) def activate(self, request, queryset): for obj in queryset: - obj.set_active() + obj.adoption_notice_status = AdoptionNoticeStatusChoices.Active.SEARCHING + obj.save() activate.short_description = _("Ausgewählte Vermittlungen aktivieren") @@ -162,10 +158,12 @@ class LocationAdmin(admin.ModelAdmin): ImportantLocationInline, ] + @admin.register(SocialMediaPost) class SocialMediaPostAdmin(admin.ModelAdmin): list_filter = ("platform",) + admin.site.register(Animal) admin.site.register(Species) admin.site.register(Rule) diff --git a/src/fellchensammlung/api/views.py b/src/fellchensammlung/api/views.py index b518f02..be12998 100644 --- a/src/fellchensammlung/api/views.py +++ b/src/fellchensammlung/api/views.py @@ -73,9 +73,9 @@ class AdoptionNoticeApiView(APIView): # Only set active when user has trust level moderator or higher if request.user_to_notify.trust_level >= TrustLevel.MODERATOR: - adoption_notice.set_active() + adoption_notice.adoption_notice_status = AdoptionNoticeStatusChoices.Active.SEARCHING else: - adoption_notice.set_unchecked() + adoption_notice.adoption_notice_status = AdoptionNoticeStatusChoices.AwaitingAction.WAITING_FOR_REVIEW # Log the action Log.objects.create( diff --git a/src/fellchensammlung/migrations/0062_alter_adoptionnotice_adoption_notice_status_and_more.py b/src/fellchensammlung/migrations/0062_alter_adoptionnotice_adoption_notice_status_and_more.py new file mode 100644 index 0000000..948a464 --- /dev/null +++ b/src/fellchensammlung/migrations/0062_alter_adoptionnotice_adoption_notice_status_and_more.py @@ -0,0 +1,21 @@ +# Generated by Django 5.2.1 on 2025-08-30 22:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fellchensammlung', '0061_datamigration_status_model_to_field'), + ] + + operations = [ + migrations.AlterField( + model_name='adoptionnotice', + name='adoption_notice_status', + field=models.TextField(choices=[('active_searching', 'Searching'), ('active_interested', 'Interested'), ('awaiting_action_waiting_for_review', 'Waiting for review'), ('awaiting_action_needs_additional_info', 'Needs additional info'), ('closed_successful_with_notfellchen', 'Successful (with Notfellchen)'), ('closed_successful_without_notfellchen', 'Successful (without Notfellchen)'), ('closed_animal_died', 'Animal died'), ('closed_for_other_adoption_notice', 'Closed for other adoption notice'), ('closed_not_open_for_adoption_anymore', 'Not open for adoption anymore'), ('closed_link_to_more_info_not_reachable', 'Der Link zu weiteren Informationen ist nicht mehr erreichbar.'), ('closed_other', 'Other (closed)'), ('disabled_against_the_rules', 'Against the rules'), ('disabled_unchecked', 'Unchecked'), ('disabled_other', 'Other (disabled)')], max_length=64, verbose_name='Status'), + ), + migrations.DeleteModel( + name='AdoptionNoticeStatus', + ), + ] diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index a113755..081cf33 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -513,60 +513,30 @@ class AdoptionNotice(models.Model): """ return geo.object_in_distance(self, position, max_distance, unknown_true) + @staticmethod + def _values_of(list_of_enums): + return list(map(lambda x: x[0], list_of_enums)) + @property def is_active(self): - if not hasattr(self, 'adoptionnoticestatus'): - return False - return self.adoptionnoticestatus.is_active + return self.adoption_notice_status in self._values_of(AdoptionNoticeStatusChoices.Active.choices) @property def is_disabled(self): - if not hasattr(self, 'adoptionnoticestatus'): - return False - return self.adoptionnoticestatus.is_disabled + return self.adoption_notice_status in self._values_of(AdoptionNoticeStatusChoices.Disabled.choices) @property def is_closed(self): - if not hasattr(self, 'adoptionnoticestatus'): - return False - return self.adoptionnoticestatus.is_closed - - @property - def is_interested(self): - if not hasattr(self, 'adoptionnoticestatus'): - return False - return self.adoptionnoticestatus.is_interested + return self.adoption_notice_status in self._values_of(AdoptionNoticeStatusChoices.Closed.choices) @property def is_awaiting_action(self): - if not hasattr(self, 'adoptionnoticestatus'): - return False - return self.adoptionnoticestatus.is_awaiting_action - - @property - def is_disabled_unchecked(self): - if not hasattr(self, 'adoptionnoticestatus'): - return False - return self.adoptionnoticestatus.is_disabled_unchecked - - def set_closed(self, minor_status=None): - self.last_checked = timezone.now() - self.save() - self.adoptionnoticestatus.set_closed(minor_status) - - def set_active(self): - self.last_checked = timezone.now() - self.save() - if not hasattr(self, 'adoptionnoticestatus'): - AdoptionNoticeStatus.create_other(self) - self.adoptionnoticestatus.set_active() + return self.adoption_notice_status in self._values_of(AdoptionNoticeStatusChoices.AwaitingAction.choices) def set_unchecked(self): self.last_checked = timezone.now() + self.adoption_notice_status = AdoptionNoticeStatusChoices.Disabled.UNCHECKED self.save() - if not hasattr(self, 'adoptionnoticestatus'): - AdoptionNoticeStatus.create_other(self) - self.adoptionnoticestatus.set_unchecked() for subscription in self.get_subscriptions(): notification_title = _("Vermittlung deaktiviert:") + f" {self.name}" @@ -586,124 +556,6 @@ class AdoptionNotice(models.Model): return last_post.created_at -class AdoptionNoticeStatus(models.Model): - """ - The major status indicates a general state of an adoption notice - whereas the minor status is used for reporting - """ - - class Meta: - verbose_name = _('Vermittlungsstatus') - verbose_name_plural = _('Vermittlungsstati') - - ACTIVE = "active" - AWAITING_ACTION = "awaiting_action" - CLOSED = "closed" - DISABLED = "disabled" - MAJOR_STATUS_CHOICES = { - ACTIVE: "active", - AWAITING_ACTION: "in review", - CLOSED: "closed", - DISABLED: "disabled", - } - - MINOR_STATUS_CHOICES = { - ACTIVE: { - "searching": "searching", - "interested": "interested", - }, - AWAITING_ACTION: { - "waiting_for_review": "waiting_for_review", - "needs_additional_info": "needs_additional_info", - }, - CLOSED: { - "successful_with_notfellchen": "successful_with_notfellchen", - "successful_without_notfellchen": "successful_without_notfellchen", - "animal_died": "animal_died", - "closed_for_other_adoption_notice": "closed_for_other_adoption_notice", - "not_open_for_adoption_anymore": "not_open_for_adoption_anymore", - "other": "other" - }, - DISABLED: { - "against_the_rules": "against_the_rules", - "missing_information": "missing_information", - "technical_error": "technical_error", - "unchecked": "unchecked", - "other": "other" - } - } - - major_status = models.CharField(choices=MAJOR_STATUS_CHOICES, max_length=200) - minor_choices = {} - for key in MINOR_STATUS_CHOICES: - minor_choices.update(MINOR_STATUS_CHOICES[key]) - minor_status = models.CharField(choices=minor_choices, max_length=200) - adoption_notice = models.OneToOneField(AdoptionNotice, on_delete=models.CASCADE) - updated_at = models.DateTimeField(auto_now=True) - created_at = models.DateTimeField(auto_now_add=True) - - def __str__(self): - return f"{self.adoption_notice}: {self.major_status}, {self.minor_status}" - - def as_string(self): - return f"{self.major_status}, {self.minor_status}" - - @property - def is_active(self): - return self.major_status == self.ACTIVE - - @property - def is_disabled(self): - return self.major_status == self.DISABLED - - @property - def is_closed(self): - return self.major_status == self.CLOSED - - @property - def is_awaiting_action(self): - return self.major_status == self.AWAITING_ACTION - - @property - def is_interested(self): - return self.major_status == self.ACTIVE and self.minor_status == "interested" - - @property - def is_disabled_unchecked(self): - return self.major_status == self.DISABLED and self.minor_status == "unchecked" - - @staticmethod - def get_minor_choices(major_status): - return AdoptionNoticeStatus.MINOR_STATUS_CHOICES[major_status] - - @staticmethod - def create_other(an_instance): - # Used as empty status to be changed immediately - major_status = AdoptionNoticeStatus.DISABLED - minor_status = AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.DISABLED]["other"] - AdoptionNoticeStatus.objects.create(major_status=major_status, - minor_status=minor_status, - adoption_notice=an_instance) - - def set_closed(self, minor_status=None): - self.major_status = self.MAJOR_STATUS_CHOICES[self.CLOSED] - if minor_status is None: - self.minor_status = self.MINOR_STATUS_CHOICES[self.CLOSED]["other"] - else: - self.minor_status = self.MINOR_STATUS_CHOICES[self.CLOSED][minor_status] - self.save() - - def set_unchecked(self): - self.major_status = self.MAJOR_STATUS_CHOICES[self.DISABLED] - self.minor_status = self.MINOR_STATUS_CHOICES[self.DISABLED]["unchecked"] - self.save() - - def set_active(self): - self.major_status = self.MAJOR_STATUS_CHOICES[self.ACTIVE] - self.minor_status = self.MINOR_STATUS_CHOICES[self.ACTIVE]["searching"] - self.save() - - class SexChoices(models.TextChoices): FEMALE = "F", _("Weiblich") MALE = "M", _("Männlich") diff --git a/src/fellchensammlung/tools/admin.py b/src/fellchensammlung/tools/admin.py index 1753ba1..36e2318 100644 --- a/src/fellchensammlung/tools/admin.py +++ b/src/fellchensammlung/tools/admin.py @@ -1,6 +1,8 @@ import logging from random import randint + +from fellchensammlung.tools.model_helpers import AdoptionNoticeStatusChoices from notfellchen import settings from django.utils import timezone from datetime import timedelta @@ -86,7 +88,8 @@ def deactivate_404_adoption_notices(): for adoption_notice in get_active_adoption_notices(): if adoption_notice.further_information and adoption_notice.further_information != "": if is_404(adoption_notice.further_information): - adoption_notice.set_closed() + adoption_notice.adoption_notice_status = AdoptionNoticeStatusChoices.Closed.LINK_TO_MORE_INFO_NOT_REACHABLE + adoption_notice.save() logging_msg = f"Automatically set Adoption Notice {adoption_notice.id} closed as link to more information returened 404" logging.info(logging_msg) Log.objects.create(action="automated", text=logging_msg) diff --git a/src/fellchensammlung/tools/metrics.py b/src/fellchensammlung/tools/metrics.py index 36a05d4..32f6756 100644 --- a/src/fellchensammlung/tools/metrics.py +++ b/src/fellchensammlung/tools/metrics.py @@ -9,14 +9,14 @@ def gather_metrics_data(): """Adoption notices""" num_adoption_notices = AdoptionNotice.objects.count() adoption_notices_active = AdoptionNotice.objects.filter( - adoptionnoticestatus=AdoptionNoticeStatusChoices.all_choices()) # TODO fix + adoption_notice_status__in=AdoptionNoticeStatusChoices.Active.values) num_adoption_notices_active = adoption_notices_active.count() num_adoption_notices_closed = AdoptionNotice.objects.filter( - adoptionnoticestatus=AdoptionNoticeStatusChoices.all_choices()) # TODO fix + adoption_notice_status__in=AdoptionNoticeStatusChoices.Closed.values).count() num_adoption_notices_disabled = AdoptionNotice.objects.filter( - adoptionnoticestatus=AdoptionNoticeStatusChoices.all_choices()) # TODO fix + adoption_notice_status__in=AdoptionNoticeStatusChoices.Disabled.values).count() num_adoption_notices_awaiting_action = AdoptionNotice.objects.filter( - adoptionnoticestatus=AdoptionNoticeStatusChoices.all_choices()) # TODO fix + adoption_notice_status__in=AdoptionNoticeStatusChoices.AwaitingAction.values).count() adoption_notices_without_location = AdoptionNotice.objects.filter(location__isnull=True).count() diff --git a/src/fellchensammlung/tools/model_helpers.py b/src/fellchensammlung/tools/model_helpers.py index f8e8dec..1a7df4e 100644 --- a/src/fellchensammlung/tools/model_helpers.py +++ b/src/fellchensammlung/tools/model_helpers.py @@ -89,6 +89,7 @@ class AdoptionNoticeStatusChoices: ANIMAL_DIED = "closed_animal_died", _("Animal died") FOR_OTHER_ADOPTION_NOTICE = "closed_for_other_adoption_notice", _("Closed for other adoption notice") NOT_OPEN_ANYMORE = "closed_not_open_for_adoption_anymore", _("Not open for adoption anymore") + LINK_TO_MORE_INFO_NOT_REACHABLE = "closed_link_to_more_info_not_reachable", _("Der Link zu weiteren Informationen ist nicht mehr erreichbar.") OTHER = "closed_other", _("Other (closed)") class Descriptions: diff --git a/src/fellchensammlung/tools/notifications.py b/src/fellchensammlung/tools/notifications.py index 91ed028..faf1814 100644 --- a/src/fellchensammlung/tools/notifications.py +++ b/src/fellchensammlung/tools/notifications.py @@ -1,9 +1,9 @@ -from fellchensammlung.models import User, Notification, TrustLevel +from fellchensammlung.models import User, Notification, TrustLevel, AdoptionNoticeStatusChoices from fellchensammlung.models import NotificationTypeChoices as ntc def notify_of_AN_to_be_checked(adoption_notice): - if adoption_notice.is_disabled_unchecked: + if adoption_notice.adoption_notice_status == AdoptionNoticeStatusChoices.AwaitingAction.WAITING_FOR_REVIEW: users_to_notify = set(User.objects.filter(trust_level__gt=TrustLevel.MODERATOR)) users_to_notify.add(adoption_notice.owner) for user in users_to_notify: diff --git a/src/fellchensammlung/tools/search.py b/src/fellchensammlung/tools/search.py index 21bbc25..55c6860 100644 --- a/src/fellchensammlung/tools/search.py +++ b/src/fellchensammlung/tools/search.py @@ -2,6 +2,7 @@ import logging from django.utils.translation import gettext_lazy as _ from .geo import LocationProxy, Position +from .model_helpers import AdoptionNoticeStatusChoices from ..forms import AdoptionNoticeSearchForm, RescueOrgSearchForm from ..models import SearchSubscription, AdoptionNotice, SexChoicesWithAll, Location, \ Notification, NotificationTypeChoices, RescueOrganization @@ -95,9 +96,8 @@ class AdoptionNoticeSearch: return True def get_adoption_notices(self): - adoptions = AdoptionNotice.objects.order_by("-created_at") - # Filter for active adoption notices - adoptions = [adoption for adoption in adoptions if adoption.is_active] + adoptions = AdoptionNotice.objects.filter( + adoption_notice_status__in=AdoptionNoticeStatusChoices.Active.values).order_by("-created_at") # Check if adoption notice fits search. adoptions = [adoption for adoption in adoptions if self.adoption_notice_fits_search(adoption)] diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index b231629..c8416b2 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -59,9 +59,8 @@ def fail_if_user_not_owner_or_trust_level(user, django_object, trust_level=Trust def index(request): """View function for home page of site.""" - latest_adoption_list = AdoptionNotice.objects.filter( - adoption_notice_status__in=AdoptionNoticeStatusChoices.Active.choices).order_by("-created_at") - active_adoptions = [adoption for adoption in latest_adoption_list if adoption.is_active] + active_adoptions = AdoptionNotice.objects.filter( + adoption_notice_status__in=AdoptionNoticeStatusChoices.Active.values).order_by("-created_at") language_code = translation.get_language() lang = Language.objects.get(languagecode=language_code) active_announcements = Announcement.get_active_announcements(lang) @@ -102,9 +101,13 @@ def handle_an_check_actions(request, action, adoption_notice=None): return render(request, "fellchensammlung/errors/403.html", status=403) if action == "checked_inactive": - adoption_notice.set_closed() + adoption_notice.adoption_notice_status = AdoptionNoticeStatusChoices.Closed.NOT_OPEN_ANYMORE + adoption_notice.last_checked = timezone.now() + adoption_notice.save() elif action == "checked_active": - adoption_notice.set_active() + adoption_notice.adoption_notice_status = AdoptionNoticeStatusChoices.Active.SEARCHING + adoption_notice.last_checked = timezone.now() + adoption_notice.save() return None @@ -286,9 +289,10 @@ def add_adoption_notice(request): an_instance.owner = request.user if request.user.trust_level >= TrustLevel.MODERATOR: - an_instance.set_active() + an_instance.adoption_notice_status = AdoptionNoticeStatusChoices.Active.SEARCHING else: - an_instance.set_unchecked() + an_instance.adoption_notice_status = AdoptionNoticeStatusChoices.AwaitingAction.WAITING_FOR_REVIEW + an_instance.save() # Get the species and number of animals from the form species = form.cleaned_data["species"] @@ -660,7 +664,8 @@ def updatequeue(request): else: last_checked_adoption_list = AdoptionNotice.objects.filter(owner=request.user).order_by("last_checked") adoption_notices_active = [adoption for adoption in last_checked_adoption_list if adoption.is_active] - adoption_notices_disabled = [adoption for adoption in last_checked_adoption_list if adoption.is_disabled_unchecked] + adoption_notices_disabled = [adoption for adoption in last_checked_adoption_list if + adoption.adoption_notice_status == AdoptionNoticeStatusChoices.Disabled.UNCHECKED] context = {"adoption_notices_disabled": adoption_notices_disabled, "adoption_notices_active": adoption_notices_active} return render(request, 'fellchensammlung/updatequeue.html', context=context) @@ -922,7 +927,10 @@ def deactivate_an(request, adoption_notice_id): adoption_notice = get_object_or_404(AdoptionNotice, pk=adoption_notice_id) if request.method == "POST": reason_for_closing = request.POST.get("reason_for_closing") - adoption_notice.set_closed(reason_for_closing) + if reason_for_closing not in AdoptionNoticeStatusChoices.Closed.choices: + return render(request, "fellchensammlung/errors/403.html", status=403) + adoption_notice.adoption_notice_status = reason_for_closing + adoption_notice.save() return redirect(reverse("adoption-notice-detail", args=[adoption_notice.pk], )) context = {"adoption_notice": adoption_notice, } return render(request, 'fellchensammlung/misc/deactivate-an.html', context=context) diff --git a/src/tests/test_admin_tasks.py b/src/tests/test_admin_tasks.py index 780c9f8..321e2b7 100644 --- a/src/tests/test_admin_tasks.py +++ b/src/tests/test_admin_tasks.py @@ -8,6 +8,7 @@ from django.test import TestCase from model_bakery import baker from fellchensammlung.models import AdoptionNotice, RescueOrganization +from fellchensammlung.tools.model_helpers import AdoptionNoticeStatusChoices class DeactivationTest(TestCase): @@ -25,10 +26,10 @@ class DeactivationTest(TestCase): name="TestAdoption3", created_at=less_than_three_weeks_ago) - cls.adoption1.set_active() + cls.adoption1.adoption_notice_status = AdoptionNoticeStatusChoices.Active.SEARCHING cls.adoption1.last_checked = more_than_three_weeks_ago # Reset updated_at to simulate test conditions cls.adoption1.save() - cls.adoption3.set_active() + cls.adoption3.adoption_notice_status = AdoptionNoticeStatusChoices.Active.SEARCHING cls.adoption3.last_checked = less_than_three_weeks_ago # Reset updated_at to simulate test conditions cls.adoption3.save() @@ -67,20 +68,20 @@ class PingTest(TestCase): name="TestAdoption1", created_at=less_than_three_weeks_ago, last_checked=less_than_three_weeks_ago, - further_information=link_active) + further_information=link_active, + adoption_notice_status=AdoptionNoticeStatusChoices.Active.SEARCHING) cls.adoption2 = baker.make(AdoptionNotice, name="TestAdoption2", created_at=less_than_three_weeks_ago, last_checked=less_than_three_weeks_ago, - further_information=link_inactive) + further_information=link_inactive, + adoption_notice_status=AdoptionNoticeStatusChoices.Active.SEARCHING) cls.adoption3 = baker.make(AdoptionNotice, name="TestAdoption3", created_at=less_than_three_weeks_ago, last_checked=less_than_three_weeks_ago, - further_information=None) - cls.adoption1.set_active() - cls.adoption2.set_active() - cls.adoption3.set_active() + further_information=None, + adoption_notice_status=AdoptionNoticeStatusChoices.Active.SEARCHING) def test_is_404(self): urls = [("https://hyteck.de/maxwell", True), diff --git a/src/tests/test_search.py b/src/tests/test_search.py index 73f6a2f..3ebceef 100644 --- a/src/tests/test_search.py +++ b/src/tests/test_search.py @@ -7,7 +7,7 @@ from fellchensammlung.models import SearchSubscription, User, TrustLevel, Adopti from model_bakery import baker from fellchensammlung.tools.geo import LocationProxy -from fellchensammlung.tools.model_helpers import NotificationTypeChoices +from fellchensammlung.tools.model_helpers import NotificationTypeChoices, AdoptionNoticeStatusChoices from fellchensammlung.tools.search import AdoptionNoticeSearch, notify_search_subscribers @@ -45,7 +45,7 @@ class TestSearch(TestCase): species=rat, sex=SexChoices.MALE, description="Eine unglaublich süße Ratte") - cls.adoption1.set_active() + cls.adoption1.adoption_notice_status = AdoptionNoticeStatusChoices.Active.SEARCHING cls.adoption2 = baker.make(AdoptionNotice, name="TestAdoption2", owner=cls.test_user0, location=cls.location_berlin) rat2 = baker.make(Animal, @@ -54,7 +54,7 @@ class TestSearch(TestCase): species=rat, sex=SexChoices.FEMALE, description="Eine unglaublich süße Ratte") - cls.adoption2.set_active() + cls.adoption2.adoption_notice_status = AdoptionNoticeStatusChoices.Active.SEARCHING cls.subscription1 = SearchSubscription.objects.create(owner=cls.test_user1, location=cls.location_tue, diff --git a/src/tests/test_tools_notifications.py b/src/tests/test_tools_notifications.py index e189f73..34c1f87 100644 --- a/src/tests/test_tools_notifications.py +++ b/src/tests/test_tools_notifications.py @@ -2,7 +2,7 @@ from django.test import TestCase from model_bakery import baker from fellchensammlung.models import User, TrustLevel, Species, Location, AdoptionNotice, Notification -from fellchensammlung.tools.model_helpers import NotificationTypeChoices +from fellchensammlung.tools.model_helpers import NotificationTypeChoices, AdoptionNoticeStatusChoices from fellchensammlung.tools.notifications import notify_of_AN_to_be_checked @@ -26,7 +26,7 @@ class TestNotifications(TestCase): 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.adoption_notice_status = AdoptionNoticeStatusChoices.AwaitingAction.WAITING_FOR_REVIEW def test_notify_of_AN_to_be_checked(self): notify_of_AN_to_be_checked(self.adoption1) diff --git a/src/tests/test_views/test_advanced_views.py b/src/tests/test_views/test_advanced_views.py index 14e74cd..62d88bf 100644 --- a/src/tests/test_views/test_advanced_views.py +++ b/src/tests/test_views/test_advanced_views.py @@ -1,14 +1,11 @@ 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, Location, AdoptionNoticeStatus, TrustLevel, \ - 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 +from fellchensammlung.models import Species, AdoptionNotice, User, Location, TrustLevel, \ + Animal, Subscriptions, Comment, Notification +from fellchensammlung.tools.model_helpers import NotificationTypeChoices, AdoptionNoticeStatusChoices class AnimalAndAdoptionTest(TestCase): @@ -158,7 +155,7 @@ class UpdateQueueTest(TestCase): # Make sure correct status is set and AN is not shown anymore self.assertNotContains(response, "TestAdoption3") self.assertFalse(self.adoption3.is_active) - self.assertEqual(self.adoption3.adoptionnoticestatus.major_status, AdoptionNoticeStatus.CLOSED) + self.assertTrue(self.adoption3.is_closed) class AdoptionDetailTest(TestCase): @@ -189,8 +186,8 @@ class AdoptionDetailTest(TestCase): adoption3.location = stuttgart adoption3.save() - adoption1.set_active() - adoption3.set_active() + adoption1.adoption_notice_status = AdoptionNoticeStatusChoices.Active.SEARCHING + adoption3.adoption_notice_status = AdoptionNoticeStatusChoices.Active.INTERESTED adoption2.set_unchecked() def test_basic_view(self): diff --git a/src/tests/test_views/test_basic_views.py b/src/tests/test_views/test_basic_views.py index 37fdb5e..b84e45b 100644 --- a/src/tests/test_views/test_basic_views.py +++ b/src/tests/test_views/test_basic_views.py @@ -6,6 +6,8 @@ from fellchensammlung.models import User, TrustLevel, AdoptionNotice, Species, R Location, ImportantLocation from model_bakery import baker +from fellchensammlung.tools.model_helpers import AdoptionNoticeStatusChoices + class BasicViewTest(TestCase): @classmethod @@ -26,7 +28,10 @@ class BasicViewTest(TestCase): for i in range(0, 8): ans.append(baker.make(AdoptionNotice, name=f"TestAdoption{i}")) for i in range(0, 4): - AdoptionNotice.objects.get(name=f"TestAdoption{i}").set_active() + adoption_notice = AdoptionNotice.objects.get(name=f"TestAdoption{i}") + adoption_notice.adoption_notice_status = AdoptionNoticeStatusChoices.Active.SEARCHING + adoption_notice.save() + rule1 = Rule.objects.create(title="Rule 1", rule_text="Description of r1", rule_identifier="rule1", language=Language.objects.get(name="English")) diff --git a/src/tests/test_views/test_search.py b/src/tests/test_views/test_search.py index 81d752c..4f885fc 100644 --- a/src/tests/test_views/test_search.py +++ b/src/tests/test_views/test_search.py @@ -4,11 +4,8 @@ from django.urls import reverse from model_bakery import baker -from fellchensammlung.models import Animal, Species, AdoptionNotice, User, Location, AdoptionNoticeStatus, TrustLevel, \ - 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 +from fellchensammlung.models import AdoptionNotice, User, Location, SearchSubscription +from fellchensammlung.tools.model_helpers import AdoptionNoticeStatusChoices class SearchTest(TestCase): @@ -28,9 +25,11 @@ class SearchTest(TestCase): # Location of Berlin: lat 52.5170365 lon 13.3888599 PLZ 10115 (Mitte) - adoption1 = baker.make(AdoptionNotice, name="TestAdoption1") + adoption1 = baker.make(AdoptionNotice, name="TestAdoption1", + adoption_notice_status=AdoptionNoticeStatusChoices.Active.SEARCHING) adoption2 = baker.make(AdoptionNotice, name="TestAdoption2") - adoption3 = baker.make(AdoptionNotice, name="TestAdoption3") + adoption3 = baker.make(AdoptionNotice, name="TestAdoption3", + adoption_notice_status=AdoptionNoticeStatusChoices.Active.INTERESTED) berlin = Location.get_location_from_string("Berlin") adoption1.location = berlin @@ -40,8 +39,6 @@ class SearchTest(TestCase): adoption3.location = stuttgart adoption3.save() - adoption1.set_active() - adoption3.set_active() adoption2.set_unchecked() cls.subscription1 = SearchSubscription.objects.create(owner=test_user1,