moved 3a-3c before 7; added notes

This commit is contained in:
2026-11-12 06:35:56 -05:00
parent 3e03d82be8
commit 5be7ebde70
2 changed files with 146 additions and 59 deletions

View File

@@ -123,4 +123,89 @@ python manage.py runserver
npm install
npm run watch
To stop the server press Ctrl+C. Run deactivate to leave the virtual environment. To start fresh, delete db.sqlite3 and repeat from step 4. Don't touch db.sqlite3-bak.
To stop the server press Ctrl+C. Run deactivate to leave the virtual environment. To start fresh, delete db.sqlite3 and repeat from step 4. Don't touch db.sqlite3-bak.
step 1 response
The environment is set up and both baselines are captured: all 114 tests pass. I mapped the nine search categories and propose 27 new test methods below. The baselines turned up four existing defects, including one 500 error, and several places where access is looser than the matching page, which need your decision before I write tests. No production code or tests were changed, and the working tree is clean apart from the gitignored venv/.
Environment and baselines
Setup: the documented virtualenv venv command failed (virtualenv: command not found). I used python3 -m venv venv, which is what CircleCI does, then pip install -r requirements-dev.txt and coverage. Python is 3.12.3.
Unpinned versions: requirements.txt only sets minimums, so pip installed Django 6.1.3, DRF 3.18.3 and knox 5.1.0. CI would get the same latest versions. manage.py check reports no issues.
Existing search suite (manage.py test NearBeach.tests.tests_views.tests_search -v 2): 4 tests, all pass (8.1s, 32s wall-clock). They check status codes only, and several post search payloads to the search page rather than search_data.
Full suite (the CI command, under coverage): Ran 114 tests in 671.508s, OK. No failures, errors or skips, and no warnings in the output. That makes any later failure new.
Statement coverage Search suite alone Full suite
search/search_objects.py 93.1% (54/58) 93.1%
search_views.py 54.2% (103/190) 58.9% (112/190)
With branch coverage the figures are 89% / 50% (search suite) and 89% / 54% (full suite). To reach 80%, search_views.py needs at least 152 of its 190 statements covered. Line 108 in search_objects.py can only be reached through the 500 error below.
Contract map
Shared rules:
Every search term is split on spaces, each word must match (case-insensitive substring), and an empty search matches everything.
The search field is limited to 250 characters; longer input returns 400.
Soft-deleted records are always excluded.
Logged-out users are sent to /login with no next parameter. Exceptions: the notification page sends them to /, and a GET to a POST-only endpoint returns 405 before the login check, except for sprint data.
Category Endpoints Request Response and matching Order / limit / pages Closed filter Access
Main search/ (page), search/data/ (POST) array_of_objects (required, list), destination_page (required), search, include_closed, include_all_groups, exclude_destination + exclude_location_id For each requested type: {type: [{id,title,status}], type_number_of_pages, type_current_page}. Title match; a numeric word also matches the exact ID. Newest ID first (model default); 5 per page; page ≤1 gives page 1; pages past the end return []; current_page echoes the input Yes; rule differs by type (below) Logged in; only objects assigned to the user's groups. Superusers see everything only with include_all_groups
Customer search/customer/, …/data/ (POST) search Django serializer list [{model,pk,fields}]; matches first name, last name or organisation name Last name, first name; max 50 No Logged in
Organisation search/organisation/, …/data/ (POST) search Serializer list; matches organisation_name Name; max 25 No Logged in
Group search/group/, …/data/ (GET or POST) search Serializer list; matches group_name Name; max 25 No Page: admin permission (administration_create_user ≥3) or superuser. Data: any logged-in user
User search/user/, …/data/ (POST) search Plain list [{id,email,first_name,last_name,username}]; matches any of those four text fields; inactive users included Last name, first name; max 50 No Page: admin permission. Data: any logged-in user
Sprint search/sprint/, …/data/ (POST) Same form as main search; array_of_objects=sprint is required {sprint: [{sprint_id,sprint_name,sprint_status}], sprint_number_of_pages, sprint_current_page} Newest first; 5 per page Hides Finished sprints Logged in; only sprints on projects or requirements in the user's groups, with no superuser bypass. Logged-out GET → 302 (not 405)
Tag search/tag/ only (filtered in the browser) none Page context: tag_results, user_level Name No Tag permission ≥1 (superusers get level 4)
Notification search/notification/, …/data/ (POST) search Serializer list; matches header or message Header; max 25 No Page: superuser only (everyone else → 302 to /). Data: any logged-in user
Permission set search/permission_set/, …/data/ (POST) search Serializer list; matches permission_set_name Name; max 25 No Page: admin permission. Data: any logged-in user
Main search object types vs. the nine categories:
The form accepts 12 values for array_of_objects, but only 6 are actually searchable: kanban_board, project, request_for_change, requirement, requirement_item and task.
The status field has a different type depending on the object: RFCs return an integer, kanban boards a string, and the rest a status label.
"Closed" means something different per type: RFC statuses 5 and 6, kanban status Closed, and for the others a status whose higher-order status is Closed.
Requirement items are visible when the user can see the parent requirement.
search/scheduled_objects/ is also in search_views.py but isn't one of the nine categories.
Existing defects (confirmed, not fixed)
500 error in main search: posting a value the form accepts but search doesn't support (e.g. array_of_objects=customer) crashes with TypeError: cannot unpack non-iterable NoneType.
500 for users with no groups: the group, user, permission-set and tag pages all crash with TypeError: '>=' not supported…. The bug is in the permission decorators, not the search modules.
Looser access on data endpoints: the group, user, permission-set and notification data endpoints don't enforce their page's permission check, and group data also accepts GET.
current_page echoes the raw input: sending 0 or 99 returns 0 or 99, even though the results are page 1 or empty.
Proposed tests (27, plus one optional)
They would go in a new file under tests/tests_views/tests_search/, using the NearBeach_basic_setup.json fixture and force_login.
Main (10):
Response keys and row shape for each type; types not requested are absent.
Results limited to the user's groups (team lead sees only ID 2, including the requirement item via its parent).
include_all_groups works for superusers only (dark_admin sees [1] or [2,1]; for the team lead it's ignored).
Multiple words are combined with AND and matching is case-insensitive.
A numeric word matches the ID but still respects group access.
Closed objects are excluded per type unless include_closed is set (one subtest per type, plus RFC statuses 5 and 6).
Pagination and ordering: 7 projects split 5 + 2, newest first, page 3 empty, page 0 returns page 1.
exclude_destination only applies when the ID is also sent.
Validation and method: 400 for missing or invalid fields, 405 for GET, redirect for logged-out users.
The search page shows search_input and is_superuser, and returns 400 over 250 characters.
Customer (2): 11. Matching on names and organisation, ordering, serializer format, deleted records excluded. 12. 400 error text, 405 for GET, page context.
Organisation (2): 13. Ordering, deleted records excluded, 25-result cap. 14. 400 for invalid input, page context.
Group (3): 15. Page: admin gets 200, team lead gets 403. 16. Data matching, ordering, deleted records excluded. 17. 400 for invalid input.
User (2): 18. Page access and context fields. 19. Matching on each of the four fields, ordering, and only the five allowed keys returned (no password); 400 for invalid input.
Sprint (3): 20. Group scoping (team lead [4,2], admin [4,3,2,1]). 21. Finished sprints hidden unless include_closed; search words. 22. Pagination; 400 / 405 / 302 cases; page renders.
Tag (1): 23. Page context user_level (4 for team lead, 1 for read-only, 4 for admin); tags ordered by name with deleted ones excluded.
Notification (2): 24. Page is superuser-only; everyone else → 302 to /. 25. Data matches header or message, ordering; 400 and 405 cases.
Permission set (2): 26. Page access (admin 200, team lead 403). 27. Data matching ("read only" returns both read-only sets) and ordering; 400.
Optional: one scheduled-objects test, for coverage only.
Projected coverage from the search suite alone: about 95% or more for search_views.py and 57/58 (98%) for search_objects.py.
Decisions for you
The two 500 errors: should the tests leave them out (my recommendation), or mark them as expectedFailure? Writing tests that expect a 500 would lock the bugs in.
The looser data-endpoint access: should tests assert that non-admins can use those four data endpoints? That would lock in what may be a security gap; otherwise the tests just won't assert on it.
How to measure the 80% target: on the search suite alone (stricter, my suggestion) or on the full suite?
Logs, the exact package versions and my probe scripts are in /tmp/probe/.