Skip to content
Snippets Groups Projects
Unverified Commit cac419e2 authored by charly reux's avatar charly reux
Browse files

Update code for coding conventions

parent 699de30a
No related branches found
Tags v0.8.0
1 merge request!37Add cooking requests to the WebAPIClient
Pipeline #6550 passed
......@@ -213,7 +213,6 @@ class _RateLimitInfo:
return r
def replacing(self, other):
if other.reset_date != self.reset_date:
# the one with a later reset date is likely more up to date.
return other.reset_date < self.reset_date
......@@ -918,12 +917,8 @@ class WebAPIClient:
return r.text
def cooking_request(
self,
bundle_type: str,
swhid: SWHIDish,
email: Optional[str] = None,
**req_args
) -> Dict[str,Any]:
self, bundle_type: str, swhid: SWHIDish, email: Optional[str] = None, **req_args
) -> Dict[str, Any]:
"""Request a cooking of a bundle
Args:
......@@ -946,16 +941,18 @@ class WebAPIClient:
"""
q = f"vault/{bundle_type}/{swhid}/"
r = self._call(q, http_method="post", json={"email":email},**req_args,)
r = self._call(
q,
http_method="post",
json={"email": email},
**req_args,
)
r.raise_for_status()
return r.json()
def cooking_check(
self,
bundle_type:str,
swhid: SWHIDish,
**req_args
) -> Dict[str,Any]:
self, bundle_type: str, swhid: SWHIDish, **req_args
) -> Dict[str, Any]:
"""Check the status of a cooking task
Args:
......@@ -977,15 +974,16 @@ class WebAPIClient:
"""
q = f"vault/{bundle_type}/{swhid}/"
r = self._call(q, http_method="get",**req_args,)
r = self._call(
q,
http_method="get",
**req_args,
)
r.raise_for_status()
return r.json()
def cooking_fetch(
self,
bundle_type:str,
swhid: SWHIDish,
**req_args
self, bundle_type: str, swhid: SWHIDish, **req_args
) -> requests.models.Response:
"""Fetch the archive of a cooking task
......@@ -1003,6 +1001,11 @@ class WebAPIClient:
"""
q = f"vault/{bundle_type}/{swhid}/raw"
r = self._call(q, http_method="get",stream=True,**req_args,)
r = self._call(
q,
http_method="get",
stream=True,
**req_args,
)
r.raise_for_status()
return r
......@@ -333,8 +333,9 @@ def test_iter(web_api_client, web_api_mock, swhid, swhid_type, typify):
def test_cooking_request(web_api_client, web_api_mock):
dir_swhid = "swh:1:dir:977fc4b98c0e85816348cebd3b12026407c368b6"
obj = web_api_client.cooking_request("flat", dir_swhid)
assert obj["fetch_url"] == ("https://archive.softwareheritage.org/api/1/vault/flat/"
+ dir_swhid + "/raw/")
assert obj["fetch_url"] == (
"https://archive.softwareheritage.org/api/1/vault/flat/" + dir_swhid + "/raw/"
)
assert obj["status"] == "pending"
assert obj["swhid"] == dir_swhid
assert obj["id"] == 415999462
......@@ -344,8 +345,9 @@ def test_cooking_request(web_api_client, web_api_mock):
def test_cooking_check(web_api_client, web_api_mock):
dir_swhid = "swh:1:dir:977fc4b98c0e85816348cebd3b12026407c368b6"
obj = web_api_client.cooking_check("flat", dir_swhid)
assert obj["fetch_url"] == ("https://archive.softwareheritage.org/api/1/vault/flat/"
+ dir_swhid + "/raw/")
assert obj["fetch_url"] == (
"https://archive.softwareheritage.org/api/1/vault/flat/" + dir_swhid + "/raw/"
)
assert obj["status"] == "pending"
assert obj["swhid"] == dir_swhid
assert obj["id"] == 415999462
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment