Skip to content

Commit 22b9d1f

Browse files
author
Kevin Hellemun
committed
Removed magic values. (#77)
1 parent 43ae1aa commit 22b9d1f

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

bunq/sdk/json/adapters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
class AnchoredObjectModelAdapter(converter.JsonAdapter):
1515
_ERROR_MODEL_NOT_FOUND = '{} is not in endpoint nor object.'
1616

17+
__STRING_FORMAT_UNDERSCORE = '_'
18+
1719
_override_field_map = {
1820
'ScheduledPayment': 'SchedulePayment',
1921
'ScheduledInstance': 'ScheduleInstance',
@@ -56,7 +58,7 @@ def _get_object_class(cls, class_name):
5658
:rtype: core.BunqModel
5759
"""
5860

59-
class_name = class_name.lstrip('_')
61+
class_name = class_name.lstrip(cls.__STRING_FORMAT_UNDERSCORE)
6062

6163
if class_name in cls._override_field_map:
6264
class_name = cls._override_field_map[class_name]

bunq/sdk/model/core.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class BunqModel(object):
1818
# The very first index of an array
1919
_INDEX_FIRST = 0
2020

21+
__STRING_FORMAT_EMPTY = ''
22+
__STRING_FORMAT_FIELD_FOR_REQUEST_ONE_UNDERSCORE = '_field_for_request'
23+
__STRING_FORMAT_FIELD_FOR_REQUEST_TWO_UNDERSCORE = '__field_for_request'
24+
2125
def is_all_field_none(self):
2226
raise NotImplementedError
2327

@@ -168,7 +172,13 @@ def _determine_monetary_account_id(cls, monetary_account_id=None):
168172

169173
@classmethod
170174
def _remove_field_for_request(cls, json_str: str):
171-
return json_str.replace('__field_for_request', '').replace('_field_for_request', '')
175+
return json_str.replace(
176+
cls.__STRING_FORMAT_FIELD_FOR_REQUEST_TWO_UNDERSCORE,
177+
cls.__STRING_FORMAT_EMPTY
178+
).replace(
179+
cls.__STRING_FORMAT_FIELD_FOR_REQUEST_ONE_UNDERSCORE,
180+
cls.__STRING_FORMAT_EMPTY
181+
)
172182

173183

174184
class Id(BunqModel):

tests/bunq_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class BunqSdkTestCase(unittest.TestCase):
3737

3838
__SPENDING_MONEY_AMOUNT = '500'
3939
__CURRENCY_EUR = 'EUR'
40-
__POINTER_EMAIL = 'EMAIL'
40+
_POINTER_EMAIL = 'EMAIL'
4141
__SPENDING_MONEY_RECIPIENT = '[email protected]'
4242
__REQUEST_SPENDING_DESCRIPTION = 'sdk python test, thanks daddy <3'
4343

@@ -46,7 +46,7 @@ class BunqSdkTestCase(unittest.TestCase):
4646

4747
__SECOND_MONETARY_ACCOUNT_DESCRIPTION = 'test account python'
4848

49-
__EMAIL_BRAVO = '[email protected]'
49+
_EMAIL_BRAVO = '[email protected]'
5050

5151
__TIME_OUT_AUTO_ACCEPT_SPENDING_MONEY = 0.5
5252

@@ -77,7 +77,7 @@ def __request_spending_money(self):
7777
endpoint.RequestInquiry.create(
7878
object_.Amount(self.__SPENDING_MONEY_AMOUNT, self.__CURRENCY_EUR),
7979
object_.Pointer(
80-
self.__POINTER_EMAIL,
80+
self._POINTER_EMAIL,
8181
self.__SPENDING_MONEY_RECIPIENT
8282
),
8383
self.__REQUEST_SPENDING_DESCRIPTION,
@@ -86,7 +86,7 @@ def __request_spending_money(self):
8686
endpoint.RequestInquiry.create(
8787
object_.Amount(self.__SPENDING_MONEY_AMOUNT, self.__CURRENCY_EUR),
8888
object_.Pointer(
89-
self.__POINTER_EMAIL,
89+
self._POINTER_EMAIL,
9090
self.__SPENDING_MONEY_RECIPIENT
9191
),
9292
self.__REQUEST_SPENDING_DESCRIPTION,
@@ -113,7 +113,7 @@ def _get_pointer_bravo(self):
113113
:rtype: object_.Pointer
114114
"""
115115

116-
return object_.Pointer(self.__POINTER_EMAIL, self.__EMAIL_BRAVO)
116+
return object_.Pointer(self._POINTER_EMAIL, self._EMAIL_BRAVO)
117117

118118
def _get_alias_second_account(self):
119119
"""

tests/model/generated/endpoint/test_payment.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class TestPayment(BunqSdkTestCase):
2121
_PAYMENT_CURRENCY = 'EUR'
2222
_PAYMENT_DESCRIPTION = 'Python unit test'
2323
_PAYMENT_CHAT_TEXT_MESSAGE = 'send from python test'
24-
_USER_ID = Config.get_user_id()
24+
25+
_MAXIMUM_PAYMENT_IN_BATCH = 10
2526

2627
def test_payment_to_other_user(self):
2728
"""
@@ -31,8 +32,8 @@ def test_payment_to_other_user(self):
3132
without errors
3233
"""
3334

34-
Payment.create(
35-
Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
35+
endpoint.Payment.create(
36+
object_.Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
3637
self._get_pointer_bravo(),
3738
self._PAYMENT_DESCRIPTION
3839
)
@@ -45,8 +46,8 @@ def test_payment_to_other_account(self):
4546
without errors
4647
"""
4748

48-
Payment.create(
49-
Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
49+
endpoint.Payment.create(
50+
object_.Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
5051
self._get_alias_second_account(),
5152
self._PAYMENT_DESCRIPTION
5253
)
@@ -59,43 +60,46 @@ def test_payment_chat(self):
5960
without errors
6061
"""
6162

62-
payment_id = Payment.create(
63-
Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
63+
payment_id = endpoint.Payment.create(
64+
object_.Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
6465
self._get_pointer_bravo(),
6566
self._PAYMENT_DESCRIPTION
6667
).value
6768

68-
chat_id = PaymentChat.create(payment_id).value
69+
chat_id = endpoint.PaymentChat.create(payment_id).value
6970

70-
ChatMessageText.create(chat_id, self._PAYMENT_CHAT_TEXT_MESSAGE)
71+
endpoint.ChatMessageText.create(chat_id, self._PAYMENT_CHAT_TEXT_MESSAGE)
7172

7273
def test_payment_batch(self):
73-
response_create: BunqResponseInt = PaymentBatch.create(
74-
self.__create_payment_list()
75-
)
74+
response_create: endpoint.BunqResponseInt =\
75+
endpoint.PaymentBatch.create(
76+
self.__create_payment_list()
77+
)
7678

7779
self.assertIsNotNone(response_create)
7880

79-
response_get: BunqResponsePaymentBatch =\
80-
PaymentBatch.get(response_create.value)
81+
response_get: endpoint.BunqResponsePaymentBatch =\
82+
endpoint.PaymentBatch.get(response_create.value)
8183

8284
self.assertIsNotNone(response_get)
8385
self.assertFalse(response_get.value.is_all_field_none())
8486

85-
@staticmethod
86-
def __create_payment_list() -> List[Payment]:
87+
def __create_payment_list(self) -> List[endpoint.Payment]:
8788
"""
8889
:rtype: List[Payment]
8990
"""
9091

91-
all_payment: List[Payment] = []
92+
all_payment: List[endpoint.Payment] = []
9293

93-
while len(all_payment) < 10:
94+
while len(all_payment) < self._MAXIMUM_PAYMENT_IN_BATCH:
9495
all_payment.append(
95-
Payment(
96-
Amount('0.01', 'EUR'),
97-
Pointer('EMAIL', '[email protected]'),
98-
'Python sdk payment batch test.'
96+
endpoint.Payment(
97+
object_.Amount(
98+
self._PAYMENT_AMOUNT_EUR,
99+
self._PAYMENT_CURRENCY
100+
),
101+
object_.Pointer(self._POINTER_EMAIL, self._EMAIL_BRAVO),
102+
self._PAYMENT_DESCRIPTION
99103
)
100104
)
101105

0 commit comments

Comments
 (0)