Skip to content

Commit 74d91db

Browse files
committed
chore(datashare-python): fix DatashareTaskClient.get_task_result
1 parent 283c3eb commit 74d91db

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

datashare-python/datashare_python/task_client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
logger = logging.getLogger(__name__)
2323

24+
ApiKey = str
25+
UserAndApiKey = tuple[User, ApiKey]
2426
# TODO: move this one to icij_common
2527

2628

@@ -100,11 +102,11 @@ def _raise_for_status(res: ClientResponse) -> None:
100102

101103

102104
class DatashareTaskClient(AiohttpClient):
103-
def __init__(self, datashare_url: str, api_key: str | None = None) -> None:
104-
self._api_key = api_key
105+
def __init__(self, datashare_url: str, auth: UserAndApiKey | None = None) -> None:
106+
self._user, self._api_key = auth if auth else (None, None)
105107
headers = None
106-
if api_key is not None:
107-
headers = {"Authorization": f"Bearer {api_key}"}
108+
if self._api_key is not None:
109+
headers = {"Authorization": f"Bearer {self._api_key}"}
108110
super().__init__(datashare_url, headers=headers)
109111

110112
async def __aenter__(self) -> Self:

datashare-python/tests/test_task_client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
TaskError,
1414
TaskResult,
1515
TaskState,
16+
User,
1617
)
1718
from datashare_python.task_client import AiohttpClient, DatashareTaskClient
1819

1920

2021
async def test_task_client_create_task(monkeypatch: MonkeyPatch) -> None:
2122
# Given
2223
datashare_url = "http://some-url"
24+
user = User(id="user")
2325
api_key = "some-api-key"
2426
task_name = "hello"
2527
task_id = f"{task_name}-{uuid.uuid4()}"
@@ -40,7 +42,14 @@ async def _put_and_assert(
4042
"id": task_id,
4143
"state": "CREATED",
4244
"name": "hello",
43-
"args": {"greeted": "world"},
45+
"args": {
46+
"greeted": "world",
47+
"user": {
48+
"@type": "org.icij.datashare.user.User",
49+
"details": {},
50+
"id": "user",
51+
},
52+
},
4453
}
4554
assert data is None
4655
json_data = kwargs.pop("json")
@@ -53,7 +62,7 @@ async def _put_and_assert(
5362

5463
monkeypatch.setattr(AiohttpClient, "_put", _put_and_assert)
5564

56-
task_client = DatashareTaskClient(datashare_url, api_key=api_key)
65+
task_client = DatashareTaskClient(datashare_url, auth=(user, api_key))
5766
async with task_client:
5867
# When
5968
t_id = await task_client.create_task(task_name, args, id_=task_id, group=group)

0 commit comments

Comments
 (0)