Skip to content

Commit 9372411

Browse files
Spraynardsea-kelp
andauthored
Fix Departments pagination automatic filter application (#1078)
## Fixes issue Fixes #1077 ## Description of Changes Changes check if there are "filters" being applied to the list given in the `departments` view. If there are no filters applied then we generate a "next" link that does not automatically apply filters. ## Tests and linting - [x] This branch is up-to-date with the `develop` branch. - [x] `pytest` passes on my local development environment. - [x] `pre-commit` passes on my local development environment. --------- Co-authored-by: sea-kelp <66500457+sea-kelp@users.noreply.github.com>
1 parent f5b725b commit 9372411

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

OpenOversight/app/main/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime
55
from http import HTTPMethod, HTTPStatus
66
from traceback import format_exc
7+
from typing import Optional
78

89
from flask import (
910
Response,
@@ -856,7 +857,7 @@ def redirect_list_officer(
856857
unique_internal_identifier=None,
857858
unit=None,
858859
current_job=None,
859-
require_photo: bool = False,
860+
require_photo: Optional[bool] = None,
860861
):
861862
flash(FLASH_MSG_PERMANENT_REDIRECT)
862863
return redirect(
@@ -896,7 +897,7 @@ def list_officer(
896897
unique_internal_identifier=None,
897898
unit=None,
898899
current_job=None,
899-
require_photo: bool = False,
900+
require_photo: Optional[bool] = None,
900901
):
901902
form = BrowseForm()
902903
form.rank.query = (

OpenOversight/tests/test_functional.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,25 @@ def test_officer_browse_pagination(mockdata, browser, server_port):
114114
total = Officer.query.filter_by(department_id=AC_DEPT).count()
115115

116116
# first page of results
117-
browser.get(f"http://localhost:{server_port}/departments/{AC_DEPT}?page=1")
117+
browser.get(
118+
f"http://localhost:{server_port}/departments/{AC_DEPT}?page=1&gender=Not+Sure"
119+
)
118120
wait_for_element(browser, By.TAG_NAME, "body")
119121
page_text = browser.find_element_by_tag_name("body").text
120122
expected = f"Showing 1-{current_app.config[KEY_OFFICERS_PER_PAGE]} of {total}"
121123
assert expected in page_text
122124

125+
# check that "Next" pagination link does not automatically add require_photo parameter
126+
next_link = browser.find_elements(By.XPATH, '//li[@class="next"]/a')[
127+
0
128+
].get_attribute("href")
129+
assert "gender" in next_link
130+
assert "require_photo" not in next_link
131+
123132
# last page of results
124133
last_page_index = (total // current_app.config[KEY_OFFICERS_PER_PAGE]) + 1
125134
browser.get(
126-
f"http://localhost:{server_port}/departments/{AC_DEPT}?page={last_page_index}"
135+
f"http://localhost:{server_port}/departments/{AC_DEPT}?page={last_page_index}&gender=Not+Sure"
127136
)
128137
wait_for_element(browser, By.TAG_NAME, "body")
129138
page_text = browser.find_element_by_tag_name("body").text
@@ -135,6 +144,13 @@ def test_officer_browse_pagination(mockdata, browser, server_port):
135144
expected = f"Showing {start_of_page}-{total} of {total}"
136145
assert expected in page_text
137146

147+
# check that "Previous" pagination link does not automatically add require_photo parameter
148+
previous_link = browser.find_elements(By.XPATH, '//li[@class="previous"]/a')[
149+
0
150+
].get_attribute("href")
151+
assert "gender" in previous_link
152+
assert "require_photo" not in previous_link
153+
138154

139155
def test_find_officer_can_see_uii_question_for_depts_with_uiis(
140156
mockdata, browser, server_port

0 commit comments

Comments
 (0)