Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

COPDS-1934: add location property #54

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cads_api_client/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import os
import time
import urllib
import urllib.parse
from typing import Any, Dict, List, Optional, Type, TypeVar

try:
Expand Down Expand Up @@ -336,14 +336,18 @@ def get_result_size(self) -> Optional[int]:
size = asset["file:size"]
return int(size)

@property
def location(self) -> str:
result_href = self.get_result_href()
return urllib.parse.urljoin(self.response.url, result_href)

def download(
self,
target: Optional[str] = None,
timeout: int = 60,
retry_options: Dict[str, Any] = {},
) -> str:
result_href = self.get_result_href()
url = urllib.parse.urljoin(self.response.url, result_href)
url = self.location
if target is None:
parts = urllib.parse.urlparse(url)
target = parts.path.strip("/").split("/")[-1]
Expand Down
4 changes: 4 additions & 0 deletions tests/integration_test_50_legacy_api_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pathlib

import pytest
import requests

from cads_api_client import legacy_api_client

Expand All @@ -22,6 +23,9 @@ def test_retrieve(tmp_path: pathlib.Path, api_root_url: str, api_key: str) -> No
assert str(target) == actual_target
assert target.stat().st_size == 1

response = requests.head(result.location)
assert response.status_code == 200


@pytest.mark.parametrize("quiet", [True, False])
def test_quiet(
Expand Down