-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve query parameters in the base URL when joining urls (#101)
* Preserve query parameters in the base URL. * additional import * tests
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 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,28 @@ | ||
import pytest | ||
from sw_utils.common import urljoin | ||
|
||
def test_urljoin_basic(): | ||
assert urljoin('http://example.com', 'path') == 'http://example.com/path' | ||
assert urljoin('http://example.com/', 'path') == 'http://example.com/path' | ||
assert urljoin('http://example.com', 'path1', 'path2') == 'http://example.com/path1/path2' | ||
assert urljoin('http://example.com/', 'path1', 'path2') == 'http://example.com/path1/path2' | ||
|
||
def test_urljoin_with_query(): | ||
assert urljoin('http://example.com?query=1', 'path') == 'http://example.com/path?query=1' | ||
assert urljoin('http://example.com/?query=1', 'path') == 'http://example.com/path?query=1' | ||
assert urljoin('http://example.com?query=1', 'path1', 'path2') == 'http://example.com/path1/path2?query=1' | ||
assert urljoin('http://example.com/?query=1', 'path1', 'path2') == 'http://example.com/path1/path2?query=1' | ||
|
||
def test_urljoin_with_fragment(): | ||
assert urljoin('http://example.com#fragment', 'path') == 'http://example.com/path#fragment' | ||
assert urljoin('http://example.com/#fragment', 'path') == 'http://example.com/path#fragment' | ||
assert urljoin('http://example.com#fragment', 'path1', 'path2') == 'http://example.com/path1/path2#fragment' | ||
assert urljoin('http://example.com/#fragment', 'path1', 'path2') == 'http://example.com/path1/path2#fragment' | ||
|
||
def test_urljoin_edge_cases(): | ||
assert urljoin('http://example.com', '') == 'http://example.com' | ||
assert urljoin('http://example.com/', '') == 'http://example.com/' | ||
assert urljoin('http://example.com', '/', '/') == 'http://example.com/' | ||
assert urljoin('http://example.com/', '/', '/') == 'http://example.com/' | ||
assert urljoin('http://example.com//', 'path') == 'http://example.com/path' | ||
assert urljoin('http://example.com/', '//path') == 'http://example.com/path' |