5
5
from kiota_http .middleware .options import ParametersNameDecodingHandlerOption
6
6
7
7
OPTION_KEY = "ParametersNameDecodingHandlerOption"
8
+
9
+
8
10
def test_no_config ():
9
11
"""
10
12
Test that default values are used if no custom confguration is passed
@@ -19,9 +21,7 @@ def test_custom_options():
19
21
"""
20
22
Test that default configuration is overrriden if custom configuration is provided
21
23
"""
22
- options = ParametersNameDecodingHandlerOption (
23
- enable = False , characters_to_decode = ["." , "-" ]
24
- )
24
+ options = ParametersNameDecodingHandlerOption (enable = False , characters_to_decode = ["." , "-" ])
25
25
handler = ParametersNameDecodingHandler (options )
26
26
27
27
assert handler .options .enabled is not True
@@ -35,24 +35,40 @@ async def test_decodes_query_parameter_names_only():
35
35
Test that only query parameter names are decoded
36
36
"""
37
37
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
+ )
51
67
]
52
-
68
+
53
69
def request_handler (request : httpx .Request ):
54
70
return httpx .Response (200 , json = {"text" : "Hello, world!" })
55
-
71
+
56
72
handler = ParametersNameDecodingHandler ()
57
73
for encoded , decoded in encoded_decoded :
58
74
request = httpx .Request ('GET' , encoded )
0 commit comments