-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add invalid ID tests for main.views
#1124
Changes from 4 commits
a39a823
0b054ec
ebb5155
6762875
0084af3
82c2223
2306f30
4010e67
26ba9f1
5294b31
f4b5cd6
6b1cce4
1e482ef
65a61a5
4505618
f73d55c
2544c81
da722e7
452f6c5
fabf793
e199cb5
5451777
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,9 +263,14 @@ def redirect_sort_images(department_id: int): | |
) | ||
@login_required | ||
def sort_images(department_id: int): | ||
try: | ||
department = Department.query.filter_by(id=department_id).one() | ||
except NoResultFound: | ||
abort(HTTPStatus.NOT_FOUND) | ||
|
||
# Select a random unsorted image from the database | ||
image_query = Image.query.filter_by(contains_cops=None).filter_by( | ||
department_id=department_id | ||
department_id=department.id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would either not change this line, or also update the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll update line 282, good 👁️! |
||
) | ||
image = get_random_image(image_query) | ||
|
||
|
@@ -320,6 +325,7 @@ def officer_profile(officer_id: int): | |
exception_type, value, full_traceback = sys.exc_info() | ||
error_str = " ".join([str(exception_type), str(value), format_exc()]) | ||
current_app.logger.error(f"Error finding officer: {error_str}") | ||
abort(HTTPStatus.NOT_FOUND) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little unsure of how to test this. Any advice would be appreciated, @sea-kelp @abandoned-prototype. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you're saying - it doesn't seem like this code is reachable since (as far as I can tell) the only other exception that could be thrown in the try block is MultipleResultsFound, but officer id is configured as a primary key. I wonder if we should just remove it. If you do want to test it, you could patch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that we are searching by the primary key, I am comfortable removing this exception section. Thanks for the 👁️ , @sea-kelp! |
||
form.job_title.query = ( | ||
Job.query.filter_by(department_id=officer.department_id) | ||
.order_by(Job.order.asc()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though it is equivalent logic, but I feel more comfortable using the
id
field of theDepartment
object to query theImage
s downstream.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming this will lead to one additional query so not exactly equivalent, but makes sense to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, one more additional query. I think there's more value to the sureness around it than the minor performance hit.