Skip to content

Commit 25157f0

Browse files
authored
Merge pull request #18 from unniznd/fix_get_uploads
fix: Updated the getUploads method from old API to new API
2 parents 678e49e + 08b65c5 commit 25157f0

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

src/lighthouseweb3/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,16 @@ def getDealStatus(cid: str):
6868
return deal_status.get_deal_status(cid)
6969
except Exception as e:
7070
raise e
71-
72-
@staticmethod
73-
def getUploads(publicKey: str, pageNo: int = 1):
71+
72+
def getUploads(self, lastKey: str = None):
7473
"""
7574
Get uploads from the Lighthouse.
7675
77-
:param publicKey: str, public key
78-
:param pageNo: int, page number (default: 1)
76+
:param lastKey: To navigate to different pages of results
7977
:return: List[t.DealData], list of deal data
8078
"""
8179
try:
82-
return getUploads.get_uploads(publicKey, pageNo)
80+
return getUploads.get_uploads(self.token, lastKey)
8381
except Exception as e:
8482
raise e
8583

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: str = 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: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@
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")
16+
res = l.getUploads()
17+
self.assertIsInstance(res.get("fileList"), list, "data is a list")
18+
self.assertIsInstance(res.get('totalFiles'), int, "totalFiles is an int")
19+
20+
def test_get_upload_with_last_key(self):
21+
"""test get_upload function with lastKey"""
22+
parse_env()
23+
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
24+
res = l.getUploads('b5f60ba0-b708-41a3-b0f2-5c808ce63b48')
2425
self.assertIsInstance(res.get("fileList"), list, "data is a list")
26+
self.assertIsInstance(res.get('totalFiles'), int, "totalFiles is an int")
27+
28+
def test_get_upload_with_invalid_token(self):
29+
"""test get_upload function with invalid token"""
30+
parse_env()
31+
l = Lighthouse("invalid_token")
32+
with self.assertRaises(Exception) as context:
33+
l.getUploads()
34+
self.assertIn("authentication failed", str(context.exception).lower())

0 commit comments

Comments
 (0)