Skip to content

Add limit and offset parameters to get_assertions_by_badge#265

Open
Daniel-1600 wants to merge 1 commit intofedora-infra:developfrom
Daniel-1600:fix/get-assertions-by-badge-pagination
Open

Add limit and offset parameters to get_assertions_by_badge#265
Daniel-1600 wants to merge 1 commit intofedora-infra:developfrom
Daniel-1600:fix/get-assertions-by-badge-pagination

Conversation

@Daniel-1600
Copy link
Copy Markdown

solves #264

Copy link
Copy Markdown
Contributor

@sdglitched sdglitched left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please maintain consistency across the codebase.

Suggested change
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the oldest assertion first is not very helpful. Use a similar sorting to that used in

result = self.session.query(Assertion).order_by(Assertion.issued_on.desc())

Suggested change
.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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.offset(offset)
.offset(begin)

Comment on lines 896 to 901
"""
Get all assertions of a particular badge.

:type badge_id: str
:param badge_id: Badge id to get assertions for.
"""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the new parameters in the docstring.

Comment on lines +680 to +708
@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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test cases in a new commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cle Community Linux Engineering enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add offset/limit support to get_assertions_by_badge for pagination

3 participants