Skip to content

Commit 41b4383

Browse files
committed
FIX: Migrated getUploads method from old api to new api. Fixed deal status response naming mismatch/
1 parent 678e49e commit 41b4383

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

src/lighthouseweb3/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,15 @@ def getDealStatus(cid: str):
7070
raise e
7171

7272
@staticmethod
73-
def getUploads(publicKey: str, pageNo: int = 1):
73+
def getUploads(self, lastKey: int = None):
7474
"""
7575
Get uploads from the Lighthouse.
7676
77-
:param publicKey: str, public key
78-
:param pageNo: int, page number (default: 1)
77+
:param lastKey: To navigate to different pages of results
7978
:return: List[t.DealData], list of deal data
8079
"""
8180
try:
82-
return getUploads.get_uploads(publicKey, pageNo)
81+
return getUploads.get_uploads(self.token, lastKey)
8382
except Exception as e:
8483
raise e
8584

src/lighthouseweb3/functions/get_uploads.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ def bytes_to_size(bytes_size):
1111
return f"{round(bytes_size, 2)} {units[index]}"
1212

1313

14-
def get_uploads(publicKey: str, pageNo: int = 1) :
14+
def get_uploads(token: str, lastKey: int = None) :
15+
headers = {
16+
"Authorization": f"Bearer {token}",
17+
}
18+
1519
try:
16-
url = f"{Config.lighthouse_api}/api/user/files_uploaded?publicKey={publicKey}&pageNo={pageNo}"
17-
response = requests.get(url)
20+
url = f"{Config.lighthouse_api}/api/user/files_uploaded?lastKey={lastKey}"
21+
response = requests.get(url, headers=headers)
1822
response.raise_for_status()
1923
return response.json()
2024
except requests.HTTPError as error:

tests/test_deal_status.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_deal_status(self):
1515
"QmT9shXpKcn4HRbJhXJ1ZywzwjEo2QWbxAx4SVgW4eYKjG")
1616
self.assertIsInstance(res, list, "data is a list")
1717
self.assertIsInstance(res[0].get(
18-
"dealId"), int, "dealId is Int")
18+
"DealID"), int, "DealID is Int")
1919

2020
def test_deal_status_init(self):
2121
"""test deal_status function"""
@@ -25,4 +25,4 @@ def test_deal_status_init(self):
2525
"QmT9shXpKcn4HRbJhXJ1ZywzwjEo2QWbxAx4SVgW4eYKjG")
2626
self.assertIsInstance(res, list, "data is a list")
2727
self.assertIsInstance(res[0].get(
28-
"dealId"), int, "dealId is Int")
28+
"DealID"), int, "DealID is Int")

tests/test_get_uploads.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,11 @@
77
from .setup import parse_env
88

99

10-
class TestDealStatus(unittest.TestCase):
10+
class TestGetUploads(unittest.TestCase):
1111

1212
def test_get_upload(self):
13-
"""test static test_get_upload function"""
14-
res = Lighthouse.getUploads(
15-
"0xB23809427cFc9B3346AEC5Bb70E7e574696cAF80")
16-
self.assertIsInstance(res.get("fileList"), list, "data is a list")
17-
18-
def test_get_upload_init(self):
1913
"""test get_upload function"""
2014
parse_env()
2115
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
22-
res = Lighthouse.getUploads(
23-
"0xB23809427cFc9B3346AEC5Bb70E7e574696cAF80")
24-
self.assertIsInstance(res.get("fileList"), list, "data is a list")
16+
res = l.getUploads()
17+
self.assertIsInstance(res.get("fileList"), list, "data is a list")

0 commit comments

Comments
 (0)