55from kiota_http .middleware .options import ParametersNameDecodingHandlerOption
66
77OPTION_KEY = "ParametersNameDecodingHandlerOption"
8+
9+
810def test_no_config ():
911 """
1012 Test that default values are used if no custom confguration is passed
@@ -19,9 +21,7 @@ def test_custom_options():
1921 """
2022 Test that default configuration is overrriden if custom configuration is provided
2123 """
22- options = ParametersNameDecodingHandlerOption (
23- enable = False , characters_to_decode = ["." , "-" ]
24- )
24+ options = ParametersNameDecodingHandlerOption (enable = False , characters_to_decode = ["." , "-" ])
2525 handler = ParametersNameDecodingHandler (options )
2626
2727 assert handler .options .enabled is not True
@@ -35,24 +35,40 @@ async def test_decodes_query_parameter_names_only():
3535 Test that only query parameter names are decoded
3636 """
3737 encoded_decoded = [
38- ("http://localhost?%24select=diplayName&api%2Dversion=2" , "http://localhost?$select=diplayName&api-version=2" ),
39- ("http://localhost?%24select=diplayName&api%7Eversion=2" , "http://localhost?$select=diplayName&api~version=2" ),
40- ("http://localhost?%24select=diplayName&api%2Eversion=2" , "http://localhost?$select=diplayName&api.version=2" ),
41- ("http://localhost:888?%24select=diplayName&api%2Dversion=2" , "http://localhost:888?$select=diplayName&api-version=2" ),
42- ("http://localhost" , "http://localhost" ),
43- ("https://google.com/?q=1%2b2" , "https://google.com/?q=1%2b2" ),
44- ("https://google.com/?q=M%26A" , "https://google.com/?q=M%26A" ),
45- ("https://google.com/?q=1%2B2" , "https://google.com/?q=1%2B2" ), # Values are not decoded
46- ("https://google.com/?q=M%26A" , "https://google.com/?q=M%26A" ), # Values are not decoded
47- ("https://google.com/?q%2D1=M%26A" , "https://google.com/?q-1=M%26A" ), # Values are not decoded but params are
48- ("https://google.com/?q%2D1&q=M%26A=M%26A" , "https://google.com/?q-1&q=M%26A=M%26A" ), # Values are not decoded but params are
49- ("https://graph.microsoft.com?%24count=true&query=%24top&created%2Din=2022-10-05&q=1%2b2&q2=M%26A&subject%2Ename=%7eWelcome&%24empty" ,
50- "https://graph.microsoft.com?$count=true&query=%24top&created-in=2022-10-05&q=1%2b2&q2=M%26A&subject.name=%7eWelcome&$empty" )
38+ (
39+ "http://localhost?%24select=diplayName&api%2Dversion=2" ,
40+ "http://localhost?$select=diplayName&api-version=2"
41+ ),
42+ (
43+ "http://localhost?%24select=diplayName&api%7Eversion=2" ,
44+ "http://localhost?$select=diplayName&api~version=2"
45+ ),
46+ (
47+ "http://localhost?%24select=diplayName&api%2Eversion=2" ,
48+ "http://localhost?$select=diplayName&api.version=2"
49+ ),
50+ (
51+ "http://localhost:888?%24select=diplayName&api%2Dversion=2" ,
52+ "http://localhost:888?$select=diplayName&api-version=2"
53+ ),
54+ ("http://localhost" , "http://localhost" ),
55+ ("https://google.com/?q=1%2b2" , "https://google.com/?q=1%2b2" ),
56+ ("https://google.com/?q=M%26A" , "https://google.com/?q=M%26A" ),
57+ ("https://google.com/?q=1%2B2" , "https://google.com/?q=1%2B2" ), # Values are not decoded
58+ ("https://google.com/?q=M%26A" , "https://google.com/?q=M%26A" ), # Values are not decoded
59+ ("https://google.com/?q%2D1=M%26A" ,
60+ "https://google.com/?q-1=M%26A" ), # Values are not decoded but params are
61+ ("https://google.com/?q%2D1&q=M%26A=M%26A" ,
62+ "https://google.com/?q-1&q=M%26A=M%26A" ), # Values are not decoded but params are
63+ (
64+ "https://graph.microsoft.com?%24count=true&query=%24top&created%2Din=2022-10-05&q=1%2b2&q2=M%26A&subject%2Ename=%7eWelcome&%24empty" ,
65+ "https://graph.microsoft.com?$count=true&query=%24top&created-in=2022-10-05&q=1%2b2&q2=M%26A&subject.name=%7eWelcome&$empty"
66+ )
5167 ]
52-
68+
5369 def request_handler (request : httpx .Request ):
5470 return httpx .Response (200 , json = {"text" : "Hello, world!" })
55-
71+
5672 handler = ParametersNameDecodingHandler ()
5773 for encoded , decoded in encoded_decoded :
5874 request = httpx .Request ('GET' , encoded )
0 commit comments