Skip to content

Commit 734f59d

Browse files
committed
Fix tests
1 parent fadfac8 commit 734f59d

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

backend/routes/units.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
add_pagination_wrapper, ordered_jsonify)
55
from backend.database.models.user import UserRole
66
from backend.database.models.agency import Unit
7-
from backend.routes.search import fetch_details, build_unit_result, build_officer_result
7+
from backend.routes.search import (
8+
fetch_details, build_unit_result, build_officer_result)
89
from flask import Blueprint, abort, request, jsonify
910
from flask_jwt_extended.view_decorators import jwt_required
1011
from backend.dto.unit import UnitQueryParams, GetUnitParams
@@ -23,7 +24,8 @@
2324

2425
LOCATION_CYPHER = """
2526
CALL (u) {
26-
MATCH (u)-[]-(:Agency)-[]-(city:CityNode)-[]-(:CountyNode)-[]-(state:StateNode)
27+
MATCH (u)-[]-(:Agency)-[]-(city:CityNode)-[]-(:CountyNode)
28+
-[]-(state:StateNode)
2729
RETURN {
2830
coords: city.coordinates,
2931
city: city.name,
@@ -58,11 +60,14 @@
5860
CALL (u) {
5961
OPTIONAL MATCH (u)<-[]-(:Employment)-[]->(:Officer)
6062
-[:ACCUSED_OF]->(a:Allegation)-[:ALLEGED]-(c:Complaint)
61-
WITH count(DISTINCT c) AS total_complaints, count(DISTINCT a) AS total_allegations
63+
WITH
64+
count(DISTINCT c) AS total_complaints,
65+
count(DISTINCT a) AS total_allegations
6266
RETURN total_complaints, total_allegations
6367
}
6468
"""
6569

70+
6671
@bp.route("", methods=["GET"])
6772
@jwt_required()
6873
@min_role_required(UserRole.PUBLIC)
@@ -177,7 +182,9 @@ def get_unit(uid: str):
177182
item.model_dump() for item in officers if item
178183
]
179184
for item in item_dump:
180-
item["last_updated"] = item["last_updated"].isoformat() if item.get("last_updated", None) else None
185+
item["last_updated"] = item[
186+
"last_updated"].isoformat() if item.get(
187+
"last_updated", None) else None
181188
unit_data["most_reported_officers"] = item_dump
182189
idx += 1
183190
if "total_officers" in params.include:
@@ -195,4 +202,4 @@ def get_unit(uid: str):
195202
"city": loc["city"],
196203
"state": loc["state"]
197204
} if loc and loc.get("coords", None) else None
198-
return ordered_jsonify(unit_data), 200
205+
return ordered_jsonify(unit_data), 200

backend/tests/test_units.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_get_all_units(client, example_units, access_token):
7575

7676
# Test that we can get all units
7777
res = client.get(
78-
"/api/v1/units/",
78+
"/api/v1/units",
7979
headers={"Authorization": "Bearer {0}".format(access_token)}
8080
)
8181
assert res.status_code == 200
@@ -87,7 +87,7 @@ def test_get_search_result(client, example_unit, access_token):
8787
name__icontains='Precinct 1'
8888
).__len__()
8989
res = client.get(
90-
"/api/v1/units/?name=Precinct 1&searchResult=true",
90+
"/api/v1/units?name=Precinct 1&searchResult=true",
9191
headers={"Authorization": "Bearer {0}".format(access_token)},
9292
)
9393
assert res.status_code == 200
@@ -96,7 +96,7 @@ def test_get_search_result(client, example_unit, access_token):
9696

9797
def test_bad_query_param(client, access_token):
9898
res = client.get(
99-
"/api/v1/units/?abc=123",
99+
"/api/v1/units?abc=123",
100100
headers={"Authorization": "Bearer {0}".format(access_token)},
101101
)
102102

@@ -110,7 +110,7 @@ def test_unit_pagination(client, example_units, access_token):
110110
expected_total_pages = math.ceil(total_units//per_page)
111111
for page in range(1, expected_total_pages + 1):
112112
res = client.get(
113-
f"/api/v1/units/?per_page={per_page}&page={page}",
113+
f"/api/v1/units?per_page={per_page}&page={page}",
114114
headers={"Authorization": "Bearer {0}".format(access_token)},
115115
)
116116

@@ -123,7 +123,7 @@ def test_unit_pagination(client, example_units, access_token):
123123

124124
res = client.get(
125125
(
126-
f"/api/v1/units/?per_page={per_page}"
126+
f"/api/v1/units?per_page={per_page}"
127127
f"&page={expected_total_pages + 1}"
128128
),
129129
headers={"Authorization": "Bearer {0}".format(access_token)},

0 commit comments

Comments
 (0)