5
5
import pathlib
6
6
import re
7
7
import typing
8
- import urllib .parse
8
+ import base64
9
+ import sys
9
10
11
+ from unittest import skipIf
10
12
from unittest .mock import patch
11
13
12
14
from tests .utils import testutils
@@ -113,9 +115,11 @@ def test_print_to_console_stdout(self):
113
115
114
116
def check_log_print_to_console_stdout (self ,
115
117
host_out : typing .List [str ]):
116
- # System logs stdout should not exist in host_out
117
- self .assertNotIn ('Secret42' , host_out )
118
+ # System logs stdout now exist in host_out
119
+ self .assertIn ('Secret42' , host_out )
118
120
121
+ @skipIf (sys .version_info < (3 , 9 , 0 ),
122
+ "Skip the tests for Python 3.8 and below" )
119
123
def test_print_to_console_stderr (self ):
120
124
r = self .webhost .request ('GET' , 'print_logging?console=true'
121
125
'&message=Secret42&is_stderr=true' ,
@@ -125,23 +129,26 @@ def test_print_to_console_stderr(self):
125
129
126
130
def check_log_print_to_console_stderr (self ,
127
131
host_out : typing .List [str ], ):
128
- # System logs stderr should not exist in host_out
129
- self .assertNotIn ('Secret42' , host_out )
132
+ # System logs stderr now exist in host_out
133
+ self .assertIn ('Secret42' , host_out )
130
134
131
135
def test_raw_body_bytes (self ):
132
136
parent_dir = pathlib .Path (__file__ ).parent .parent
133
137
image_file = parent_dir / 'unittests/resources/functions.png'
134
138
with open (image_file , 'rb' ) as image :
135
139
img = image .read ()
136
- sanitized_image = urllib .parse .quote (img )
137
- sanitized_img_len = len (sanitized_image )
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 )
138
144
r = self .webhost .request ('POST' , 'raw_body_bytes' , data = img ,
139
145
no_prefix = True )
140
146
141
147
received_body_len = int (r .headers ['body-len' ])
142
148
self .assertEqual (received_body_len , sanitized_img_len )
143
149
144
- body = urllib .parse .unquote_to_bytes (r .content )
150
+ encoded_image_data = encoded_image .split ("," )[0 ]
151
+ body = base64 .b64decode (encoded_image_data )
145
152
try :
146
153
received_img_file = parent_dir / 'received_img.png'
147
154
with open (received_img_file , 'wb' ) as received_img :
@@ -217,9 +224,9 @@ def check_log_hijack_current_event_loop(self,
217
224
self .assertIn ('parallelly_log_custom at custom_logger' , host_out )
218
225
self .assertIn ('callsoon_log' , host_out )
219
226
220
- # System logs should not exist in host_out
221
- self .assertNotIn ('parallelly_log_system at disguised_logger' ,
222
- host_out )
227
+ # System logs now exist in host_out
228
+ self .assertIn ('parallelly_log_system at disguised_logger' ,
229
+ host_out )
223
230
224
231
225
232
class TestWsgiHttpFunctions (
0 commit comments