Mercurial > p > roundup > code
annotate test/test_anypy.py @ 7853:03c1b7ae3a68
issue2551328/issue2551264 unneeded next link and total_count incorrect
Fix: issue2551328 - REST results show next link if number of
results is a multiple of page size. (Found by members of
team 3 in the UMass-Boston CS682 Spring 2024 class.)
issue2551264 - REST X-Total-Count header and @total_size
count incorrect when paginated
These issues arose because we retrieved the exact number of rows
from the database as requested by the user using the @page_size
parameter. With this changeset, we retrieve up to 10 million + 1
rows from the database. If the total number of rows exceeds 10
million, we set the total_count indicators to -1 as an invalid
size. (The max number of requested rows (default 10 million +1)
can be modified by the admin through interfaces.py.)
By retrieving more data than necessary, we can calculate the
total count by adding @page_index*@page_size to the number of
rows returned by the query.
Furthermore, since we return more than @page_size rows, we can
determine the existence of a row at @page_size+1 and use that
information to determine if a next link should be
provided. Previously, a next link was returned if @page_size rows
were retrieved.
This change does not guarantee that the user will get @page_size
rows returned. Access policy filtering occurs after the rows are
returned, and discards rows inaccessible by the user.
Using the current @page_index/@page_size it would be difficult to
have the roundup code refetch data and make sure that a full
@page_size set of rows is returned. E.G. @page_size=100 and 5 of
them are dropped due to access restrictions. We then fetch 10
items and add items 1-4 and 6 (5 is inaccessible). There is no
way to calculate the new database offset at:
@page_index*@page_size + 6 from the URL. We would need to add an
@page_offset=6 or something.
This could work since the client isn't adding 1 to @page_index to
get the next page. Thanks to HATEOAS, the client just uses the
'next' url. But I am not going to cross that bridge without a
concrete use case.
This can also be handled client side by merging a short response
with the next response and re-paginating client side.
Also added extra index markers to the docs to highlight use of
interfaces.py.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 01 Apr 2024 09:57:16 -0400 |
| parents | ebb03b8cee4d |
| children |
| rev | line source |
|---|---|
|
6532
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
1 """Random tests for anypy modules""" |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
2 |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
3 |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
4 import unittest |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
5 from roundup.anypy.strings import repr_export, eval_import |
|
7824
ebb03b8cee4d
test: invoke test function in cmp_.py.
John Rouillard <rouilj@ieee.org>
parents:
7766
diff
changeset
|
6 from roundup.anypy.cmp_ import _test |
|
6532
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
7 |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
8 import sys |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
9 _py3 = sys.version_info[0] > 2 |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
10 |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
11 class StringsTest(unittest.TestCase): |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
12 |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
13 def test_import_params(self): |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
14 """ issue2551170 - handle long int in history/journal |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
15 params tuple |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
16 """ |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
17 # python2 export with id as number |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
18 val = eval_import("('issue', 2345L, 'status')") |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
19 self.assertSequenceEqual(val, ('issue', 2345, 'status')) |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
20 |
|
7766
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
21 # eval a tuple e.g. date representation |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
22 val = eval_import("(2022, 9, 6, 3, 58, 4.776, 0, 0, 0)") |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
23 self.assertSequenceEqual(val, (2022, 9, 6, 3, 58, 4.776, 0, 0, 0)) |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
24 |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
25 # eval a boolean |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
26 val = eval_import("False") |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
27 self.assertEqual(val, False) |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
28 val = eval_import("True") |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
29 self.assertEqual(val, True) |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
30 |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
31 # check syntax error |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
32 for testcase in ['true', '(2004, 10, 20', "2000, 10, 22)", |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
33 "test'", '"test']: |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
34 with self.assertRaises(ValueError) as m: |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
35 val = eval_import(testcase) |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
36 print(m.exception) |
|
c65e0a725c88
fix: replace eval with ast.literal_eval; ruff linting
John Rouillard <rouilj@ieee.org>
parents:
6532
diff
changeset
|
37 |
|
6532
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
38 # python3 export with id as number |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
39 val = eval_import("('issue', 2345, 'status')") |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
40 self.assertSequenceEqual(val, ('issue', 2345, 'status')) |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
41 |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
42 # python2 or python3 export with id as string |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
43 val = eval_import("('issue', '2345', 'status')") |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
44 self.assertSequenceEqual(val, ('issue', '2345', 'status')) |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
45 |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
46 def test_export_params(self): |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
47 """ issue2551170 - handle long int in history/journal |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
48 params tuple |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
49 """ |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
50 # python2 export with id as number |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
51 if _py3: |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
52 val = repr_export(('issue', 2345, 'status')) |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
53 self.assertEqual(val, "('issue', 2345, 'status')") |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
54 else: |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
55 val = repr_export(('issue', long(2345), 'status')) |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
56 self.assertEqual(val, "('issue', 2345L, 'status')") |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
57 |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
58 # python2 or python3 export with id as string |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
59 val = repr_export(('issue', '2345', 'status')) |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
60 self.assertEqual(val, "('issue', '2345', 'status')") |
|
e4db9d0b85c7
test for issue2551170 process python 2 long under python3
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
61 |
|
7824
ebb03b8cee4d
test: invoke test function in cmp_.py.
John Rouillard <rouilj@ieee.org>
parents:
7766
diff
changeset
|
62 class MiscTest(unittest.TestCase): |
|
ebb03b8cee4d
test: invoke test function in cmp_.py.
John Rouillard <rouilj@ieee.org>
parents:
7766
diff
changeset
|
63 |
|
ebb03b8cee4d
test: invoke test function in cmp_.py.
John Rouillard <rouilj@ieee.org>
parents:
7766
diff
changeset
|
64 def test_cmp_(self): |
|
ebb03b8cee4d
test: invoke test function in cmp_.py.
John Rouillard <rouilj@ieee.org>
parents:
7766
diff
changeset
|
65 _test() |
