|
5 | 5 |
|
6 | 6 | import azure.functions as func |
7 | 7 | import azure.functions.http as http |
| 8 | +from azure.functions._http import HttpResponseHeaders |
8 | 9 |
|
9 | 10 |
|
10 | 11 | class TestHTTP(unittest.TestCase): |
@@ -88,6 +89,53 @@ def test_http_output_type(self): |
88 | 89 | self.assertTrue(check_output_type(func.HttpResponse)) |
89 | 90 | self.assertTrue(check_output_type(str)) |
90 | 91 |
|
| 92 | + def test_http_response_encode_to_datum_no_cookie(self): |
| 93 | + resp = func.HttpResponse() |
| 94 | + datum = http.HttpResponseConverter.encode(resp, expected_type=None) |
| 95 | + |
| 96 | + self.assertEqual(datum.value["cookies"], None) |
| 97 | + |
| 98 | + def test_http_response_encode_to_datum_with_cookies(self): |
| 99 | + headers = HttpResponseHeaders() |
| 100 | + headers.add("Set-Cookie", |
| 101 | + 'foo3=42; Domain=example.com; Expires=Thu, ' |
| 102 | + '12-Jan-2017 13:55:08 GMT; Path=/; Max-Age=10000000') |
| 103 | + headers.add("Set-Cookie", |
| 104 | + 'foo3=43; Domain=example.com; Expires=Thu, 12-Jan-2018 ' |
| 105 | + '13:55:09 GMT; Path=/; Max-Age=10000000') |
| 106 | + resp = func.HttpResponse(headers=headers) |
| 107 | + datum = http.HttpResponseConverter.encode(resp, expected_type=None) |
| 108 | + |
| 109 | + actual_cookies = datum.value['cookies'] |
| 110 | + self.assertIsNotNone(actual_cookies) |
| 111 | + self.assertTrue(isinstance(actual_cookies, list)) |
| 112 | + self.assertTrue(len(actual_cookies), 2) |
| 113 | + self.assertEqual(str(actual_cookies[0]), |
| 114 | + "Set-Cookie: foo3=42; Domain=example.com; " |
| 115 | + "expires=Thu, 12-Jan-2017 13:55:08 GMT; " |
| 116 | + "Max-Age=10000000; Path=/") |
| 117 | + self.assertEqual(str(actual_cookies[1]), |
| 118 | + "Set-Cookie: foo3=43; Domain=example.com; " |
| 119 | + "expires=Thu, 12-Jan-2018 13:55:09 GMT; " |
| 120 | + "Max-Age=10000000; Path=/") |
| 121 | + |
| 122 | + self.assertTrue("Set-Cookie" not in resp.headers) |
| 123 | + |
| 124 | + def test_http_response_encode_to_datum_with_cookies_lower_case(self): |
| 125 | + headers = HttpResponseHeaders() |
| 126 | + headers.add("set-cookie", |
| 127 | + 'foo3=42; Domain=example.com; Path=/; Max-Age=10000.0') |
| 128 | + resp = func.HttpResponse(headers=headers) |
| 129 | + datum = http.HttpResponseConverter.encode(resp, expected_type=None) |
| 130 | + |
| 131 | + actual_cookies = datum.value['cookies'] |
| 132 | + self.assertIsNotNone(actual_cookies) |
| 133 | + self.assertTrue(isinstance(actual_cookies, list)) |
| 134 | + self.assertTrue(len(actual_cookies), 1) |
| 135 | + self.assertEqual(str(actual_cookies[0]), |
| 136 | + "Set-Cookie: foo3=42; Domain=example.com; " |
| 137 | + "Max-Age=10000.0; Path=/") |
| 138 | + |
91 | 139 | def test_http_request_should_not_have_implicit_output(self): |
92 | 140 | self.assertFalse(http.HttpRequestConverter.has_implicit_output()) |
93 | 141 |
|
|
0 commit comments