Skip to content

Commit

Permalink
Add test for list command
Browse files Browse the repository at this point in the history
  • Loading branch information
misaelnieto committed Nov 14, 2023
1 parent 5d8c8ad commit 62b2807
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tests/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from vercel_storage import blob

def test_blob_delete(requests_mock: Mocker):
requests_mock.delete(
requests_mock.post(
url='https://blob.vercel-storage.com/delete',
status_code='200'
status_code=200,
json={}
)

blob.delete(
Expand Down
38 changes: 38 additions & 0 deletions tests/test_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from requests_mock import Mocker
from vercel_storage import blob


def test_blob_list(requests_mock: Mocker):
requests_mock.get(
url="https://blob.vercel-storage.com/",
status_code=200,
json={
"hasMore": False,
"blobs": [
{
"url": "https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/README-PWeZ5e2SC66TZgvFcvzVOMz2ZcUqnR.md",
"pathname": "README.md",
"size": 263,
"uploadedAt": "2023-11-14T23:26:52.759Z",
"contentType": "text/markdown",
"contentDisposition": 'attachment; filename="README.md"',
},
{
"url": "https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/tox-XrRb5Y3rC0H30fIXhL6yDYtTOPG8TL.ini",
"pathname": "tox.ini",
"size": 195,
"uploadedAt": "2023-11-14T23:26:43.364Z",
"contentType": "text/plain",
"contentDisposition": 'attachment; filename="tox.ini"',
},
],
},
)

contents = blob.list(
options={"token": "ABCD123foobar"},
)

assert requests_mock.called
assert requests_mock.call_count == 1
assert [z["pathname"] for z in contents['blobs']] == ["README.md", "tox.ini"]
2 changes: 1 addition & 1 deletion vercel_storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _coerce_bool(value):


def _handle_response(response: requests.Response):
if response.status_code == 200:
if str(response.status_code) == '200':
return response.json()
raise APIResponseError(f"Oops, something went wrong: {response.json()}")

Expand Down

0 comments on commit 62b2807

Please sign in to comment.