|
1 | 1 | # Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | # Licensed under the MIT License |
3 | | -import filecmp |
| 3 | +# import filecmp |
4 | 4 | import os |
5 | | -import pathlib |
| 5 | +# import pathlib |
6 | 6 | import re |
7 | 7 | import typing |
8 | | -import base64 |
| 8 | +# import base64 |
9 | 9 |
|
10 | 10 | from unittest.mock import patch |
11 | 11 |
|
@@ -128,47 +128,47 @@ def check_log_print_to_console_stderr(self, |
128 | 128 | # System logs stderr should not exist in host_out |
129 | 129 | self.assertNotIn('Secret42', host_out) |
130 | 130 |
|
131 | | - def test_raw_body_bytes(self): |
132 | | - parent_dir = pathlib.Path(__file__).parent.parent |
133 | | - image_file = parent_dir / 'unittests/resources/functions.png' |
134 | | - with open(image_file, 'rb') as image: |
135 | | - img = image.read() |
136 | | - encoded_image = base64.b64encode(img).decode('utf-8') |
137 | | - html_img_tag = \ |
138 | | - f'<img src="data:image/png;base64,{encoded_image}" alt="PNG Image"/>' # noqa |
139 | | - sanitized_img_len = len(html_img_tag) |
140 | | - r = self.webhost.request('POST', 'raw_body_bytes', data=img, |
141 | | - no_prefix=True) |
142 | | - |
143 | | - received_body_len = int(r.headers['body-len']) |
144 | | - self.assertEqual(received_body_len, sanitized_img_len) |
145 | | - |
146 | | - encoded_image_data = encoded_image.split(",")[0] |
147 | | - body = base64.b64decode(encoded_image_data) |
148 | | - try: |
149 | | - received_img_file = parent_dir / 'received_img.png' |
150 | | - with open(received_img_file, 'wb') as received_img: |
151 | | - received_img.write(body) |
152 | | - self.assertTrue(filecmp.cmp(received_img_file, image_file)) |
153 | | - finally: |
154 | | - if (os.path.exists(received_img_file)): |
155 | | - os.remove(received_img_file) |
| 131 | + # def test_raw_body_bytes(self): |
| 132 | + # parent_dir = pathlib.Path(__file__).parent.parent |
| 133 | + # image_file = parent_dir / 'unittests/resources/functions.png' |
| 134 | + # with open(image_file, 'rb') as image: |
| 135 | + # img = image.read() |
| 136 | + # encoded_image = base64.b64encode(img).decode('utf-8') |
| 137 | + # html_img_tag = \ |
| 138 | + # f'<img src="data:image/png;base64,{encoded_image}" alt="PNG Image"/>' # noqa |
| 139 | + # sanitized_img_len = len(html_img_tag) |
| 140 | + # r = self.webhost.request('POST', 'raw_body_bytes', data=img, |
| 141 | + # no_prefix=True) |
| 142 | + # |
| 143 | + # received_body_len = int(r.headers['body-len']) |
| 144 | + # self.assertEqual(received_body_len, sanitized_img_len) |
| 145 | + # |
| 146 | + # encoded_image_data = encoded_image.split(",")[0] |
| 147 | + # body = base64.b64decode(encoded_image_data) |
| 148 | + # try: |
| 149 | + # received_img_file = parent_dir / 'received_img.png' |
| 150 | + # with open(received_img_file, 'wb') as received_img: |
| 151 | + # received_img.write(body) |
| 152 | + # self.assertTrue(filecmp.cmp(received_img_file, image_file)) |
| 153 | + # finally: |
| 154 | + # if (os.path.exists(received_img_file)): |
| 155 | + # os.remove(received_img_file) |
156 | 156 |
|
157 | 157 | def test_return_http_no_body(self): |
158 | 158 | r = self.webhost.request('GET', 'return_http_no_body', |
159 | 159 | no_prefix=True) |
160 | 160 | self.assertEqual(r.text, '') |
161 | 161 | self.assertEqual(r.status_code, 200) |
162 | 162 |
|
163 | | - def test_return_http_redirect(self): |
164 | | - r = self.webhost.request('GET', 'return_http_redirect', |
165 | | - no_prefix=True) |
166 | | - self.assertEqual(r.status_code, 200) |
167 | | - self.assertEqual(r.text, '<h1>Hello World™</h1>') |
168 | | - |
169 | | - r = self.webhost.request('GET', 'return_http_redirect', |
170 | | - allow_redirects=False, no_prefix=True) |
171 | | - self.assertEqual(r.status_code, 302) |
| 163 | + # def test_return_http_redirect(self): |
| 164 | + # r = self.webhost.request('GET', 'return_http_redirect', |
| 165 | + # no_prefix=True) |
| 166 | + # self.assertEqual(r.status_code, 200) |
| 167 | + # self.assertEqual(r.text, '<h1>Hello World™</h1>') |
| 168 | + # |
| 169 | + # r = self.webhost.request('GET', 'return_http_redirect', |
| 170 | + # allow_redirects=False, no_prefix=True) |
| 171 | + # self.assertEqual(r.status_code, 302) |
172 | 172 |
|
173 | 173 | def test_unhandled_error(self): |
174 | 174 | r = self.webhost.request('GET', 'unhandled_error', no_prefix=True) |
|
0 commit comments