From 8e5001549d187d9ed37d414fd4895c4094717d0c Mon Sep 17 00:00:00 2001 From: Sasha Kochniev Date: Mon, 6 May 2024 11:42:16 -0400 Subject: [PATCH] CSL3-2071 CSL3-2108 - Case Insensitive headers test --- .../test_case_insensitive_headers.star | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 larky/src/test/resources/quick_tests/test_case_insensitive_headers.star diff --git a/larky/src/test/resources/quick_tests/test_case_insensitive_headers.star b/larky/src/test/resources/quick_tests/test_case_insensitive_headers.star new file mode 100644 index 000000000..e36d1ba59 --- /dev/null +++ b/larky/src/test/resources/quick_tests/test_case_insensitive_headers.star @@ -0,0 +1,42 @@ +load("@stdlib//larky", "larky") +load("@stdlib//unittest","unittest") +load("@stdlib//json","json") +load("@stdlib//types", "types") +load("@stdlib//builtins", builtins="builtins") + +load("@vendor//asserts","asserts") + +load("@vgs//http/request", "VGSHttpRequest") + + +def test_read_case_insensitive_headers(): + actual_header_key = 'case-sensitive' + expected_header_key = actual_header_key.upper() + header_value = 'Header Value' + headers = {actual_header_key : header_value} + request = VGSHttpRequest("http://example.com", data=b'{"cardNumber": "4111111111111111"}', headers=headers, method='POST') + + asserts.assert_that(request.headers[expected_header_key]).is_equal_to(header_value) + asserts.assert_that(request.headers.get(expected_header_key)).is_equal_to(header_value) + asserts.assert_that(request.headers.pop(expected_header_key)).is_equal_to(header_value) + +def test_write_case_insensitive_headers(): + actual_header_key = 'case-sensitive' + expected_header_key = actual_header_key.upper() + headers = {actual_header_key : header_value} + request = VGSHttpRequest("http://example.com", data=b'{"cardNumber": "4111111111111111"}', headers=headers, method='POST') + + asserts.assert_that(request.headers.size()).is_equal_to(1) + request.headers[expected_header_key] = 'New Value' + asserts.assert_that(request.headers.size()).is_equal_to(1) + + +def _testsuite(): + _suite = unittest.TestSuite() + _suite.addTest(unittest.FunctionTestCase(test_read_case_insensitive_headers)) + _suite.addTest(unittest.FunctionTestCase(test_write_case_insensitive_headers)) + return _suite + + +_runner = unittest.TextTestRunner() +_runner.run(_testsuite())