Skip to content

Commit 6dd588a

Browse files
refactor: convert test class to functions
1 parent 8b53094 commit 6dd588a

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

tests/issues/test_973_url_decoding.py

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,73 +6,73 @@
66
from mcp.server.fastmcp.resources import ResourceTemplate
77

88

9-
class TestUrlParameterDecoding:
10-
"""Test URL parameter decoding in resource templates."""
9+
def test_template_matches_decodes_space():
10+
"""Test that %20 is decoded to space."""
1111

12-
def test_template_matches_decodes_space(self):
13-
"""Test that %20 is decoded to space."""
12+
def search(query: str) -> str: # pragma: no cover
13+
return f"Results for: {query}"
1414

15-
def search(query: str) -> str: # pragma: no cover
16-
return f"Results for: {query}"
15+
template = ResourceTemplate.from_function(
16+
fn=search,
17+
uri_template="search://{query}",
18+
name="search",
19+
)
1720

18-
template = ResourceTemplate.from_function(
19-
fn=search,
20-
uri_template="search://{query}",
21-
name="search",
22-
)
21+
params = template.matches("search://hello%20world")
22+
assert params is not None
23+
assert params["query"] == "hello world"
2324

24-
params = template.matches("search://hello%20world")
25-
assert params is not None
26-
assert params["query"] == "hello world"
2725

28-
def test_template_matches_decodes_accented_characters(self):
29-
"""Test that %C3%A9 is decoded to e with accent."""
26+
def test_template_matches_decodes_accented_characters():
27+
"""Test that %C3%A9 is decoded to e with accent."""
3028

31-
def search(query: str) -> str: # pragma: no cover
32-
return f"Results for: {query}"
29+
def search(query: str) -> str: # pragma: no cover
30+
return f"Results for: {query}"
3331

34-
template = ResourceTemplate.from_function(
35-
fn=search,
36-
uri_template="search://{query}",
37-
name="search",
38-
)
32+
template = ResourceTemplate.from_function(
33+
fn=search,
34+
uri_template="search://{query}",
35+
name="search",
36+
)
3937

40-
params = template.matches("search://caf%C3%A9")
41-
assert params is not None
42-
assert params["query"] == "café"
38+
params = template.matches("search://caf%C3%A9")
39+
assert params is not None
40+
assert params["query"] == "café"
4341

44-
def test_template_matches_decodes_complex_phrase(self):
45-
"""Test complex French phrase from the original issue."""
4642

47-
def search(query: str) -> str: # pragma: no cover
48-
return f"Results for: {query}"
43+
def test_template_matches_decodes_complex_phrase():
44+
"""Test complex French phrase from the original issue."""
4945

50-
template = ResourceTemplate.from_function(
51-
fn=search,
52-
uri_template="search://{query}",
53-
name="search",
54-
)
46+
def search(query: str) -> str: # pragma: no cover
47+
return f"Results for: {query}"
5548

56-
params = template.matches("search://stick%20correcteur%20teint%C3%A9%20anti-imperfections")
57-
assert params is not None
58-
assert params["query"] == "stick correcteur teinté anti-imperfections"
49+
template = ResourceTemplate.from_function(
50+
fn=search,
51+
uri_template="search://{query}",
52+
name="search",
53+
)
5954

60-
def test_template_matches_preserves_plus_sign(self):
61-
"""Test that plus sign remains as plus (not converted to space).
55+
params = template.matches("search://stick%20correcteur%20teint%C3%A9%20anti-imperfections")
56+
assert params is not None
57+
assert params["query"] == "stick correcteur teinté anti-imperfections"
6258

63-
In URI encoding, %20 is space. Plus-as-space is only for
64-
application/x-www-form-urlencoded (HTML forms).
65-
"""
6659

67-
def search(query: str) -> str: # pragma: no cover
68-
return f"Results for: {query}"
60+
def test_template_matches_preserves_plus_sign():
61+
"""Test that plus sign remains as plus (not converted to space).
6962
70-
template = ResourceTemplate.from_function(
71-
fn=search,
72-
uri_template="search://{query}",
73-
name="search",
74-
)
63+
In URI encoding, %20 is space. Plus-as-space is only for
64+
application/x-www-form-urlencoded (HTML forms).
65+
"""
7566

76-
params = template.matches("search://hello+world")
77-
assert params is not None
78-
assert params["query"] == "hello+world"
67+
def search(query: str) -> str: # pragma: no cover
68+
return f"Results for: {query}"
69+
70+
template = ResourceTemplate.from_function(
71+
fn=search,
72+
uri_template="search://{query}",
73+
name="search",
74+
)
75+
76+
params = template.matches("search://hello+world")
77+
assert params is not None
78+
assert params["query"] == "hello+world"

0 commit comments

Comments
 (0)