Skip to content

Commit

Permalink
Update response for result list API
Browse files Browse the repository at this point in the history
  • Loading branch information
tung-vu-td committed Jul 25, 2024
1 parent 25601ee commit e91d849
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
4 changes: 2 additions & 2 deletions tdclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,8 @@ def results(self):
results = self.api.list_result()

def result(m):
name, url, organizations = m
return models.Result(self, name, url, organizations)
name, url, organizations, id, user_id = m
return models.Result(self, name, url, organizations, id, user_id)

return [result(m) for m in results]

Expand Down
6 changes: 3 additions & 3 deletions tdclient/result_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ def list_result(self):
"""Get the list of all the available authentications.
Returns:
[(str, str, None)]: The list of tuple of name, Result output url, and
organization name (always `None` for api compatibility).
[(str, str, None, int, int)]: The list of tuple of name, Result output url,
organization name (always `None` for api compatibility), result id and user id
"""
with self.get("/v3/result/list") as res:
code, body = res.status, res.read()
if code != 200:
self.raise_error("List result table failed", res, body)
js = self.checked_json(body, ["results"])
return [
(m["name"], m["url"], None) for m in js["results"]
(m["name"], m["url"], None, m["id"], m["user_id"]) for m in js["results"]
] # same as database

def create_result(self, name, url, params=None):
Expand Down
16 changes: 15 additions & 1 deletion tdclient/result_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class Result(Model):
"""Result on Treasure Data Service
"""

def __init__(self, client, name, url, org_name):
def __init__(self, client, name, url, org_name, id, user_id):
super(Result, self).__init__(client)
self._name = name
self._url = url
self._org_name = org_name
self._id = id
self._user_id = user_id

@property
def name(self):
Expand All @@ -30,3 +32,15 @@ def org_name(self):
"""str: organization name
"""
return self._org_name

@property
def id(self):
"""int: result id
"""
return self._id

@property
def user_id(self):
"""int: result's owner id
"""
return self._user_id
18 changes: 12 additions & 6 deletions tdclient/test/result_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@ def test_list_result_success():
{
"name": "foo",
"organization": null,
"url": "mysql://example.com/db/foo"
"url": "mysql://example.com/db/foo",
"id": 123,
"user_id": 1
},
{
"name": "bar",
"organization": null,
"url": "postgresql://example.com/db/bar"
"url": "postgresql://example.com/db/bar",
"id": 124,
"user_id": 1
},
{
"name": "baz",
"organization": null,
"url": "s3://s3.example.com/baz.csv"
"url": "s3://s3.example.com/baz.csv",
"id": 125,
"user_id": 1
}
]
}
Expand All @@ -39,9 +45,9 @@ def test_list_result_success():
results = td.list_result()
td.get.assert_called_with("/v3/result/list")
assert len(results) == 3
assert results[0] == ("foo", "mysql://example.com/db/foo", None)
assert results[1] == ("bar", "postgresql://example.com/db/bar", None)
assert results[2] == ("baz", "s3://s3.example.com/baz.csv", None)
assert results[0] == ("foo", "mysql://example.com/db/foo", None, 123, 1)
assert results[1] == ("bar", "postgresql://example.com/db/bar", None, 124, 1)
assert results[2] == ("baz", "s3://s3.example.com/baz.csv", None, 125, 1)


def test_list_result_failure():
Expand Down
4 changes: 3 additions & 1 deletion tdclient/test/result_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def setup_function(function):

def test_result():
client = mock.MagicMock()
result = models.Result(client, "name", "url", "org_name")
result = models.Result(client, "name", "url", "org_name", 123, 1)
assert result.name == "name"
assert result.url == "url"
assert result.org_name == "org_name"
assert result.id == 123
assert result.user_id == 1

0 comments on commit e91d849

Please sign in to comment.