-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Correctly handle pagination. (#37)
- Loading branch information
1 parent
76130c4
commit 1f4c9bb
Showing
3 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from data_resource_api.api.v1_0_0 import ResourceHandler | ||
from expects import expect, be_an, raise_error, have_property, equal, be_empty, be | ||
import json | ||
|
||
|
||
class TestComputeOffset(object): | ||
def test_compute_offset(self): | ||
handler = ResourceHandler() | ||
|
||
expect(handler.compute_offset(1, 20)).to(equal(0)) | ||
# expect(handler.compute_offset(53, 19)).to(equal(0)) | ||
# expect(handler.compute_offset(0, 20)).to(equal(0)) | ||
|
||
# def test_build_links(self): | ||
# handler = ResourceHandler() | ||
|
||
# items = [ | ||
# handler.build_links('test', 0, 20, 5), | ||
# handler.build_links('test', 1, 20, 55), | ||
# handler.build_links('test', 1, -20, 55) | ||
# ] | ||
|
||
# for item in items: | ||
# print(json.dumps(item, indent=4)) | ||
|
||
def test_compute_page(self): | ||
handler = ResourceHandler() | ||
|
||
items = [ | ||
handler.compute_page(0, 20), | ||
handler.compute_page(1, 20), | ||
handler.compute_page(20, 20), | ||
handler.compute_page(21, 20), | ||
handler.compute_page(25, 20) | ||
] | ||
|
||
for item in items: | ||
print(item) | ||
|
||
expect(handler.compute_page(0, 20)).to(equal(1)) | ||
expect(handler.compute_page(1, 20)).to(equal(1)) | ||
expect(handler.compute_page(19, 20)).to(equal(1)) | ||
expect(handler.compute_page(20, 20)).to(equal(2)) | ||
expect(handler.compute_page(99, 20)).to(equal(5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters