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
Matt Griswold 5147028bee clean up / format / poetry (#1000)
* stub in poetry for pipenv

* re-add tester image

* add pre-commit / formatting

* fix ghactions

* revert test data whitespace, exclude tests/data

* revert ws

* decruft, rm tox/pipenv

* install dev packages for base image

* add lgtm config to force to py3
2021-07-10 10:12:35 -05:00

39 lines
1.1 KiB
Python

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):
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