-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_update_request_publisher_rejected_notify.py
77 lines (59 loc) · 3.07 KB
/
test_update_request_publisher_rejected_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from portality import models
from portality import constants
from portality.bll import exceptions
from doajtest.helpers import DoajTestCase
from portality.events.consumers.update_request_publisher_rejected_notify import UpdateRequestPublisherRejectedNotify
from doajtest.fixtures import ApplicationFixtureFactory
import time
class TestUpdateRequestPublisherRejectedNotify(DoajTestCase):
def setUp(self):
super(TestUpdateRequestPublisherRejectedNotify, self).setUp()
def tearDown(self):
super(TestUpdateRequestPublisherRejectedNotify, self).tearDown()
def test_should_consume(self):
source = ApplicationFixtureFactory.make_application_source()
event = models.Event(constants.EVENT_APPLICATION_STATUS, context={"application" : source, "old_status" : "in progress", "new_status": "rejected"})
assert UpdateRequestPublisherRejectedNotify.should_consume(event)
event = models.Event(constants.EVENT_APPLICATION_STATUS,
context={"old_status": "rejected", "new_status": "rejected"})
assert not UpdateRequestPublisherRejectedNotify.should_consume(event)
event = models.Event("test:event", context={"application" : "2345"})
assert not UpdateRequestPublisherRejectedNotify.should_consume(event)
event = models.Event(constants.EVENT_APPLICATION_STATUS)
assert not UpdateRequestPublisherRejectedNotify.should_consume(event)
def test_consume_success(self):
self._make_and_push_test_context("/")
acc = models.Account()
acc.set_id("publisher")
acc.set_email("test@example.com")
acc.save(blocking=True)
source = ApplicationFixtureFactory.make_application_source()
event = models.Event(constants.EVENT_APPLICATION_STATUS, context={"application" : source, "old_status": "in progress", "new_status": "rejected"})
UpdateRequestPublisherRejectedNotify.consume(event)
time.sleep(1)
ns = models.Notification.all()
assert len(ns) == 1
n = ns[0]
assert n.who == "publisher"
assert n.created_by == UpdateRequestPublisherRejectedNotify.ID
assert n.classification == constants.NOTIFICATION_CLASSIFICATION_STATUS_CHANGE
assert n.long is not None
assert n.short is not None
assert not n.is_seen()
def test_consume_fail(self):
# application model error
event = models.Event(constants.EVENT_APPLICATION_STATUS, context={"application": {"key" : "value"}})
with self.assertRaises(exceptions.NoSuchObjectException):
UpdateRequestPublisherRejectedNotify.consume(event)
# no owner
source = ApplicationFixtureFactory.make_application_source()
del source["admin"]["owner"]
event = models.Event(constants.EVENT_APPLICATION_STATUS, context={
"application": source,
"old_status": "in progress",
"new_status": "rejected"
})
UpdateRequestPublisherRejectedNotify.consume(event)
time.sleep(1)
ns = models.Notification.all()
assert len(ns) == 0