-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #478 from danieldotnl/httpx_issue
Merge url params with provided params since httpx doesn't do it anymore
- Loading branch information
Showing
2 changed files
with
116 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"""Tests for the http module.""" | ||
from custom_components.multiscrape.http import merge_url_with_params | ||
|
||
|
||
def test_merge_url_with_params(): | ||
"""Test merge_url_with_params function.""" | ||
url = "https://example.com" | ||
params = {"param1": "value1", "param2": "value2"} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=value1¶m2=value2" | ||
|
||
url = "https://example.com" | ||
params = {"param1": "value1", "param2": 2} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=value1¶m2=2" | ||
|
||
url = "https://example.com?param1=value1" | ||
params = {"param2": "value2"} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=value1¶m2=value2" | ||
|
||
url = "https://example.com?param1=value1" | ||
params = {} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=value1" | ||
|
||
url = "https://example.com?param1=33" | ||
params = None | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=33" | ||
|
||
|
||
def test_merge_url_with_params_existing_params(): | ||
"""Test merge_url_with_params with existing URL parameters.""" | ||
url = "https://example.com?param1=value1" | ||
params = {"param2": "value2"} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=value1¶m2=value2" | ||
|
||
url = "https://example.com?param1=value1¶m2=value2" | ||
params = {"param3": "value3"} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=value1¶m2=value2¶m3=value3" | ||
|
||
|
||
def test_merge_url_with_params_override_existing(): | ||
"""Test merge_url_with_params overriding existing URL parameters.""" | ||
url = "https://example.com?param1=value1" | ||
params = {"param1": "new_value1", "param2": "value2"} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=new_value1¶m2=value2" | ||
|
||
|
||
def test_merge_url_with_params_array_values(): | ||
"""Test merge_url_with_params with array values.""" | ||
url = "https://example.com" | ||
params = {"param1": ["value1", "value2"]} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=value1¶m1=value2" | ||
|
||
url = "https://example.com?param1=value1" | ||
params = {"param1": ["value2", "value3"]} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=value2¶m1=value3" | ||
|
||
|
||
def test_merge_url_with_params_special_characters(): | ||
"""Test merge_url_with_params with special characters in parameters.""" | ||
url = "https://example.com" | ||
params = {"param1": "value with spaces", | ||
"param2": "value&with&special&chars"} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=value+with+spaces¶m2=value%26with%26special%26chars" | ||
|
||
|
||
def test_merge_url_with_params_url_components(): | ||
"""Test merge_url_with_params with various URL components.""" | ||
# Test URL with port | ||
url = "https://example.com:8080" | ||
params = {"param1": "value1"} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com:8080?param1=value1" | ||
|
||
# Test URL with fragment | ||
url = "https://example.com#section1" | ||
params = {"param1": "value1"} | ||
result = merge_url_with_params(url, params) | ||
assert result == "https://example.com?param1=value1#section1" |