Skip to content

Commit d2fb72f

Browse files
committed
Use bakrep-v2 api
* Update api url * Make md5 and size from result file object optional
1 parent 1fb33d8 commit d2fb72f

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

bakrep/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def matches(self, filters: List[dict]):
3333

3434
@staticmethod
3535
def from_dict(dict: dict):
36-
return Result(dict['url'], dict['attributes'], dict['md5'], dict['size'])
36+
return Result(dict['url'], dict['attributes'], dict['md5'] if 'md5' in dict else "", dict['size'] if 'size' in dict else 0)
3737

3838

3939
class Dataset:
@@ -160,7 +160,7 @@ class DownloadFailedException(Exception):
160160

161161

162162
class BakrepDownloader:
163-
def __init__(self, url: str = "https://bakrep.computational.bio/api/v1/datasets/"):
163+
def __init__(self, url: str = "https://bakrep.computational.bio/api/v2/datasets/"):
164164
self.url = url
165165

166166
def download(self, id: str, filters: List[dict], target_directory: str):

test/test_download.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def mockdataset(m, id):
9-
m.get(f"https://bakrep.computational.bio/api/v1/datasets/{id}",
9+
m.get(f"https://bakrep.computational.bio/api/v2/datasets/{id}",
1010
content=Path(f"./test/data/scenarios/download-dataset/{id}.json").read_bytes())
1111

1212

@@ -73,7 +73,7 @@ def test_download_dataset_fails_should_raise_exception(self):
7373
with requests_mock.Mocker() as m:
7474
id = "SAMEA3231284"
7575
m.get(
76-
f"https://bakrep.computational.bio/api/v1/datasets/{id}", status_code=404)
76+
f"https://bakrep.computational.bio/api/v2/datasets/{id}", status_code=404)
7777
with tempfile.TemporaryDirectory() as tmp:
7878
d = BakrepDownloader()
7979
self.assertRaises(DownloadFailedException, lambda: d.download(

test/test_download_command.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
from bakrep.cli import main
88

99

10-
def mock_result(id: str, suffix: str, attributes: dict,
11-
md5="d41d8cd98f00b204e9800998ecf8427e" # md5 sum for no content
12-
):
10+
def mock_result(id: str, suffix: str, attributes: dict):
1311
return {
1412
"url": f"https://bakrep-data.s3.computational.bio.uni-giessen.de/{id}/{id}.{suffix}",
1513
"attributes": attributes,
16-
"md5": md5,
1714
"size": 0,
1815
}
1916

@@ -25,7 +22,7 @@ def mock_dataset(m: Mocker, id: str):
2522
mock_result(id, "json", {"tool": "test", "filetype": "json"})
2623
]}
2724
m.get(
28-
f"https://bakrep.computational.bio/api/v1/datasets/{id}", json=dataset)
25+
f"https://bakrep.computational.bio/api/v2/datasets/{id}", json=dataset)
2926
for r in dataset["results"]:
3027
m.get(r['url'], text='')
3128

0 commit comments

Comments
 (0)