Skip to content

Commit

Permalink
Constructed URLs correctly when there's no port (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
moleculekayak authored Oct 8, 2024
1 parent 24479d0 commit 6cb504c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/clients/torrent_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def _extract_credentials_from_url(self, url, base_path=None):
parsed_url = urlparse(url)
username = unquote(parsed_url.username) if parsed_url.username else ""
password = unquote(parsed_url.password) if parsed_url.password else ""
origin = f"{parsed_url.scheme}://{parsed_url.hostname}:{parsed_url.port}"
host = f"{parsed_url.hostname}{(':' + str(parsed_url.port)) if parsed_url.port else ''}"
origin = f"{parsed_url.scheme}://{host}"

if base_path is not None:
href = url_join(origin, os.path.normpath(base_path))
Expand Down
17 changes: 17 additions & 0 deletions tests/clients/test_qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ def torrent_info_response():
}


class TestInit(SetupTeardown):
def test_initializes_with_url_parts(self):
qbit_client = Qbittorrent("http://admin:supersecret@localhost:8080")

assert qbit_client._qbit_url_parts == ("http://localhost:8080/api/v2", "admin", "supersecret")

def test_initializes_with_no_auth(self):
qbit_client = Qbittorrent("http://localhost:8080")

assert qbit_client._qbit_url_parts == ("http://localhost:8080/api/v2", "", "")

def test_initializes_with_no_port(self):
qbit_client = Qbittorrent("http://admin:supersecret@localhost")

assert qbit_client._qbit_url_parts == ("http://localhost/api/v2", "admin", "supersecret")


class TestSetup(SetupTeardown):
def test_sets_auth_cookie(self, qbit_client):
assert qbit_client._qbit_cookie is None
Expand Down

0 comments on commit 6cb504c

Please sign in to comment.