-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_ActiveClient.py
More file actions
130 lines (106 loc) · 4.14 KB
/
test_ActiveClient.py
File metadata and controls
130 lines (106 loc) · 4.14 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python2
from client_lib import ActiveClient, InvalidClient, ClientManager
import unittest
class ClientManagerCase(unittest.TestCase):
def test_create_ClientManager_instance(self):
try:
cm = ClientManager() # noqa
except NameError:
self.fail("Can't create a ClientManager class")
def test_new_client(self):
cm = ClientManager()
client = cm.new_client()
self.assertIsInstance(client, ActiveClient)
def test_get_client(self):
cm = ClientManager()
client = cm.new_client()
client2 = cm.get_client(client.id)
self.assertEquals(client, client2)
def test_clean_list(self):
cm = ClientManager()
client = cm.new_client()
old_timeout = ActiveClient.CLIENT_TIMEOUT
ActiveClient.CLIENT_TIMEOUT = 0
client = cm.get_client(client.id)
ActiveClient.CLIENT_TIMEOUT = old_timeout
self.assertIsNone(client)
class InvalidClientCase(unittest.TestCase):
def test_create_InvalidClient_class(self):
try:
ac = InvalidClient('123') # noqa
except NameError:
self.fail("Can't create an InvalidClient class")
class ActiveClientCase(unittest.TestCase):
'''test all things to do with the ActiveClient class'''
def test_create_ActiveClient_instance(self):
try:
ac = ActiveClient('123') # noqa
except NameError:
self.fail("Can't create an ActiveClient class")
def test_id_arg(self):
ac_id = '123'
ac = ActiveClient(ac_id)
self.assertEquals(ac.id, ac_id)
def test_creation_time(self):
import datetime
ac = ActiveClient('123')
delta = datetime.datetime.now() - ac.creation_time
self.assertLess(delta.seconds, 2)
def test_first_path(self):
ac = ActiveClient('123')
self.assertEqual(len(ac.path_index), 1)
def test_path_depth_not_found(self):
ac = ActiveClient('123')
self.assertEqual(ac.get_path_depth('not_in_there'), -1)
def test_get_next_path_first(self):
ac = ActiveClient('123')
title, path = ac.get_next_path()
self.assertEqual(path, ac.path_index[0])
def test_get_next_path_ordering(self):
ac = ActiveClient('123')
title1, path1 = ac.get_next_path()
title2, path2 = ac.get_next_path(path1)
title1_again, path1_again = ac.get_next_path()
self.assertEqual(path1, path1_again)
self.assertNotEqual(path1, path2)
def test_validate_path_exists(self):
ac = ActiveClient('123')
title, path = ac.get_next_path()
self.assertTrue(ac.validate_path(path))
def test_validate_path_not_exists(self):
ac = ActiveClient('123')
self.assertFalse(ac.validate_path('not_in_there'))
def test_link_titles(self):
ac = ActiveClient('123')
paths = []
next_path = ac.get_next_path()
while next_path:
title, path = next_path
paths.append(title)
next_path = ac.get_next_path(path)
self.assertEqual(set(paths), set(ActiveClient.LINK_TITLES))
def test_is_valid(self):
ac = ActiveClient('123')
self.assertTrue(ac.is_valid())
def test_timeout(self):
ac = ActiveClient('123')
old_timeout = ActiveClient.CLIENT_TIMEOUT
ActiveClient.CLIENT_TIMEOUT = 0
self.assertFalse(ac.is_valid())
with self.assertRaises(InvalidClient):
ac.get_next_path()
with self.assertRaises(InvalidClient):
ac.get_path_depth('123')
with self.assertRaises(InvalidClient):
ac.validate_path('123')
ActiveClient.CLIENT_TIMEOUT = old_timeout
def test_random_link_titles(self):
# note: these could fail if we randomize and it comes back with the
# original list sequence
ac1 = ActiveClient('123')
ac2 = ActiveClient('456')
self.assertNotEqual(ac1.my_titles, ac2.my_titles)
self.assertNotEqual(ac1.my_titles, ActiveClient.LINK_TITLES)
self.assertNotEqual(ac2.my_titles, ActiveClient.LINK_TITLES)
if __name__ == '__main__':
unittest.main()