6
6
from qiniu import conf
7
7
8
8
9
- def round_tripper (client , method , path , body ):
9
+ def round_tripper (client , method , path , body , header = {} ):
10
10
pass
11
11
12
12
13
13
class ClsTestClient (rpc .Client ):
14
14
15
- def round_tripper (self , method , path , body ):
16
- round_tripper (self , method , path , body )
17
- return super (ClsTestClient , self ).round_tripper (method , path , body )
15
+ def round_tripper (self , method , path , body , header = {} ):
16
+ round_tripper (self , method , path , body , header )
17
+ return super (ClsTestClient , self ).round_tripper (method , path , body , header )
18
18
19
19
client = ClsTestClient (conf .RS_HOST )
20
20
@@ -24,7 +24,7 @@ class TestClient(unittest.TestCase):
24
24
def test_call (self ):
25
25
global round_tripper
26
26
27
- def tripper (client , method , path , body ):
27
+ def tripper (client , method , path , body , header = {} ):
28
28
self .assertEqual (path , "/hello" )
29
29
assert body is None
30
30
@@ -34,7 +34,7 @@ def tripper(client, method, path, body):
34
34
def test_call_with (self ):
35
35
global round_tripper
36
36
37
- def tripper (client , method , path , body ):
37
+ def tripper (client , method , path , body , header = {} ):
38
38
self .assertEqual (body , "body" )
39
39
40
40
round_tripper = tripper
@@ -43,16 +43,16 @@ def tripper(client, method, path, body):
43
43
def test_call_with_multipart (self ):
44
44
global round_tripper
45
45
46
- def tripper (client , method , path , body ):
46
+ def tripper (client , method , path , body , header = {} ):
47
47
target_type = "multipart/form-data"
48
48
self .assertTrue (
49
- client . _header ["Content-Type" ].startswith (target_type ))
50
- start_index = client . _header ["Content-Type" ].find ("boundary" )
51
- boundary = client . _header ["Content-Type" ][start_index + 9 :]
49
+ header ["Content-Type" ].startswith (target_type ))
50
+ start_index = header ["Content-Type" ].find ("boundary" )
51
+ boundary = header ["Content-Type" ][start_index + 9 :]
52
52
dispostion = 'Content-Disposition: form-data; name="auth"'
53
53
tpl = "--%s\r \n %s\r \n \r \n %s\r \n --%s--\r \n " % (boundary , dispostion ,
54
54
"auth_string" , boundary )
55
- self .assertEqual (len (tpl ), client . _header ["Content-Length" ])
55
+ self .assertEqual (len (tpl ), header ["Content-Length" ])
56
56
self .assertEqual (len (tpl ), body .length ())
57
57
58
58
round_tripper = tripper
@@ -61,15 +61,26 @@ def tripper(client, method, path, body):
61
61
def test_call_with_form (self ):
62
62
global round_tripper
63
63
64
- def tripper (client , method , path , body ):
64
+ def tripper (client , method , path , body , header = {} ):
65
65
self .assertEqual (body , "action=a&op=a&op=b" )
66
66
target_type = "application/x-www-form-urlencoded"
67
- self .assertEqual (client . _header ["Content-Type" ], target_type )
68
- self .assertEqual (client . _header ["Content-Length" ], len (body ))
67
+ self .assertEqual (header ["Content-Type" ], target_type )
68
+ self .assertEqual (header ["Content-Length" ], len (body ))
69
69
70
70
round_tripper = tripper
71
71
client .call_with_form ("/hello" , dict (op = ["a" , "b" ], action = "a" ))
72
72
73
+ def test_call_after_call_with_form (self ):
74
+ # test case for https://github.com/qiniu/python-sdk/issues/112
75
+ global round_tripper
76
+
77
+ def tripper (client , method , path , body , header = {}):
78
+ pass
79
+
80
+ round_tripper = tripper
81
+ client .call_with_form ("/hello" , dict (op = ["a" , "b" ], action = "a" ))
82
+ client .call ("/hello" )
83
+
73
84
74
85
class TestMultiReader (unittest .TestCase ):
75
86
0 commit comments