@@ -132,48 +132,12 @@ def check_log_print_to_console_stderr(self,
132132 # System logs stderr now exist in host_out
133133 self .assertIn ('Secret42' , host_out )
134134
135- def test_raw_body_bytes (self ):
136- parent_dir = pathlib .Path (__file__ ).parent .parent
137- image_file = parent_dir / 'unittests/resources/functions.png'
138- with open (image_file , 'rb' ) as image :
139- img = image .read ()
140- encoded_image = base64 .b64encode (img ).decode ('utf-8' )
141- html_img_tag = \
142- f'<img src="data:image/png;base64,{ encoded_image } " alt="PNG Image"/>' # noqa
143- sanitized_img_len = len (html_img_tag )
144- r = self .webhost .request ('POST' , 'raw_body_bytes' , data = img ,
145- no_prefix = True )
146-
147- received_body_len = int (r .headers ['body-len' ])
148- self .assertEqual (received_body_len , sanitized_img_len )
149-
150- encoded_image_data = encoded_image .split ("," )[0 ]
151- body = base64 .b64decode (encoded_image_data )
152- try :
153- received_img_file = parent_dir / 'received_img.png'
154- with open (received_img_file , 'wb' ) as received_img :
155- received_img .write (body )
156- self .assertTrue (filecmp .cmp (received_img_file , image_file ))
157- finally :
158- if (os .path .exists (received_img_file )):
159- os .remove (received_img_file )
160-
161135 def test_return_http_no_body (self ):
162136 r = self .webhost .request ('GET' , 'return_http_no_body' ,
163137 no_prefix = True )
164138 self .assertEqual (r .text , '' )
165139 self .assertEqual (r .status_code , 200 )
166140
167- def test_return_http_redirect (self ):
168- r = self .webhost .request ('GET' , 'return_http_redirect' ,
169- no_prefix = True )
170- self .assertEqual (r .status_code , 200 )
171- self .assertEqual (r .text , '<h1>Hello World™</h1>' )
172-
173- r = self .webhost .request ('GET' , 'return_http_redirect' ,
174- allow_redirects = False , no_prefix = True )
175- self .assertEqual (r .status_code , 302 )
176-
177141 def test_unhandled_error (self ):
178142 r = self .webhost .request ('GET' , 'unhandled_error' , no_prefix = True )
179143 self .assertEqual (r .status_code , 500 )
@@ -228,10 +192,46 @@ def check_log_hijack_current_event_loop(self,
228192 self .assertIn ('parallelly_log_system at disguised_logger' ,
229193 host_out )
230194
195+ def test_raw_body_bytes (self ):
196+ parent_dir = pathlib .Path (__file__ ).parent .parent
197+ image_file = parent_dir / 'unittests/resources/functions.png'
198+ with open (image_file , 'rb' ) as image :
199+ img = image .read ()
200+ encoded_image = base64 .b64encode (img ).decode ('utf-8' )
201+ html_img_tag = \
202+ f'<img src="data:image/png;base64,{ encoded_image } " alt="PNG Image"/>' # noqa
203+ sanitized_img_len = len (html_img_tag )
204+ r = self .webhost .request ('POST' , 'raw_body_bytes' , data = img ,
205+ no_prefix = True )
206+
207+ received_body_len = int (r .headers ['body-len' ])
208+ self .assertEqual (received_body_len , sanitized_img_len )
209+
210+ encoded_image_data = encoded_image .split ("," )[0 ]
211+ body = base64 .b64decode (encoded_image_data )
212+ try :
213+ received_img_file = parent_dir / 'received_img.png'
214+ with open (received_img_file , 'wb' ) as received_img :
215+ received_img .write (body )
216+ self .assertTrue (filecmp .cmp (received_img_file , image_file ))
217+ finally :
218+ if (os .path .exists (received_img_file )):
219+ os .remove (received_img_file )
220+
231221
232222class TestWsgiHttpFunctions (
233223 ThirdPartyHttpFunctionsTestBase .TestThirdPartyHttpFunctions ):
234224 @classmethod
235225 def get_script_dir (cls ):
236226 return UNIT_TESTS_ROOT / 'third_party_http_functions' / 'stein' / \
237227 'wsgi_function'
228+
229+ def test_return_http_redirect (self ):
230+ r = self .webhost .request ('GET' , 'return_http_redirect' ,
231+ no_prefix = True )
232+ self .assertEqual (r .status_code , 200 )
233+ self .assertEqual (r .text , '<h1>Hello World™</h1>' )
234+
235+ r = self .webhost .request ('GET' , 'return_http_redirect' ,
236+ allow_redirects = False , no_prefix = True )
237+ self .assertEqual (r .status_code , 302 )
0 commit comments