11from 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_
25from tests .bunq_test import BunqSdkTestCase
36from 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