Add limit and offset parameters to get_assertions_by_badge#265
Add limit and offset parameters to get_assertions_by_badge#265Daniel-1600 wants to merge 1 commit intofedora-infra:developfrom
Conversation
sdglitched
left a comment
There was a problem hiding this comment.
Thank you for working on this.
Please make the requested changes, along with signing the commit and following the 50-character rule for commit messages.
Also, specify the AI usage as per ACP and explain what your thought process was during the development as per the latest decision.
| return self.session.query(Assertion).filter_by(person_id=person.id).all() | ||
|
|
||
| def get_assertions_by_badge(self, badge_id): | ||
| def get_assertions_by_badge(self, badge_id, limit=None, offset=None): |
There was a problem hiding this comment.
Please maintain consistency across the codebase.
| def get_assertions_by_badge(self, badge_id, limit=None, offset=None): | |
| def get_assertions_by_badge(self, badge_id: str, begin: int, limit: int): |
| return ( | ||
| self.session.query(Assertion) | ||
| .filter(func.lower(Assertion.badge_id) == func.lower(badge_id)) | ||
| .order_by(Assertion.issued_on) |
There was a problem hiding this comment.
Having the oldest assertion first is not very helpful. Use a similar sorting to that used in
tahrir-api/tahrir_api/dbapi.py
Line 875 in 43e1906
| .order_by(Assertion.issued_on) | |
| .order_by(Assertion.issued_on.desc()) |
| self.session.query(Assertion) | ||
| .filter(func.lower(Assertion.badge_id) == func.lower(badge_id)) | ||
| .order_by(Assertion.issued_on) | ||
| .offset(offset) |
There was a problem hiding this comment.
| .offset(offset) | |
| .offset(begin) |
| """ | ||
| Get all assertions of a particular badge. | ||
|
|
||
| :type badge_id: str | ||
| :param badge_id: Badge id to get assertions for. | ||
| """ |
There was a problem hiding this comment.
Add the new parameters in the docstring.
| @pytest.fixture | ||
| def multiple_assertions(api, dummy_badge_id): | ||
| """Add multiple assertions for the same badge to test pagination.""" | ||
| emails = [f"user{i}@tester.com" for i in range(5)] | ||
| for email in emails: | ||
| api.add_person(email) | ||
| api.add_assertion(dummy_badge_id, email, None, f"link_{email}") | ||
| return emails | ||
|
|
||
|
|
||
| def test_get_assertions_by_badge_limit(api, dummy_badge_id, multiple_assertions): | ||
| result = api.get_assertions_by_badge(dummy_badge_id, limit=3) | ||
| assert len(result) == 3 | ||
|
|
||
|
|
||
| def test_get_assertions_by_badge_offset(api, dummy_badge_id, multiple_assertions): | ||
| all_results = api.get_assertions_by_badge(dummy_badge_id) | ||
| offset_results = api.get_assertions_by_badge(dummy_badge_id, offset=2) | ||
| assert len(offset_results) == len(all_results) - 2 | ||
|
|
||
|
|
||
| def test_get_assertions_by_badge_limit_and_offset(api, dummy_badge_id, multiple_assertions): | ||
| result = api.get_assertions_by_badge(dummy_badge_id, limit=2, offset=1) | ||
| assert len(result) == 2 | ||
|
|
||
|
|
||
| def test_get_assertions_by_badge_no_limit_no_offset(api, dummy_badge_id, multiple_assertions): | ||
| result = api.get_assertions_by_badge(dummy_badge_id) | ||
| assert len(result) == 5 |
There was a problem hiding this comment.
Add test cases in a new commit.
solves #264