Skip to content

[fix] Ensure recent items are shown first in the REST API - #1044

Merged
nemesifier merged 7 commits into
openwisp:masterfrom
stktyagi:issue/1040-added-recency-tests
Jun 12, 2025
Merged

[fix] Ensure recent items are shown first in the REST API #1044
nemesifier merged 7 commits into
openwisp:masterfrom
stktyagi:issue/1040-added-recency-tests

Conversation

@stktyagi

Copy link
Copy Markdown
Member

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #1040.

Description of Changes

Added ordering by creation date (descending) to the Base command view to ensure consistent and expected command ordering and checked all other list apis to ensure recency.
Tests to supported the same added.

@stktyagi

Copy link
Copy Markdown
Member Author

@nemesifier
I've created a new pull request which follows the contributing guidelines.

@stktyagi

Copy link
Copy Markdown
Member Author

updated commit message to prevent build failure.

@nemesifier nemesifier changed the title Issue/1040 added recency tests [fix] Ensure recent items are shown first in the REST API May 23, 2025
@nemesifier nemesifier added the bug label May 23, 2025
Comment thread openwisp_controller/connection/api/views.py Outdated
@coveralls

coveralls commented May 23, 2025

Copy link
Copy Markdown

Coverage Status

coverage: 98.816%. remained the same
when pulling 2559be8 on stktyagi:issue/1040-added-recency-tests
into 85eee35 on openwisp:master.

@nemesifier nemesifier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@stktyagi it looks good to me! I just want to find some time to double check this is the only endpoint where we need to fix this.

@nemesifier nemesifier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other endpoints I found that are suffering from the same issue:

  • /api/v1/controller/group/
  • /api/v1/controller/device/

Can we take advantage and fix those as well?

Regarding the tests, I recommend extending the existing tests for these endpoints with a subtest which checks the ordering, let's try to reduce the new lines to the bare minimuim required to test the ordering effectively.

Please also update your local copy of openwisp-utils to the latest master, reinstall it to update the dependencies and run openwisp-qa-format again as there's been slight changes to the QA dependencies and configuration (see openwisp/openwisp-utils#473 and openwisp/openwisp-utils#456).

See also my comments below.

Comment thread openwisp_controller/connection/tests/test_api.py Outdated
Comment thread openwisp_controller/connection/tests/test_api.py Outdated
stktyagi and others added 6 commits June 6, 2025 12:46
Fixed bug where device connections were not properly filtered in the API response with recency with new tests added.
Fixes #1040
Fixed bug where device connections were not properly filtered in the API response with recency with new tests added. All the command list endpoint models were updated.

Fixes #1040
Added and tested recency tests for config /group and /device endpoints. Updated tests(added as subtests) for previously fixed and recently fixed endpoints.

Fixes #1040
@stktyagi

stktyagi commented Jun 6, 2025

Copy link
Copy Markdown
Member Author

@nemesifier greetings,
updated test files with new subtests instead of redundant test functions and updated logic to avoid bloat.
Tested for all endpoints which include 2 of the previous ones, /group and /device.
complied with new qa-tests.

@stktyagi
stktyagi requested a review from nemesifier June 8, 2025 07:51
@pandafy pandafy moved this from To do (general) to In progress in OpenWISP Contributor's Board Jun 10, 2025

@nemesifier nemesifier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I must have made some confusion during the previous review because I see that device and device group are already ordered properly. Well, that's good to know, thanks for adding the tests! I did some minor simplifications, should be ready to merge.

r = self.client.get(path)
self.assertEqual(r.status_code, 200)
with self.subTest("should return devices ordered by most recent first"):
Device.objects.all().delete()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this needed? We could avoid it and add only 2 more devices so we end up with 3.

@github-project-automation github-project-automation Bot moved this from In progress to Reviewer approved in OpenWISP Priorities for next releases Jun 12, 2025
@nemesifier
nemesifier merged commit d449e9b into openwisp:master Jun 12, 2025
@github-project-automation github-project-automation Bot moved this from In progress to Done in OpenWISP Contributor's Board Jun 12, 2025
@github-project-automation github-project-automation Bot moved this from Reviewer approved to Done in OpenWISP Priorities for next releases Jun 12, 2025
@stktyagi
stktyagi deleted the issue/1040-added-recency-tests branch June 13, 2025 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

[bug] REST API showing most recent as last

4 participants