Skip to content

Commit

Permalink
Merge pull request #129 from starkbank/fix/requests-prefix
Browse files Browse the repository at this point in the history
Fix request param prefix
  • Loading branch information
leoKagohara-Stark authored Jul 1, 2024
2 parents 3a6ff39 + cf99dc8 commit 7a9d0ae
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 45 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:
- request methods
### Changed
- core version
### Fixed
- request prefix param

## [2.25.1] - 2024-04-01
### Fixed
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2605,7 +2605,7 @@ import starkbank
example_id = "5155165527080960"
request = starkbank.request.get(
path=f"/invoice/{example_id}"
)
).json()

print(request)
```
Expand All @@ -2618,7 +2618,7 @@ import starkbank
example_id = "5699165527090460"
request = starkbank.request.get(
path=f"/invoice/log/{example_id}",
)
).json()

print(request)
```
Expand All @@ -2631,7 +2631,7 @@ import starkbank
request = starkbank.request.get(
path="/invoice",
query={"limit": 10, "status": "paid"},
)
).json()

for item in request["invoices"]:
print(item)
Expand All @@ -2645,7 +2645,7 @@ import starkbank
request = starkbank.request.get(
path="/invoice/log",
query={"limit": 10, "status": "paid"},
)
).json()

for item in request["invoices"]:
print(item)
Expand All @@ -2659,7 +2659,7 @@ import starkbank
example_id = "5155165527080960"
pdf = starkbank.request.get(
path=f"/invoice/{example_id}/pdf",
)
).content
with open("request.pdf", "wb") as file:
file.write(pdf)
```
Expand Down Expand Up @@ -2692,11 +2692,11 @@ data={
request = starkbank.request.post(
path="/invoice",
body=data,
)
).json()
print(request)
```

## patch
## PATCH

You can perform a PATCH request to any StarkBank route.

Expand All @@ -2708,7 +2708,7 @@ example_id = "5155165527080960"
request = starkbank.request.patch(
path=f"/invoice/{example_id}",
body={"amount": 0},
)
).json()
print(request)
```

Expand All @@ -2731,7 +2731,7 @@ data = {
request = starkbank.request.put(
path="/split-profile",
body=data,
)
).json()
print(request)
```
## DELETE
Expand All @@ -2745,7 +2745,7 @@ import starkbank
example_id = "5155165527080960"
request = starkbank.request.delete(
path=f"/transfer/{example_id}",
)
).json()
print(request)
```
# Handling errors
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
starkcore==0.3.2
starkcore==0.5.0
1 change: 1 addition & 0 deletions starkbank/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
user = None
language = "en-US"
timeout = 15
request_methods_prefix = "Joker"

from starkcore import Organization, Project

Expand Down
2 changes: 1 addition & 1 deletion starkbank/corporatecard/__corporatecard.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def create(card, expand=None, user=None):
- CorporateCard object with updated attributes
"""
path = "{endpoint}/{sub_resource}".format(endpoint=endpoint(_resource), sub_resource="token")
json = rest.post_raw(path=path, payload=api_json(card), expand=expand, user=user)
json = rest.post_raw(path=path, payload=api_json(card), query={"expand": expand}, user=user).json()
return from_api_json(_resource, json[last_name(_resource)])


Expand Down
21 changes: 16 additions & 5 deletions starkbank/request/__request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ..utils import rest
from starkbank import request_methods_prefix


def get(path, query=None, user=None):
Expand All @@ -16,7 +17,9 @@ def get(path, query=None, user=None):
return rest.get_raw(
path=path,
query=query,
user=user
user=user,
prefix=request_methods_prefix,
raiseException=False
)


Expand All @@ -37,7 +40,9 @@ def post(path, body=None, query=None, user=None):
path=path,
payload=body,
query=query,
user=user
user=user,
prefix=request_methods_prefix,
raiseException=False
)


Expand All @@ -56,7 +61,9 @@ def patch(path, body=None, user=None):
return rest.patch_raw(
path=path,
payload=body,
user=user
user=user,
prefix=request_methods_prefix,
raiseException=False
)


Expand All @@ -76,7 +83,9 @@ def put(path, body=None, user=None):
return rest.put_raw(
path=path,
payload=body,
user=user
user=user,
prefix=request_methods_prefix,
raiseException=False
)


Expand All @@ -96,5 +105,7 @@ def delete(path, body=None, user=None):
return rest.delete_raw(
path=path,
payload=body,
user=user
user=user,
prefix=request_methods_prefix,
raiseException=False
)
56 changes: 30 additions & 26 deletions tests/sdk/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,53 @@
class TestJokerGet(TestCase):

def test_get(self):
example_id = starkbank.request.get(
path=f'/invoice/',
query={"limit": 1, "status": "paid"},
)["invoices"][0]["id"]
try:
example_id = starkbank.request.get(
path=f'/invoice/',
query={"limit": 1, "status": "paid"},
)

request = starkbank.request.get(
path=f'/invoice/{example_id}',
user=exampleProject
)
self.assertEqual(request["invoice"]["id"], example_id)
request = starkbank.request.get(
path=f'/invoice/{example_id.json()["invoices"][0]["id"]}',
user=exampleProject
)
if request.status != 200:
raise Exception(request.content)
self.assertEqual(request.json()["invoice"]["id"], example_id.json()["invoices"][0]["id"])
except Exception:
raise Exception

def test_get_pdf(self):
example_id = starkbank.request.get(
path=f'/invoice/',
query={"limit": 10, "status": "paid"}
)["invoices"][0]["id"]
).json()["invoices"][0]["id"]
pdf = starkbank.request.get(
path=f'/invoice/{example_id}/pdf',
)
).content

self.assertGreater(len(pdf), 1000)

def test_get_qrcode(self):
example_id = starkbank.request.get(
path=f'/invoice/',
query={"limit": 10, "status": "paid"}
)["invoices"][0]["id"]
).json()["invoices"][0]["id"]

qrcode = starkbank.request.get(
path=f'/invoice/{example_id}/qrcode',
query={"size": 15},
)
).content
self.assertGreater(len(qrcode), 1000)

def test_get_reversal_receipt(self):
example_id = starkbank.request.get(
path=f'/deposit/log/',
query={"limit": 1, "types": "reversed"}
)
example_id = example_id["logs"][0]["id"]
).json()["logs"][0]["id"]
reversal_pdf = starkbank.request.get(
path=f'/deposit/log/{example_id}/pdf/',
)
).content
self.assertGreater(len(reversal_pdf), 1000)

def test_get_page(self):
Expand All @@ -68,7 +72,7 @@ def test_get_page(self):
"before": before.strftime("%Y-%m-%d"),
"status": "paid"
}
)
).json()
for item in request["invoices"]:
self.assertTrue(after.date() <= datetime.strptime(item["created"], "%Y-%m-%dT%H:%M:%S.%f%z").date() <= (before + timedelta(hours=3)).date())
self.assertEqual(10, len(request["invoices"]))
Expand All @@ -89,7 +93,7 @@ def test_get_pagination(self):
"status": "paid",
"cursor": cursor
}
)
).json()
cursor = request["cursor"]
total_items += len(request["invoices"])
for item in request["invoices"]:
Expand All @@ -114,7 +118,7 @@ def test_post(self):
request = starkbank.request.post(
path=f'/invoice/',
body=data,
)
).json()
print(request)


Expand All @@ -124,18 +128,18 @@ def test_patch(self):
initial_state = starkbank.request.get(
path=f'/invoice/',
query={"limit": 1, "status": "paid"}
)
).json()
example_id = initial_state["invoices"][0]["id"]
amount = initial_state["invoices"][0]["amount"]

starkbank.request.patch(
path=f'/invoice/{example_id}/',
body={"amount": amount - amount},
)
).json()

final_state = starkbank.request.get(
path=f'/invoice/{example_id}',
)
).json()
self.assertEqual(final_state["invoice"]["amount"],0)


Expand All @@ -155,7 +159,7 @@ def test_put(self):
body=data,
)

result = starkbank.request.get(path=f'/split-profile/')
result = starkbank.request.get(path=f'/split-profile/').json()

self.assertEqual(result["profiles"][0]["delay"], 0)
self.assertEqual(result["profiles"][0]["interval"], "day")
Expand Down Expand Up @@ -185,15 +189,15 @@ def test_delete(self):
create = starkbank.request.post(
path=f'/transfer/',
body=data,
)
).json()

starkbank.request.delete(
path=f'/transfer/{create["transfers"][0]["id"]}',
)
).json()

final_status = starkbank.request.get(
path=f'/transfer/{create["transfers"][0]["id"]}',
)["transfer"]["status"]
).json()["transfer"]["status"]

self.assertEqual(final_status, 'canceled')

Expand Down
5 changes: 3 additions & 2 deletions tests/utils/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from uuid import uuid4
import starkbank.corporateholder
from starkbank import CorporateHolder
from tests.utils.user import exampleProject
from .names.names import get_full_name
from .rule import generateExampleRuleJson

owner_id = os.environ["SANDBOX_ID"] if "SANDBOX_ID" in os.environ else exampleProject.id

example_holder = CorporateHolder(
name="Iron Bank S.A." + str(uuid4()),
Expand All @@ -14,13 +16,12 @@
],
permissions=[
starkbank.corporateholder.Permission(
owner_id=os.environ["SANDBOX_ID"],
owner_id=owner_id,
owner_type="project"
)
]
)


def generateExampleHoldersJson(n=1):
holders = []
for _ in range(n):
Expand Down

0 comments on commit 7a9d0ae

Please sign in to comment.