-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_dispatcher.py
86 lines (68 loc) · 2.95 KB
/
test_dispatcher.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
77
78
79
80
81
82
83
84
85
86
# Import dummy notifs for testing
from constants import DUMMY_USER_DICT
# Factory variant creators.
from Models.ConcreteFactory import email_notif_factory, post_notif_factory, sms_notif_factory
# Custom exceptions
from Exceptions import invalid_email_req, invalid_post_req, invalid_sms_req
import unittest
from dispatcher import Dispatcher
desc = '''
This unittest verifies instance relation.
Since the project uses Factory design pattern for object modelling,
it's important to make sure objects are rightly created and are instances
of the subclass they are supposed to be of.
'''
class TestDispatcher(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dummy = DUMMY_USER_DICT
def test_email_dispatcher(self):
# JSON with all valid attributes.
target = TestDispatcher.dummy.get("valid_user_email")
testIn, testOut = target.get("in").getData(), target.get("out")
self.assertEqual(
Dispatcher(notif_object=testIn).push_notification(),
testOut
)
# JSON with only valid attributes
target = TestDispatcher.dummy.get("none_but_essential_emailnotif")
testIn, testOut = target.get("in").getData(), target.get("out")
self.assertEqual(
Dispatcher(notif_object=testIn).push_notification(),
testOut
)
# JSON with missing email.
target = TestDispatcher.dummy.get("no_email")
testIn, testOut = target.get("in").getData(), target.get("out")
# Since exception is handled before returning to client code,
# using assertIsInstance() rather than assertRaises() ...
self.assertIsInstance(
Dispatcher(notif_object=testIn).push_notification(),
(Exception, invalid_email_req.InvalidEmailReq)
)
def test_sms_dispatcher(self):
# JSON with all valid attributes.
target = TestDispatcher.dummy.get("valid_user_sms")
testIn, testOut = target.get("in").getData(), target.get("out")
self.assertEqual(
Dispatcher(notif_object=testIn).push_notification(),
testOut
)
# # JSON with only valid attributes
# target = TestDispatcher.dummy.get("none_but_essential_emailnotif")
# testIn, testOut = target.get("in").getData(), target.get("out")
# self.assertEqual(
# Dispatcher(notif_object=testIn).push_notification(),
# testOut
# )
# # JSON with missing email.
# target = TestDispatcher.dummy.get("no_email")
# testIn, testOut = target.get("in").getData(), target.get("out")
# # Since exception is handled before returning to client code,
# # using assertIsInstance() rather than assertRaises() ...
# self.assertIsInstance(
# Dispatcher(notif_object=testIn).push_notification(),
# (Exception, invalid_email_req.InvalidEmailReq)
# )
if __name__ == '__main__':
unittest.main()