Skip to content

Refactor getUploads method and updated the test functions #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/lighthouseweb3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def getDealStatus(cid: str):
except Exception as e:
raise e

@staticmethod
def getUploads(publicKey: str, pageNo: int = 1):
def getUploads(self, lastKey: int = None):
"""
Get uploads from the Lighthouse.

Expand All @@ -79,7 +78,7 @@ def getUploads(publicKey: str, pageNo: int = 1):
:return: List[t.DealData], list of deal data
"""
try:
return getUploads.get_uploads(publicKey, pageNo)
return getUploads.get_uploads(self.token, lastKey)
except Exception as e:
raise e

Expand Down
9 changes: 6 additions & 3 deletions src/lighthouseweb3/functions/get_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ def bytes_to_size(bytes_size):
return f"{round(bytes_size, 2)} {units[index]}"


def get_uploads(publicKey: str, pageNo: int = 1) :
def get_uploads(token: str, lastKey: int = None) :
headers = {
"Authorization": f"Bearer {token}",
}
try:
url = f"{Config.lighthouse_api}/api/user/files_uploaded?publicKey={publicKey}&pageNo={pageNo}"
response = requests.get(url)
url = f"{Config.lighthouse_api}/api/user/files_uploaded?lastKey={lastKey}"
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()
except requests.HTTPError as error:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_deal_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_deal_status(self):
"QmT9shXpKcn4HRbJhXJ1ZywzwjEo2QWbxAx4SVgW4eYKjG")
self.assertIsInstance(res, list, "data is a list")
self.assertIsInstance(res[0].get(
"dealId"), int, "dealId is Int")
"DealID"), int, "DealID is Int")

def test_deal_status_init(self):
"""test deal_status function"""
Expand All @@ -25,4 +25,4 @@ def test_deal_status_init(self):
"QmT9shXpKcn4HRbJhXJ1ZywzwjEo2QWbxAx4SVgW4eYKjG")
self.assertIsInstance(res, list, "data is a list")
self.assertIsInstance(res[0].get(
"dealId"), int, "dealId is Int")
"DealID"), int, "DealID is Int")
13 changes: 4 additions & 9 deletions tests/test_get_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@
from .setup import parse_env


class TestDealStatus(unittest.TestCase):
class TestGetUploads(unittest.TestCase):

def test_get_upload(self):
"""test static test_get_upload function"""
res = Lighthouse.getUploads(
"0xB23809427cFc9B3346AEC5Bb70E7e574696cAF80")
self.assertIsInstance(res.get("fileList"), list, "data is a list")

def test_get_upload_init(self):
"""test get_upload function"""
parse_env()
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
res = Lighthouse.getUploads(
"0xB23809427cFc9B3346AEC5Bb70E7e574696cAF80")
res = l.getUploads()
self.assertIsInstance(res.get("fileList"), list, "data is a list")