Skip to content

Commit

Permalink
Add extra tests for extract_route_params
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout Feys committed Nov 6, 2024
1 parent 073ba1e commit 6a27f19
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions aikido_zen/context/extract_route_params_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,95 @@ def test_uses_keys():
]


def test_normal_urls():
assert extract_route_params("http://localhost:8080/a/b/abc2393027def/def") == [
"a/b/abc2393027def/def"
]


def test_with_empty_route():
url1 = "http://localhost:8080"
assert extract_route_params(url1) == []

url2 = "http://localhost:8080"
assert extract_route_params(url2) == []


def test_special_characters():
url1 = "http://localhost:8080/app/shell/!@#$%^&*()" # Everything past hashtag is not url anymore
assert extract_route_params(url1) == ["!@", "app/shell/!@"]

url2 = "http://localhost:8080/app/shell/space test"
assert extract_route_params(url2) == ["space test", "app/shell/space test"]

url3 = "http://localhost:8080/app/shell/hello%20world"
assert extract_route_params(url3) == ["hello world", "app/shell/hello%20world"]


def test_numeric_segments():
# Alphanum is ignored:
url1 = "http://localhost:8080/app/shell/12345"
assert extract_route_params(url1) == ["app/shell/12345"]

url2 = "http://localhost:8080/app/shell/67890/abc"
assert extract_route_params(url2) == ["app/shell/67890/abc"]


def test_mixed_segments():
url1 = "http://localhost:8080/app/shell/abc123/!@#"
assert extract_route_params(url1) == ["!@", "app/shell/abc123/!@"]

url2 = "http://localhost:8080/app/shell/abc/123/!@#"
assert extract_route_params(url2) == ["!@", "app/shell/abc/123/!@"]


def test_encoded_and_unencoded():
url1 = "http://localhost:8080/app/shell/%E2%9C%93"
assert extract_route_params(url1) == ["✓", "app/shell/%E2%9C%93"]

url2 = "http://localhost:8080/app/shell/%E2%9C%93/normal"
assert extract_route_params(url2) == ["✓", "app/shell/%E2%9C%93/normal"]


def test_no_params():
url1 = "http://localhost:8080/app/shell/"
assert extract_route_params(url1) == ["app/shell/"]

url2 = "http://localhost:8080/app/"
assert extract_route_params(url2) == ["app/"]


def test_edge_cases():
url1 = "http://localhost:8080/app/shell/.."
assert extract_route_params(url1) == ["..", "app/shell/.."]

url2 = "http://localhost:8080/app/shell/./"
assert extract_route_params(url2) == ["app/shell/./"]


def test_long_urls():
url1 = "http://localhost:8080/app/shell/" + "a" * 1000
assert extract_route_params(url1) == ["app/shell/" + "a" * 1000]

url2 = "http://localhost:8080/app/shell/" + "b" * 1000 + "/c" * 1000
assert extract_route_params(url2) == ["app/shell/" + "b" * 1000 + "/c" * 1000]


def test_query_parameters():
# Test query parameters are ignored:
url1 = "http://localhost:8080/app/shell/?param=value"
assert extract_route_params(url1) == ["app/shell/"]

url2 = "http://localhost:8080/app/shell/?key1=value1&key2=value2"
assert extract_route_params(url2) == ["app/shell/"]


def test_fragment_identifiers():
# Fragments should be ignored:
url1 = "http://localhost:8080/app/shell/#section1"
assert extract_route_params(url1) == ["app/shell/"]

url2 = "http://localhost:8080/app/shell/#/path/to/resource"
assert extract_route_params(url2) == [
"app/shell/",
]

0 comments on commit 6a27f19

Please sign in to comment.