Correct typo and enable Slack notification test

This commit is contained in:
Jasmine Schladen 2020-10-16 17:08:44 -07:00
parent 6a1889787d
commit e90b08b363
2 changed files with 26 additions and 18 deletions

View File

@ -217,9 +217,9 @@ def send_rotation_notification(certificate, notification_plugin=None):
notification_plugin.send("rotation", data, [data["owner"]], [])
status = SUCCESS_METRIC_STATUS
except Exception as e:
log_data["message"] = "Unable to send rotation notification for certificate {0} to ownner {1}" \
log_data["message"] = "Unable to send rotation notification for certificate {0} to owner {1}" \
.format(certificate.name, data["owner"])
current_app.logger.error(log_data)
current_app.logger.error(log_data, exc_info=True)
sentry.captureException()
metrics.send(

View File

@ -1,3 +1,10 @@
from datetime import timedelta
import arrow
from lemur.tests.factories import NotificationFactory, CertificateFactory
def test_formatting(certificate):
from lemur.plugins.lemur_slack.plugin import create_expiration_attachments
from lemur.certificates.schemas import certificate_notification_output_schema
@ -27,32 +34,33 @@ def get_options():
return [
{"name": "interval", "value": 10},
{"name": "unit", "value": "days"},
{"name": "webhook", "value": "https://slack.com/api/api.test"},
]
# Currently disabled as we have no good way to mock Slack webhooks
# def test_send_expiration_notification():
# from lemur.notifications.messaging import send_expiration_notifications
# from lemur.tests.factories import CertificateFactory
#
# now = arrow.utcnow()
# in_ten_days = now + timedelta(days=10, hours=1) # a bit more than 10 days since we'll check in the future
# certificate = CertificateFactory()
# notification = NotificationFactory(plugin_name="slack-notification")
#
# certificate.not_after = in_ten_days
# certificate.notifications.append(notification)
# certificate.notifications[0].options = get_options()
#
# assert send_expiration_notifications([]) == (2, 0)
def test_send_expiration_notification():
from lemur.notifications.messaging import send_expiration_notifications
notification = NotificationFactory(plugin_name="slack-notification")
notification.options = get_options()
now = arrow.utcnow()
in_ten_days = now + timedelta(days=10, hours=1) # a bit more than 10 days since we'll check in the future
certificate = CertificateFactory()
certificate.not_after = in_ten_days
certificate.notifications.append(notification)
assert send_expiration_notifications([]) == (2, 0)
# Currently disabled as we have no good way to mock Slack webhooks
# Currently disabled as the Slack plugin doesn't support this type of notification
# def test_send_rotation_notification(endpoint, source_plugin):
# from lemur.notifications.messaging import send_rotation_notification
# from lemur.deployment.service import rotate_certificate
#
# notification = NotificationFactory(plugin_name="slack-notification")
# notification.options = get_options()
#
# new_certificate = CertificateFactory()
# rotate_certificate(endpoint, new_certificate)