Skip to content

Commit 2b80995

Browse files
committed
Allow for multiple permitted IPs; finish Pagination Scenario test [#20]
1 parent 57b7e8e commit 2b80995

File tree

3 files changed

+94
-7
lines changed

3 files changed

+94
-7
lines changed

tests/assets/config.example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"USER_ID": "xxxx",
44
"MONETARY_ACCOUNT_ID": "xxxx",
55
"MONETARY_ACCOUNT_ID2": "xxxx",
6-
"ipAddress": "<Ip address>",
6+
"PERMITTED_IPS": "<IP address>,<IP address 2>",
77
"AttachmentPublicTest":{
88
"CONTENT_TYPE": "image/png",
99
"DESCRIPTION": "TEST PNG PHP",

tests/config.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66

77
class Config:
8-
_FIELD_IP_ADDRESS_ALLOWED = "ipAddress"
8+
# Delimiter between the IP addresses in the PERMITTED_IPS field.
9+
_DELIMITER_IPS = ","
10+
11+
# Field constants
12+
_FIELD_PERMITTED_IPS = "PERMITTED_IPS"
913
_FIELD_COUNTER_PARTY_OTHER = "CounterPartyOther"
1014
_FIELD_COUNTER_PARTY_SELF = "CounterPartySelf"
1115
_FIELD_TYPE = "Type"
@@ -116,12 +120,17 @@ def get_pointer_counter_party_other(cls):
116120
return Pointer(type_, alias)
117121

118122
@classmethod
119-
def get_ip_address(cls):
123+
def get_permitted_ips(cls):
120124
"""
121-
:rtype: str
125+
:rtype: str[]
122126
"""
123127

124-
return cls._get_config_file()[cls._FIELD_IP_ADDRESS_ALLOWED]
128+
permitted_ips_str = cls._get_config_file()[cls._FIELD_PERMITTED_IPS]
129+
130+
if not permitted_ips_str:
131+
return []
132+
else:
133+
return permitted_ips_str.split(cls._DELIMITER_IPS)
125134

126135
@classmethod
127136
def _get_config_file(cls):

tests/test_pagination_scenario.py

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from bunq.sdk import client
2+
from bunq.sdk.json import converter
3+
from bunq.sdk.model.generated import endpoint
4+
from bunq.sdk.model.generated import object_
25
from tests.bunq_test import BunqSdkTestCase
36
from tests.bunq_test import Config
47

@@ -13,7 +16,7 @@ class TestPaginationScenario(BunqSdkTestCase):
1316
def setUpClass(cls):
1417
cls._USER_ID = Config.get_user_id()
1518
cls._MONETARY_ACCOUNT_ID = Config.get_monetary_account_id_1()
16-
cls._COUNTER_PARTY_ALIAS_OTHER =\
19+
cls._COUNTER_PARTY_ALIAS_OTHER = \
1720
Config.get_pointer_counter_party_other()
1821
cls._API_CONTEXT = cls._get_api_context()
1922
cls._PAYMENT_LISTING_PAGE_SIZE = 2
@@ -23,4 +26,79 @@ def setUpClass(cls):
2326
cls._CURRENCY = 'EUR'
2427
cls._PAYMENT_DESCRIPTION = 'Python test Payment'
2528

26-
29+
def test_api_scenario_payment_listing_with_pagination(self):
30+
self._ensure_enough_payments()
31+
payments_expected = self._payments_required()
32+
pagination = client.Pagination()
33+
pagination.count = self._PAYMENT_LISTING_PAGE_SIZE
34+
35+
response_latest = self._list_payments(pagination.url_params_count_only)
36+
pagination_latest = response_latest.pagination
37+
response_previous = self._list_payments(
38+
pagination_latest.url_params_previous_page
39+
)
40+
pagination_previous = response_previous.pagination
41+
response_previous_next = self._list_payments(
42+
pagination_previous.url_params_next_page
43+
)
44+
payments_previous = response_previous.value
45+
payments_previous_next = response_previous_next.value
46+
payments_actual = payments_previous_next + payments_previous
47+
payments_expected_serialized = converter.serialize(payments_expected)
48+
payments_actual_serialized = converter.serialize(payments_actual)
49+
50+
self.assertEqual(payments_expected_serialized,
51+
payments_actual_serialized)
52+
53+
def _ensure_enough_payments(self):
54+
"""
55+
:rtype: None
56+
"""
57+
58+
for i in range(self._payment_missing_count):
59+
self._create_payment()
60+
61+
@property
62+
def _payment_missing_count(self):
63+
"""
64+
:rtype: int
65+
"""
66+
67+
return self._PAYMENT_REQUIRED_COUNT_MINIMUM - \
68+
len(self._payments_required())
69+
70+
def _payments_required(self):
71+
"""
72+
:rtype: list[endpoint.Payment]
73+
"""
74+
75+
pagination = client.Pagination()
76+
pagination.count = self._PAYMENT_REQUIRED_COUNT_MINIMUM
77+
78+
return self._list_payments(pagination.url_params_count_only).value
79+
80+
def _list_payments(self, params):
81+
"""
82+
:type params: dict[str, str]
83+
84+
:rtype BunqResponse[list[Payment]]
85+
"""
86+
87+
return endpoint.Payment.list(self._API_CONTEXT, self._USER_ID,
88+
self._MONETARY_ACCOUNT_ID, params)
89+
90+
def _create_payment(self):
91+
"""
92+
:rtype: None
93+
"""
94+
95+
request_map = {
96+
endpoint.Payment.FIELD_AMOUNT:
97+
object_.Amount(self._AMOUNT_EUR, self._CURRENCY),
98+
endpoint.Payment.FIELD_DESCRIPTION: self._PAYMENT_DESCRIPTION,
99+
endpoint.Payment.FIELD_COUNTERPARTY_ALIAS:
100+
self._COUNTER_PARTY_ALIAS_OTHER,
101+
}
102+
103+
endpoint.Payment.create(self._API_CONTEXT, request_map,
104+
self._USER_ID, self._MONETARY_ACCOUNT_ID)

0 commit comments

Comments
 (0)