Change get_sample_data API to not require the custom notification tuple
This commit is contained in:
parent
e7dbc4ee91
commit
e7fec9dd20
3 changed files with 21 additions and 31 deletions
|
@ -8,10 +8,10 @@ from endpoints.api import (RepositoryParamResource, nickname, resource, require_
|
|||
path_param, disallow_for_app_repositories)
|
||||
from endpoints.exception import NotFound
|
||||
from notifications import build_notification_data
|
||||
from notifications.models_interface import Repository
|
||||
from notifications.notificationevent import NotificationEvent
|
||||
from notifications.notificationmethod import (NotificationMethod,
|
||||
CannotValidateNotificationMethodException)
|
||||
from workers.notificationworker.models_pre_oci import notification
|
||||
from endpoints.api.repositorynotification_models_pre_oci import pre_oci_model as model
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -153,6 +153,8 @@ class TestRepositoryNotification(RepositoryParamResource):
|
|||
def post(self, namespace_name, repository_name, uuid):
|
||||
""" Queues a test notification for this repository. """
|
||||
test_note = model.queue_test_notification(uuid)
|
||||
event_info = NotificationEvent.get_event(test_note.event_name)
|
||||
sample_data = event_info.get_sample_data(Repository(namespace, repository), event_config)
|
||||
|
||||
if not test_note:
|
||||
raise InvalidRequest("No repository notification found for: %s, %s, %s" % (namespace_name, repository_name, uuid))
|
||||
|
|
|
@ -40,7 +40,7 @@ class NotificationEvent(object):
|
|||
'notification_data': notification_data
|
||||
})
|
||||
|
||||
def get_sample_data(self, notification):
|
||||
def get_sample_data(self, repository, event_config):
|
||||
"""
|
||||
Returns sample data for testing the raising of this notification, with an example notification.
|
||||
"""
|
||||
|
@ -95,8 +95,8 @@ class RepoPushEvent(NotificationEvent):
|
|||
def get_summary(self, event_data, notification_data):
|
||||
return 'Repository %s updated' % (event_data['repository'])
|
||||
|
||||
def get_sample_data(self, notification):
|
||||
return build_event_data(notification.repository, {
|
||||
def get_sample_data(self, repository, event_config):
|
||||
return build_event_data(repository, {
|
||||
'updated_tags': {'latest': 'someimageid', 'foo': 'anotherimage'},
|
||||
'pruned_image_count': 3
|
||||
})
|
||||
|
@ -129,10 +129,9 @@ class VulnerabilityFoundEvent(NotificationEvent):
|
|||
|
||||
return 'info'
|
||||
|
||||
def get_sample_data(self, notification):
|
||||
event_config = notification.event_config_dict
|
||||
def get_sample_data(self, repository, event_config):
|
||||
level = event_config.get(VulnerabilityFoundEvent.CONFIG_LEVEL, 'Critical')
|
||||
return build_event_data(notification.repository, {
|
||||
return build_event_data(repository, {
|
||||
'tags': ['latest', 'prod', 'foo', 'bar', 'baz'],
|
||||
'image': 'some-image-id',
|
||||
'vulnerability': {
|
||||
|
@ -217,9 +216,9 @@ class BuildQueueEvent(BaseBuildEvent):
|
|||
def get_level(self, event_data, notification_data):
|
||||
return 'info'
|
||||
|
||||
def get_sample_data(self, notification):
|
||||
def get_sample_data(self, repository, event_config):
|
||||
build_uuid = 'fake-build-id'
|
||||
return build_event_data(notification.repository, {
|
||||
return build_event_data(repository, {
|
||||
'is_manual': False,
|
||||
'build_id': build_uuid,
|
||||
'build_name': 'some-fake-build',
|
||||
|
@ -255,9 +254,9 @@ class BuildStartEvent(BaseBuildEvent):
|
|||
def get_level(self, event_data, notification_data):
|
||||
return 'info'
|
||||
|
||||
def get_sample_data(self, notification):
|
||||
def get_sample_data(self, repository, event_config):
|
||||
build_uuid = 'fake-build-id'
|
||||
return build_event_data(notification.repository, {
|
||||
return build_event_data(repository, {
|
||||
'build_id': build_uuid,
|
||||
'build_name': 'some-fake-build',
|
||||
'docker_tags': ['latest', 'foo', 'bar'],
|
||||
|
@ -282,9 +281,9 @@ class BuildSuccessEvent(BaseBuildEvent):
|
|||
def get_level(self, event_data, notification_data):
|
||||
return 'success'
|
||||
|
||||
def get_sample_data(self, notification):
|
||||
def get_sample_data(self, repository, event_config):
|
||||
build_uuid = 'fake-build-id'
|
||||
return build_event_data(notification.repository, {
|
||||
return build_event_data(repository, {
|
||||
'build_id': build_uuid,
|
||||
'build_name': 'some-fake-build',
|
||||
'docker_tags': ['latest', 'foo', 'bar'],
|
||||
|
@ -310,9 +309,9 @@ class BuildFailureEvent(BaseBuildEvent):
|
|||
def get_level(self, event_data, notification_data):
|
||||
return 'error'
|
||||
|
||||
def get_sample_data(self, notification):
|
||||
def get_sample_data(self, repository, event_config):
|
||||
build_uuid = 'fake-build-id'
|
||||
return build_event_data(notification.repository, {
|
||||
return build_event_data(repository, {
|
||||
'build_id': build_uuid,
|
||||
'build_name': 'some-fake-build',
|
||||
'docker_tags': ['latest', 'foo', 'bar'],
|
||||
|
@ -349,9 +348,9 @@ class BuildCancelledEvent(BaseBuildEvent):
|
|||
def get_level(self, event_data, notification_data):
|
||||
return 'info'
|
||||
|
||||
def get_sample_data(self, notification):
|
||||
def get_sample_data(self, repository, event_config):
|
||||
build_uuid = 'fake-build-id'
|
||||
return build_event_data(notification.repository, {
|
||||
return build_event_data(repository, {
|
||||
'build_id': build_uuid,
|
||||
'build_name': 'some-fake-build',
|
||||
'docker_tags': ['latest', 'foo', 'bar'],
|
||||
|
|
|
@ -1,25 +1,14 @@
|
|||
from notifications.models_interface import Repository
|
||||
from notifications.notificationevent import NotificationEvent
|
||||
from util.morecollections import AttrDict
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
def test_all_notifications(app):
|
||||
# Create a test notification.
|
||||
test_notification = AttrDict({
|
||||
'repository': AttrDict({
|
||||
'namespace_name': AttrDict(dict(username='foo')),
|
||||
'name': 'bar',
|
||||
}),
|
||||
'event_config_dict': {
|
||||
'level': 'low',
|
||||
},
|
||||
})
|
||||
|
||||
def test_all_notifications(initialized_db):
|
||||
for subc in NotificationEvent.__subclasses__():
|
||||
if subc.event_name() is not None:
|
||||
# Create the notification event.
|
||||
found = NotificationEvent.get_event(subc.event_name())
|
||||
sample_data = found.get_sample_data(test_notification)
|
||||
sample_data = found.get_sample_data(Repository('foo', 'bar'), {'level': 'low'})
|
||||
|
||||
# Make sure all calls succeed.
|
||||
notification_data = {
|
||||
|
|
Reference in a new issue