1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/tests/test_cmd_pdb_sponsorship_notify.py

39 lines
1.1 KiB
Python
Raw Normal View History

import random
import string
from datetime import datetime, timedelta, timezone
import pytest
from django.conf import settings
from django.core.management import call_command
from django.test import override_settings
from peeringdb_server.models import Organization, Sponsorship
FIVE_MONTHS_AGO = datetime.now(tz=timezone.utc) - timedelta(days=150)
TWO_MONTHS_AGO = datetime.now(tz=timezone.utc) - timedelta(days=60)
# max number of seconds we allow between running command and asserting date is
# the same
SECONDS_THRESHOLD = 120
@pytest.mark.django_db
@override_settings(SPONSORSHIPS_EMAIL="localhost")
def test_send_email(outdated_sponsorship):
2020-11-04 07:39:15 +00:00
NOW = datetime.now(tz=timezone.utc)
sponsorship = Sponsorship.objects.all()[0]
call_command("pdb_sponsorship_notify")
sponsorship.refresh_from_db()
assert (sponsorship.notify_date - NOW) < timedelta(seconds=SECONDS_THRESHOLD)
@pytest.fixture
def outdated_sponsorship():
# Has not been notified of expiration
org = Sponsorship.objects.create(
start_date=FIVE_MONTHS_AGO,
end_date=TWO_MONTHS_AGO,
notify_date=None,
level=2,
)
return org