Refactors the default notification option. Also ensures that notifications and destinations are easier to test. (#437)
This commit is contained in:
@ -46,7 +46,6 @@ LEMUR_DEFAULT_LOCATION = 'Los Gatos'
|
||||
LEMUR_DEFAULT_ORGANIZATION = 'Example, Inc.'
|
||||
LEMUR_DEFAULT_ORGANIZATIONAL_UNIT = 'Example'
|
||||
|
||||
|
||||
# Database
|
||||
|
||||
# modify this if you are not using a local database
|
||||
@ -54,7 +53,6 @@ SQLALCHEMY_DATABASE_URI = 'postgresql://lemur:lemur@localhost:5432/lemur'
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
# AWS
|
||||
|
||||
LEMUR_INSTANCE_PROFILE = 'Lemur'
|
||||
|
||||
# Issuers
|
||||
|
@ -140,6 +140,22 @@ def issuer_plugin():
|
||||
return TestIssuerPlugin
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def notification_plugin():
|
||||
from lemur.plugins.base import register
|
||||
from .plugins.notification_plugin import TestNotificationPlugin
|
||||
register(TestNotificationPlugin)
|
||||
return TestNotificationPlugin
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def destination_plugin():
|
||||
from lemur.plugins.base import register
|
||||
from .plugins.destination_plugin import TestDestinationPlugin
|
||||
register(TestDestinationPlugin)
|
||||
return TestDestinationPlugin
|
||||
|
||||
|
||||
@pytest.yield_fixture(scope="function")
|
||||
def logged_in_user(session, app):
|
||||
with app.test_request_context():
|
||||
|
@ -137,7 +137,7 @@ class AuthorityFactory(BaseFactory):
|
||||
|
||||
class DestinationFactory(BaseFactory):
|
||||
"""Destination factory."""
|
||||
plugin_name = Sequence(lambda n: 'destination{0}'.format(n))
|
||||
plugin_name = 'test-destination'
|
||||
label = Sequence(lambda n: 'destination{0}'.format(n))
|
||||
|
||||
class Meta:
|
||||
@ -147,7 +147,7 @@ class DestinationFactory(BaseFactory):
|
||||
|
||||
class NotificationFactory(BaseFactory):
|
||||
"""Notification factory."""
|
||||
plugin_name = Sequence(lambda n: 'notification{0}'.format(n))
|
||||
plugin_name = 'test-notification'
|
||||
label = Sequence(lambda n: 'notification{0}'.format(n))
|
||||
|
||||
class Meta:
|
||||
|
16
lemur/tests/plugins/destination_plugin.py
Normal file
16
lemur/tests/plugins/destination_plugin.py
Normal file
@ -0,0 +1,16 @@
|
||||
from lemur.plugins.bases import DestinationPlugin
|
||||
|
||||
|
||||
class TestDestinationPlugin(DestinationPlugin):
|
||||
title = 'Test'
|
||||
slug = 'test-destination'
|
||||
description = 'Enables testing'
|
||||
|
||||
author = 'Kevin Glisson'
|
||||
author_url = 'https://github.com/netflix/lemur.git'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(TestDestinationPlugin, self).__init__(*args, **kwargs)
|
||||
|
||||
def upload(self, name, body, private_key, cert_chain, options, **kwargs):
|
||||
return
|
17
lemur/tests/plugins/notification_plugin.py
Normal file
17
lemur/tests/plugins/notification_plugin.py
Normal file
@ -0,0 +1,17 @@
|
||||
from lemur.plugins.bases import NotificationPlugin
|
||||
|
||||
|
||||
class TestNotificationPlugin(NotificationPlugin):
|
||||
title = 'Test'
|
||||
slug = 'test-notification'
|
||||
description = 'Enables testing'
|
||||
|
||||
author = 'Kevin Glisson'
|
||||
author_url = 'https://github.com/netflix/lemur.git'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(TestNotificationPlugin, self).__init__(*args, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def send(event_type, message, targets, options, **kwargs):
|
||||
return
|
@ -6,7 +6,7 @@ from lemur.destinations.views import * # noqa
|
||||
from .vectors import VALID_ADMIN_HEADER_TOKEN, VALID_USER_HEADER_TOKEN
|
||||
|
||||
|
||||
def test_destination_input_schema(client, destination):
|
||||
def test_destination_input_schema(client, destination_plugin, destination):
|
||||
from lemur.destinations.schemas import DestinationInputSchema
|
||||
|
||||
input_data = {
|
||||
@ -15,7 +15,7 @@ def test_destination_input_schema(client, destination):
|
||||
'description': 'my destination',
|
||||
'active': True,
|
||||
'plugin': {
|
||||
'slug': 'aws-destination'
|
||||
'slug': 'test-destination'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ from lemur.notifications.views import * # noqa
|
||||
from .vectors import VALID_ADMIN_HEADER_TOKEN, VALID_USER_HEADER_TOKEN
|
||||
|
||||
|
||||
def test_notification_input_schema(client, notification):
|
||||
def test_notification_input_schema(client, notification_plugin, notification):
|
||||
from lemur.notifications.schemas import NotificationInputSchema
|
||||
|
||||
input_data = {
|
||||
@ -15,7 +15,7 @@ def test_notification_input_schema(client, notification):
|
||||
'description': 'my notification',
|
||||
'active': True,
|
||||
'plugin': {
|
||||
'slug': 'email-notification'
|
||||
'slug': 'test-notification'
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ def test_notification_input_schema(client, notification):
|
||||
(VALID_ADMIN_HEADER_TOKEN, 200),
|
||||
('', 401)
|
||||
])
|
||||
def test_notification_get(client, token, status):
|
||||
assert client.get(api.url_for(Notifications, notification_id=1), headers=token).status_code == status
|
||||
def test_notification_get(client, notification_plugin, notification, token, status):
|
||||
assert client.get(api.url_for(Notifications, notification_id=notification.id), headers=token).status_code == status
|
||||
|
||||
|
||||
@pytest.mark.parametrize("token,status", [
|
||||
@ -83,7 +83,7 @@ def test_notification_list_post_(client, token, status):
|
||||
(VALID_ADMIN_HEADER_TOKEN, 200),
|
||||
('', 401)
|
||||
])
|
||||
def test_notification_list_get(client, token, status):
|
||||
def test_notification_list_get(client, notification_plugin, notification, token, status):
|
||||
assert client.get(api.url_for(NotificationsList), headers=token).status_code == status
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user