Refactors how notifications are generated. (#584)
This commit is contained in:
@ -23,21 +23,48 @@ def test_needs_notification(app, certificate, notification):
|
||||
assert needs_notification(certificate)
|
||||
|
||||
|
||||
def test_get_certificates(app, certificate, notification):
|
||||
from lemur.notifications.messaging import get_certificates
|
||||
delta = certificate.not_after - timedelta(days=2)
|
||||
with freeze_time(delta.datetime):
|
||||
# no notification
|
||||
certs = len(get_certificates())
|
||||
|
||||
# with notification
|
||||
certificate.notifications.append(notification)
|
||||
assert len(get_certificates()) > certs
|
||||
|
||||
certificate.notify = False
|
||||
assert len(get_certificates()) == certs
|
||||
|
||||
# expired
|
||||
delta = certificate.not_after + timedelta(days=2)
|
||||
with freeze_time(delta.datetime):
|
||||
certificate.notifications.append(notification)
|
||||
assert len(get_certificates()) == 0
|
||||
|
||||
|
||||
def test_get_eligible_certificates(app, certificate, notification):
|
||||
from lemur.notifications.messaging import get_eligible_certificates
|
||||
|
||||
certificate.notifications.append(notification)
|
||||
certificate.notifications[0].options = [{'name': 'interval', 'value': 10}, {'name': 'unit', 'value': 'days'}]
|
||||
|
||||
delta = certificate.not_after - timedelta(days=10)
|
||||
with freeze_time(delta.datetime):
|
||||
assert get_eligible_certificates() == {certificate.owner: {notification.label: [(notification, certificate)]}}
|
||||
|
||||
|
||||
@mock_ses
|
||||
def test_send_expiration_notification(certificate, notification, notification_plugin):
|
||||
from lemur.notifications.messaging import send_expiration_notifications
|
||||
notification.options = [{'name': 'interval', 'value': 10}, {'name': 'unit', 'value': 'days'}]
|
||||
|
||||
certificate.notifications.append(notification)
|
||||
certificate.notifications[0].options = [{'name': 'interval', 'value': 10}, {'name': 'unit', 'value': 'days'}]
|
||||
|
||||
delta = certificate.not_after - timedelta(days=10)
|
||||
|
||||
with freeze_time(delta.datetime):
|
||||
sent = send_expiration_notifications()
|
||||
assert sent == 1
|
||||
|
||||
certificate.notify = False
|
||||
|
||||
sent = send_expiration_notifications()
|
||||
assert sent == 0
|
||||
assert send_expiration_notifications() == (2, 0)
|
||||
|
||||
|
||||
@mock_ses
|
||||
|
Reference in New Issue
Block a user