7
7
:license: Apache License 2.0
8
8
"""
9
9
10
+ # Standard library
11
+ import json
12
+ import unittest
13
+
10
14
# Tests utilities
11
15
from tests .utilities import UtilityServer
12
16
13
17
# JSON-RPC library
14
18
import jsonrpclib
15
19
16
- # Standard library
17
- import json
18
- import unittest
19
-
20
20
# ------------------------------------------------------------------------------
21
21
22
22
@@ -41,39 +41,65 @@ def tearDown(self):
41
41
self .server .stop ()
42
42
43
43
def get_client (self ):
44
- return jsonrpclib .ServerProxy ('http://localhost:{0}' .format (self .port ),
45
- history = self .history )
44
+ """
45
+ Utility method to get a proxy to the test server
46
+ """
47
+ return jsonrpclib .ServerProxy (
48
+ "http://localhost:{0}" .format (self .port ),
49
+ history = self .history
50
+ )
46
51
47
52
def get_multicall_client (self ):
53
+ """
54
+ Utility method to get a multi-call proxy to the test server
55
+ """
48
56
server = self .get_client ()
49
57
return jsonrpclib .MultiCall (server )
50
58
51
59
def test_connect (self ):
60
+ """
61
+ Simple Ping() test
62
+ """
52
63
client = self .get_client ()
53
64
result = client .ping ()
54
65
self .assertTrue (result )
55
66
56
67
def test_single_args (self ):
68
+ """
69
+ Positional arguments test
70
+ """
57
71
client = self .get_client ()
58
72
result = client .add (5 , 10 )
59
73
self .assertTrue (result == 15 )
60
74
61
75
def test_single_kwargs (self ):
76
+ """
77
+ Keyword-arguments test
78
+ """
62
79
client = self .get_client ()
63
80
result = client .add (x = 5 , y = 10 )
64
81
self .assertTrue (result == 15 )
65
82
66
83
def test_single_kwargs_and_args (self ):
84
+ """
85
+ Mixed positional/keyword args failure test
86
+ """
67
87
client = self .get_client ()
68
88
self .assertRaises (jsonrpclib .ProtocolError ,
69
89
client .add , (5 ,), {'y' : 10 })
70
90
71
91
def test_single_notify (self ):
92
+ """
93
+ Notification test
94
+ """
72
95
client = self .get_client ()
73
96
result = client ._notify .add (5 , 10 )
74
97
self .assertTrue (result is None )
75
98
76
99
def test_single_namespace (self ):
100
+ """
101
+ Namespace test
102
+ """
77
103
client = self .get_client ()
78
104
client .namespace .sum (1 , 2 , 4 )
79
105
request = json .loads (self .history .request )
@@ -89,6 +115,9 @@ def test_single_namespace(self):
89
115
self .assertTrue (verify_response == response )
90
116
91
117
def test_multicall_success (self ):
118
+ """
119
+ Multi-call test
120
+ """
92
121
multicall = self .get_multicall_client ()
93
122
multicall .ping ()
94
123
multicall .add (5 , 10 )
@@ -99,13 +128,19 @@ def test_multicall_success(self):
99
128
self .assertTrue (result == correct [i ])
100
129
101
130
def test_multicall_success_2 (self ):
131
+ """
132
+ Another multi-call test
133
+ """
102
134
multicall = self .get_multicall_client ()
103
135
for i in range (3 ):
104
136
multicall .add (5 , i )
105
137
result = multicall ()
106
138
self .assertTrue (result [2 ] == 7 )
107
139
108
140
def test_multicall_failure (self ):
141
+ """
142
+ Multi-call test with failures
143
+ """
109
144
multicall = self .get_multicall_client ()
110
145
multicall .ping ()
111
146
multicall .add (x = 5 , y = 10 , z = 10 )
0 commit comments