|
| 1 | +from bunq.sdk import client |
| 2 | +from bunq.sdk import exception |
| 3 | +from tests.bunq_test import BunqSdkTestCase |
| 4 | + |
| 5 | + |
| 6 | +class TestPagination(BunqSdkTestCase): |
| 7 | + """ |
| 8 | + Tests: |
| 9 | + Pagination |
| 10 | + """ |
| 11 | + |
| 12 | + _PAGINATION_OLDER_ID_CUSTOM = 1 |
| 13 | + _PAGINATION_NEWER_ID_CUSTOM = 2 |
| 14 | + _PAGINATION_FUTURE_ID_CUSTOM = 3 |
| 15 | + _PAGINATION_COUNT_CUSTOM = 5 |
| 16 | + |
| 17 | + def test_get_url_params_count_only(self): |
| 18 | + pagination = self.create_pagination_with_all_properties_set() |
| 19 | + url_params_count_only_expected = { |
| 20 | + client.Pagination.PARAM_COUNT: str(self._PAGINATION_COUNT_CUSTOM), |
| 21 | + } |
| 22 | + |
| 23 | + self.assertEqual(url_params_count_only_expected, |
| 24 | + pagination.url_params_count_only) |
| 25 | + |
| 26 | + def create_pagination_with_all_properties_set(self): |
| 27 | + """ |
| 28 | + :rtype: Pagination |
| 29 | + """ |
| 30 | + |
| 31 | + pagination = client.Pagination() |
| 32 | + pagination.older_id = self._PAGINATION_OLDER_ID_CUSTOM |
| 33 | + pagination.newer_id = self._PAGINATION_NEWER_ID_CUSTOM |
| 34 | + pagination.future_id = self._PAGINATION_FUTURE_ID_CUSTOM |
| 35 | + pagination.count = self._PAGINATION_COUNT_CUSTOM |
| 36 | + |
| 37 | + return pagination |
| 38 | + |
| 39 | + def test_get_url_params_previous_page(self): |
| 40 | + pagination = self.create_pagination_with_all_properties_set() |
| 41 | + url_params_previous_page_expected = { |
| 42 | + client.Pagination.PARAM_COUNT: str(self._PAGINATION_COUNT_CUSTOM), |
| 43 | + client.Pagination.PARAM_OLDER_ID: |
| 44 | + str(self._PAGINATION_OLDER_ID_CUSTOM), |
| 45 | + } |
| 46 | + |
| 47 | + self.assertTrue(pagination.has_previous_page()) |
| 48 | + self.assertEqual(url_params_previous_page_expected, |
| 49 | + pagination.url_params_previous_page) |
| 50 | + |
| 51 | + def test_get_url_params_previous_page_no_count(self): |
| 52 | + pagination = self.create_pagination_with_all_properties_set() |
| 53 | + pagination.count = None |
| 54 | + url_params_previous_page_expected = { |
| 55 | + client.Pagination.PARAM_OLDER_ID: |
| 56 | + str(self._PAGINATION_OLDER_ID_CUSTOM), |
| 57 | + } |
| 58 | + |
| 59 | + self.assertTrue(pagination.has_previous_page()) |
| 60 | + self.assertEqual(url_params_previous_page_expected, |
| 61 | + pagination.url_params_previous_page) |
| 62 | + |
| 63 | + def test_get_url_params_next_page_newer(self): |
| 64 | + pagination = self.create_pagination_with_all_properties_set() |
| 65 | + url_params_next_page_expected = { |
| 66 | + client.Pagination.PARAM_COUNT: str(self._PAGINATION_COUNT_CUSTOM), |
| 67 | + client.Pagination.PARAM_NEWER_ID: |
| 68 | + str(self._PAGINATION_NEWER_ID_CUSTOM), |
| 69 | + } |
| 70 | + |
| 71 | + self.assertTrue(pagination.has_next_page_assured()) |
| 72 | + self.assertEqual(url_params_next_page_expected, |
| 73 | + pagination.url_params_next_page) |
| 74 | + |
| 75 | + def test_get_url_params_next_page_newer_no_count(self): |
| 76 | + pagination = self.create_pagination_with_all_properties_set() |
| 77 | + pagination.count = None |
| 78 | + url_params_next_page_expected = { |
| 79 | + client.Pagination.PARAM_NEWER_ID: |
| 80 | + str(self._PAGINATION_NEWER_ID_CUSTOM), |
| 81 | + } |
| 82 | + |
| 83 | + self.assertTrue(pagination.has_next_page_assured()) |
| 84 | + self.assertEqual(url_params_next_page_expected, |
| 85 | + pagination.url_params_next_page) |
| 86 | + |
| 87 | + def test_get_url_params_next_page_future(self): |
| 88 | + pagination = self.create_pagination_with_all_properties_set() |
| 89 | + pagination.newer_id = None |
| 90 | + url_params_next_page_expected = { |
| 91 | + client.Pagination.PARAM_COUNT: str(self._PAGINATION_COUNT_CUSTOM), |
| 92 | + client.Pagination.PARAM_NEWER_ID: |
| 93 | + str(self._PAGINATION_FUTURE_ID_CUSTOM), |
| 94 | + } |
| 95 | + |
| 96 | + self.assertFalse(pagination.has_next_page_assured()) |
| 97 | + self.assertEqual(url_params_next_page_expected, |
| 98 | + pagination.url_params_next_page) |
| 99 | + |
| 100 | + def test_get_url_params_next_page_future_no_count(self): |
| 101 | + pagination = self.create_pagination_with_all_properties_set() |
| 102 | + pagination.newer_id = None |
| 103 | + pagination.count = None |
| 104 | + url_params_next_page_expected = { |
| 105 | + client.Pagination.PARAM_NEWER_ID: |
| 106 | + str(self._PAGINATION_FUTURE_ID_CUSTOM), |
| 107 | + } |
| 108 | + |
| 109 | + self.assertFalse(pagination.has_next_page_assured()) |
| 110 | + self.assertEqual(url_params_next_page_expected, |
| 111 | + pagination.url_params_next_page) |
| 112 | + |
| 113 | + def test_get_url_params_prev_page_from_pagination_with_no_prev_page(self): |
| 114 | + pagination = self.create_pagination_with_all_properties_set() |
| 115 | + pagination.older_id = None |
| 116 | + |
| 117 | + def access_url_params_previous_page(): |
| 118 | + _ = pagination.url_params_previous_page |
| 119 | + |
| 120 | + self.assertRaises(exception.BunqException, |
| 121 | + access_url_params_previous_page) |
| 122 | + |
| 123 | + def test_get_url_params_next_page_from_pagination_with_no_next_page(self): |
| 124 | + pagination = self.create_pagination_with_all_properties_set() |
| 125 | + pagination.newer_id = None |
| 126 | + pagination.future_id = None |
| 127 | + |
| 128 | + def access_url_params_next_page(): |
| 129 | + _ = pagination.url_params_next_page |
| 130 | + |
| 131 | + self.assertRaises(exception.BunqException, access_url_params_next_page) |
0 commit comments