Change notificationworker test to pytest
This commit is contained in:
parent
50c2f1fde8
commit
8ec198228c
1 changed files with 25 additions and 38 deletions
|
@ -1,45 +1,32 @@
|
||||||
import unittest
|
|
||||||
|
|
||||||
from data import model
|
from data import model
|
||||||
from workers.notificationworker import NotificationWorker
|
from workers.notificationworker.notificationworker import NotificationWorker
|
||||||
from initdb import setup_database_for_testing, finished_database_for_testing
|
from test.fixtures import *
|
||||||
|
|
||||||
class NotificationWorkerTests(unittest.TestCase):
|
def test_basic_notification(initialized_db):
|
||||||
def setUp(self):
|
# Ensure the public user doesn't have any notifications.
|
||||||
setup_database_for_testing(self)
|
target_user = model.user.get_user('public')
|
||||||
|
assert len(list(model.notification.list_notifications(target_user))) == 0
|
||||||
|
|
||||||
def tearDown(self):
|
# Add a basic build notification.
|
||||||
finished_database_for_testing(self)
|
repo = model.repository.get_repository('devtable', 'simple')
|
||||||
|
method_data = {
|
||||||
def test_basic_notification(self):
|
'target': {
|
||||||
# Ensure the public user doesn't have any notifications.
|
'kind': 'user',
|
||||||
target_user = model.user.get_user('public')
|
'name': 'public',
|
||||||
self.assertEquals(0, len(list(model.notification.list_notifications(target_user))))
|
|
||||||
|
|
||||||
# Add a basic build notification.
|
|
||||||
repo = model.repository.get_repository('devtable', 'simple')
|
|
||||||
method_data = {
|
|
||||||
'target': {
|
|
||||||
'kind': 'user',
|
|
||||||
'name': 'public',
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
notification = model.notification.create_repo_notification(repo, 'build_success',
|
}
|
||||||
'quay_notification', method_data, {})
|
notification = model.notification.create_repo_notification(repo, 'build_success',
|
||||||
|
'quay_notification', method_data, {})
|
||||||
|
|
||||||
notification_uuid = notification.uuid
|
notification_uuid = notification.uuid
|
||||||
event_data = {}
|
event_data = {}
|
||||||
|
|
||||||
# Fire off the queue processing.
|
# Fire off the queue processing.
|
||||||
worker = NotificationWorker(None)
|
worker = NotificationWorker(None)
|
||||||
worker.process_queue_item({
|
worker.process_queue_item({
|
||||||
'notification_uuid': notification_uuid,
|
'notification_uuid': notification_uuid,
|
||||||
'event_data': event_data,
|
'event_data': event_data,
|
||||||
})
|
})
|
||||||
|
|
||||||
# Ensure the notification was handled.
|
# Ensure the notification was handled.
|
||||||
self.assertEquals(1, len(list(model.notification.list_notifications(target_user))))
|
assert len(list(model.notification.list_notifications(target_user))) == 1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
|
Reference in a new issue