Skip to content

Commit 4e60e06

Browse files
committed
PR feedback: tighter message assertions
1 parent 2fd7799 commit 4e60e06

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

test/unit/features/test_pagination_option_validation.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616

1717
from unittest import TestCase
18-
from ibmcloudant.features.pagination import _MIN_LIMIT, _MAX_LIMIT, PagerType, Pagination
18+
from ibmcloudant.features.pagination import _DOCS_KEY_ERROR, _MIN_LIMIT, _MAX_LIMIT, _VIEW_KEY_ERROR, PagerType, Pagination
1919

2020
class TestPaginationOptionValidation(TestCase):
2121

@@ -39,31 +39,35 @@ def test_valid_limits(self):
3939
def test_invalid_limits(self):
4040
test_limits = (_MIN_LIMIT - 1, _MAX_LIMIT + 1)
4141
for limit in test_limits:
42+
if (limit == _MIN_LIMIT -1):
43+
msg_regex = f'The provided limit {limit} is lower than the minimum page size value of 1.'
44+
elif (limit == _MAX_LIMIT + 1):
45+
msg_regex= f'The provided limit {limit} exceeds the maximum page size value of 200.'
4246
for pager_type in self.all_paginations:
4347
with self.subTest(pager_type):
44-
with self.assertRaises(ValueError, msg='There should be a ValueError for invalid limits.'):
48+
with self.assertRaisesRegex(ValueError, msg_regex):
4549
Pagination.new_pagination(None, pager_type, limit=limit)
4650

4751
def test_keys_value_error_for_view_like(self):
4852
for pager_type in self.view_like_paginations:
4953
with self.subTest(pager_type):
50-
with self.assertRaises(ValueError, msg=f'There should be a ValueError for {pager_type} with keys.'):
54+
with self.assertRaisesRegex(ValueError, 'The option \'keys\' is invalid when using pagination.'):
5155
Pagination.new_pagination(None, pager_type, keys=['a','b','c'])
5256

5357
def test_facet_value_errors_for_search(self):
5458
for invalid_opt in ('counts', 'group_field', 'group_limit', 'group_sort', 'ranges',):
5559
with self.subTest(invalid_opt):
56-
with self.assertRaises(ValueError, msg=f'There should be a ValueError for search with option {invalid_opt}.'):
60+
with self.assertRaisesRegex(ValueError, f'The option \'{invalid_opt}\' is invalid when using pagination.'):
5761
Pagination.new_pagination(None, PagerType.POST_SEARCH, **{invalid_opt: 'test value'})
5862

5963
def test_key_value_error_for_docs(self):
6064
for pager_type in self.all_doc_paginations:
6165
with self.subTest(pager_type):
62-
with self.assertRaises(ValueError, msg=f'There should be a ValueError for {pager_type} with key.'):
66+
with self.assertRaisesRegex(ValueError, f'The option \'key\' is invalid when using pagination. {_DOCS_KEY_ERROR}'):
6367
Pagination.new_pagination(None, pager_type, key='a')
6468

6569
def test_key_value_error_for_views(self):
6670
for pager_type in self.view_paginations:
6771
with self.subTest(pager_type):
68-
with self.assertRaises(ValueError, msg=f'There should be a ValueError for {pager_type} with key.'):
72+
with self.assertRaisesRegex(ValueError, f'The option \'key\' is invalid when using pagination. {_VIEW_KEY_ERROR}'):
6973
Pagination.new_pagination(None, pager_type, key={})

0 commit comments

Comments
 (0)