Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better moderation reminders. #586

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion joboffers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
)
)
)
16 changes: 9 additions & 7 deletions joboffers/tests/test_notify-pending_moderation_offers.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
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
notify_pending_moderation_offers
)
from .factories import JobOfferFactory
from .fixtures import create_telegram_dummy # noqa


@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):
"""
Test expiration of old joboffers command
"""
"""Expiration of old joboffers command."""
today = timezone.now()
two_hundred_days_ago = today - timedelta(days=200)
JobOfferFactory.create()
Expand All @@ -35,6 +37,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=2
))
Loading