@@ -66,6 +66,10 @@ def test_empty(self):
6666 self .assertTrue (response .empty )
6767 self .assertEqual (response .peek (10 ), "" )
6868 self .assertEqual (response .read (10 ), "" )
69+
70+ arr = bytearray (10 )
71+ self .assertEqual (response .readinto (arr ), 0 )
72+ self .assertEqual (arr , bytearray (10 ))
6973 self .assertTrue (response .empty )
7074
7175 def test_read_past_end (self ):
@@ -87,6 +91,42 @@ def test_read_partial(self):
8791 self .assertTrue (response .empty )
8892 self .assertEqual (response .read (), '' )
8993
94+ def test_readable (self ):
95+ txt = "abcd"
96+ response = binding .ResponseReader (StringIO (txt ))
97+ self .assertTrue (response .readable ())
98+
99+ def test_readinto_bytearray (self ):
100+ txt = "Checking readinto works as expected"
101+ response = binding .ResponseReader (StringIO (txt ))
102+ arr = bytearray (10 )
103+ self .assertEqual (response .readinto (arr ), 10 )
104+ self .assertEqual (arr [:10 ], "Checking r" )
105+ self .assertEqual (response .readinto (arr ), 10 )
106+ self .assertEqual (arr [:10 ], "eadinto wo" )
107+ self .assertEqual (response .readinto (arr ), 10 )
108+ self .assertEqual (arr [:10 ], "rks as exp" )
109+ self .assertEqual (response .readinto (arr ), 5 )
110+ self .assertEqual (arr [:5 ], "ected" )
111+ self .assertTrue (response .empty )
112+
113+ def test_readinto_memoryview (self ):
114+ txt = "Checking readinto works as expected"
115+ response = binding .ResponseReader (StringIO (txt ))
116+ arr = bytearray (10 )
117+ mv = memoryview (arr )
118+ self .assertEqual (response .readinto (mv ), 10 )
119+ self .assertEqual (arr [:10 ], "Checking r" )
120+ self .assertEqual (response .readinto (mv ), 10 )
121+ self .assertEqual (arr [:10 ], "eadinto wo" )
122+ self .assertEqual (response .readinto (mv ), 10 )
123+ self .assertEqual (arr [:10 ], "rks as exp" )
124+ self .assertEqual (response .readinto (mv ), 5 )
125+ self .assertEqual (arr [:5 ], "ected" )
126+ self .assertTrue (response .empty )
127+
128+
129+
90130class TestUrlEncoded (BindingTestCase ):
91131 def test_idempotent (self ):
92132 a = UrlEncoded ('abc' )
@@ -95,7 +135,7 @@ def test_idempotent(self):
95135 def test_append (self ):
96136 self .assertEqual (UrlEncoded ('a' ) + UrlEncoded ('b' ),
97137 UrlEncoded ('ab' ))
98-
138+
99139 def test_append_string (self ):
100140 self .assertEqual (UrlEncoded ('a' ) + '%' ,
101141 UrlEncoded ('a%' ))
@@ -111,15 +151,15 @@ def test_chars(self):
111151 for char , code in [(' ' , '%20' ),
112152 ('"' , '%22' ),
113153 ('%' , '%25' )]:
114- self .assertEqual (UrlEncoded (char ),
154+ self .assertEqual (UrlEncoded (char ),
115155 UrlEncoded (code , skip_encode = True ))
116156
117157 def test_repr (self ):
118158 self .assertEqual (repr (UrlEncoded ('% %' )), "UrlEncoded('% %')" )
119159
120160class TestAuthority (unittest .TestCase ):
121161 def test_authority_default (self ):
122- self .assertEqual (binding ._authority (),
162+ self .assertEqual (binding ._authority (),
123163 "https://localhost:8089" )
124164
125165 def test_ipv4_host (self ):
@@ -137,7 +177,7 @@ def test_ipv6_host(self):
137177 def test_all_fields (self ):
138178 self .assertEqual (
139179 binding ._authority (
140- scheme = "http" ,
180+ scheme = "http" ,
141181 host = "splunk.utopia.net" ,
142182 port = "471" ),
143183 "http://splunk.utopia.net:471" )
@@ -172,7 +212,7 @@ def test_user_without_role_fails(self):
172212
173213 def test_create_user (self ):
174214 response = self .context .post (
175- PATH_USERS , name = self .username ,
215+ PATH_USERS , name = self .username ,
176216 password = self .password , roles = self .roles )
177217 self .assertEqual (response .status , 201 )
178218
@@ -265,7 +305,7 @@ def test_without_autologin(self):
265305 self .context .autologin = False
266306 self .assertEqual (self .context .get ("/services" ).status , 200 )
267307 self .context .logout ()
268- self .assertRaises (AuthenticationError ,
308+ self .assertRaises (AuthenticationError ,
269309 self .context .get , "/services" )
270310
271311class TestAbspath (BindingTestCase ):
@@ -403,7 +443,7 @@ def isatom(body):
403443class TestPluggableHTTP (testlib .SDKTestCase ):
404444 # Verify pluggable HTTP reqeust handlers.
405445 def test_handlers (self ):
406- paths = ["/services" , "authentication/users" ,
446+ paths = ["/services" , "authentication/users" ,
407447 "search/jobs" ]
408448 handlers = [binding .handler (), # default handler
409449 urllib2_handler ]
@@ -421,7 +461,7 @@ def test_logout(self):
421461 response = self .context .get ("/services" )
422462 self .assertEqual (response .status , 200 )
423463 self .context .logout ()
424- self .assertRaises (AuthenticationError ,
464+ self .assertRaises (AuthenticationError ,
425465 self .context .get , "/services" )
426466 self .assertRaises (AuthenticationError ,
427467 self .context .post , "/services" )
@@ -512,11 +552,11 @@ def test_preexisting_token(self):
512552 opts ["token" ] = token
513553 opts ["username" ] = "boris the mad baboon"
514554 opts ["password" ] = "nothing real"
515-
555+
516556 newContext = binding .Context (** opts )
517557 response = newContext .get ("/services" )
518558 self .assertEqual (response .status , 200 )
519-
559+
520560 socket = newContext .connect ()
521561 socket .write ("POST %s HTTP/1.1\r \n " % \
522562 self .context ._abspath ("some/path/to/post/to" ))
0 commit comments