-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_bg_job_finished_notify.py
59 lines (46 loc) · 2.04 KB
/
test_bg_job_finished_notify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from portality import models
from portality import constants
from portality.bll import exceptions
from doajtest.helpers import DoajTestCase
from portality.events.consumers.bg_job_finished_notify import BGJobFinishedNotify
from doajtest.fixtures import BackgroundFixtureFactory
import time
class TestBGJobFinishedNotify(DoajTestCase):
def setUp(self):
super(TestBGJobFinishedNotify, self).setUp()
def tearDown(self):
super(TestBGJobFinishedNotify, self).tearDown()
def test_should_consume(self):
event = models.Event(constants.BACKGROUND_JOB_FINISHED, context={"job" : {}})
assert BGJobFinishedNotify.should_consume(event)
event = models.Event("test:event", context={"job" : "2345"})
assert not BGJobFinishedNotify.should_consume(event)
event = models.Event(constants.BACKGROUND_JOB_FINISHED)
assert not BGJobFinishedNotify.should_consume(event)
def test_consume_success(self):
self._make_and_push_test_context("/")
source = BackgroundFixtureFactory.example()
bj = models.BackgroundJob(**source)
# bj.save(blocking=True)
acc = models.Account()
acc.set_id('testuser')
acc.set_email("test@example.com")
acc.add_role('admin')
acc.save(blocking=True)
event = models.Event(constants.BACKGROUND_JOB_FINISHED, context={"job" : bj.data})
BGJobFinishedNotify.consume(event)
time.sleep(1)
ns = models.Notification.all()
assert len(ns) == 1
n = ns[0]
assert n.who == acc.id
assert n.created_by == BGJobFinishedNotify.ID
assert n.classification == constants.NOTIFICATION_CLASSIFICATION_FINISHED
assert n.long is not None
assert n.short is not None
assert n.action is not None
assert not n.is_seen()
def test_consume_fail(self):
event = models.Event(constants.BACKGROUND_JOB_FINISHED, context={"job": "abcd"})
with self.assertRaises(exceptions.NoSuchObjectException):
BGJobFinishedNotify.consume(event)