From 87ae71dd0a0c4dcf83a41cb6d728371590deaf47 Mon Sep 17 00:00:00 2001 From: Facundo Batista Date: Thu, 25 Jan 2024 13:47:01 -0300 Subject: [PATCH 1/3] Better moderation reminders. --- joboffers/constants.py | 2 +- .../commands/notify_pending_moderation_offers.py | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/joboffers/constants.py b/joboffers/constants.py index 72345b8..32ca3b1 100644 --- a/joboffers/constants.py +++ b/joboffers/constants.py @@ -127,7 +127,7 @@ OFFER_EXPIRATION_DAYS = 180 -PENDING_MODERATION_OFFER_DAYS = 2 +PENDING_MODERATION_OFFER_DAYS = 0 TELEGRAM_MODERATION_MESSAGE = _('La oferta {offer_url} necesita ser moderada.') TELEGRAM_APPROVED_MESSAGE = _('La oferta {offer_url} fue aprobada por {username}.') diff --git a/joboffers/management/commands/notify_pending_moderation_offers.py b/joboffers/management/commands/notify_pending_moderation_offers.py index 453e1a9..0ceb252 100644 --- a/joboffers/management/commands/notify_pending_moderation_offers.py +++ b/joboffers/management/commands/notify_pending_moderation_offers.py @@ -15,13 +15,13 @@ def notify_pending_moderation_offers(): """ expiration_date = timezone.now() - timedelta(days=PENDING_MODERATION_OFFER_DAYS) joboffers = JobOffer.objects.filter( - state=OfferState.MODERATION, modified_at__lte=expiration_date + state=OfferState.MODERATION, modified_at__lte=expiration_date ) for joboffer in joboffers: message = TELEGRAM_PENDING_MODERATION_MESSAGE.format( - offer_url=joboffer.get_absolute_url(), - moderation_reminder_days=PENDING_MODERATION_OFFER_DAYS + offer_url=joboffer.get_full_url(), + moderation_reminder_days=PENDING_MODERATION_OFFER_DAYS ) send_notification_to_moderators(message) @@ -38,9 +38,8 @@ def handle(self, *args, **options): offers_notifed = notify_pending_moderation_offers() self.stdout.write( - self.style.SUCCESS( - _('Se enviaron {offers_notified} recordatorios de moderaciĆ³n.').format( - offers_notified=offers_notifed + self.style.SUCCESS( + _('Se enviaron {offers_notified} recordatorios de moderaciĆ³n.').format( + offers_notified=offers_notifed) ) - ) ) From 4084b0ea51f7438744d833432d785d0fd21560bf Mon Sep 17 00:00:00 2001 From: Facundo Batista Date: Thu, 25 Jan 2024 20:07:33 -0300 Subject: [PATCH 2/3] Fixed test. --- .../tests/test_notify-pending_moderation_offers.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/joboffers/tests/test_notify-pending_moderation_offers.py b/joboffers/tests/test_notify-pending_moderation_offers.py index 900f4ad..d52035e 100644 --- a/joboffers/tests/test_notify-pending_moderation_offers.py +++ b/joboffers/tests/test_notify-pending_moderation_offers.py @@ -7,7 +7,7 @@ from joboffers.constants import PENDING_MODERATION_OFFER_DAYS, TELEGRAM_PENDING_MODERATION_MESSAGE from joboffers.models import JobOffer, OfferState from joboffers.management.commands.notify_pending_moderation_offers import ( - notify_pending_moderation_offers + notify_pending_moderation_offers ) from .factories import JobOfferFactory from .fixtures import create_telegram_dummy # noqa @@ -15,9 +15,7 @@ @pytest.mark.django_db def test_remind_offers_in_moderation(telegram_dummy): - """ - Test expiration of old joboffers command - """ + """Expiration of old joboffers command.""" today = timezone.now() two_hundred_days_ago = today - timedelta(days=200) JobOfferFactory.create() @@ -35,6 +33,6 @@ def test_remind_offers_in_moderation(telegram_dummy): assert offers_notified == 1 assert len(telegram_history) == 1 assert sent_message.endswith(TELEGRAM_PENDING_MODERATION_MESSAGE.format( - offer_url=offer2.get_absolute_url(), - moderation_reminder_days=PENDING_MODERATION_OFFER_DAYS + offer_url=offer2.get_full_url(), + moderation_reminder_days=PENDING_MODERATION_OFFER_DAYS )) From 89d766c8a81a2d938140318a9060ccf174546edd Mon Sep 17 00:00:00 2001 From: Facundo Batista Date: Fri, 26 Jan 2024 20:16:55 -0300 Subject: [PATCH 3/3] Patch the constant so it's testeable. --- joboffers/tests/test_notify-pending_moderation_offers.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/joboffers/tests/test_notify-pending_moderation_offers.py b/joboffers/tests/test_notify-pending_moderation_offers.py index d52035e..192addd 100644 --- a/joboffers/tests/test_notify-pending_moderation_offers.py +++ b/joboffers/tests/test_notify-pending_moderation_offers.py @@ -1,10 +1,11 @@ import pytest from datetime import timedelta +from unittest.mock import patch from django.utils import timezone -from joboffers.constants import PENDING_MODERATION_OFFER_DAYS, TELEGRAM_PENDING_MODERATION_MESSAGE +from joboffers.constants import TELEGRAM_PENDING_MODERATION_MESSAGE from joboffers.models import JobOffer, OfferState from joboffers.management.commands.notify_pending_moderation_offers import ( notify_pending_moderation_offers @@ -14,6 +15,9 @@ @pytest.mark.django_db +@patch( + "joboffers.management.commands.notify_pending_moderation_offers.PENDING_MODERATION_OFFER_DAYS", + 2) def test_remind_offers_in_moderation(telegram_dummy): """Expiration of old joboffers command.""" today = timezone.now() @@ -34,5 +38,5 @@ def test_remind_offers_in_moderation(telegram_dummy): assert len(telegram_history) == 1 assert sent_message.endswith(TELEGRAM_PENDING_MODERATION_MESSAGE.format( offer_url=offer2.get_full_url(), - moderation_reminder_days=PENDING_MODERATION_OFFER_DAYS + moderation_reminder_days=2 ))