Skip to content

Commit d68dbb5

Browse files
committed
Testing issue solved
1 parent a518cd3 commit d68dbb5

File tree

2 files changed

+47
-39
lines changed

2 files changed

+47
-39
lines changed

backend/database/models/officer.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
from neomodel import (
66
StructuredNode,
7-
RelationshipTo, RelationshipFrom, Relationship,
8-
StringProperty, DateProperty,
9-
UniqueIdProperty, One
7+
RelationshipTo,
8+
RelationshipFrom,
9+
Relationship,
10+
StringProperty,
11+
DateProperty,
12+
UniqueIdProperty,
13+
One,
1014
)
1115

1216

@@ -16,20 +20,26 @@ class StateID(StructuredNode, JsonSerializable):
1620
law enforcement agencies. For example, in New York, this would be
1721
the Tax ID Number.
1822
"""
23+
1924
id_name = StringProperty() # e.g. "Tax ID Number"
2025
state = StringProperty(choices=State.choices()) # e.g. "NY"
2126
value = StringProperty() # e.g. "958938"
22-
officer = RelationshipFrom('Officer', "HAS_STATE_ID", cardinality=One)
27+
officer = RelationshipFrom("Officer", "HAS_STATE_ID", cardinality=One)
2328

2429
def __repr__(self):
2530
return f"<StateID: Officer {self.officer_id}, {self.state}>"
2631

2732

2833
class Officer(StructuredNode, JsonSerializable):
2934
__property_order__ = [
30-
"uid", "first_name", "middle_name",
31-
"last_name", "suffix", "ethnicity",
32-
"gender", "date_of_birth"
35+
"uid",
36+
"first_name",
37+
"middle_name",
38+
"last_name",
39+
"suffix",
40+
"ethnicity",
41+
"gender",
42+
"date_of_birth",
3343
]
3444
__hidden_properties__ = ["citations"]
3545

@@ -43,19 +53,23 @@ class Officer(StructuredNode, JsonSerializable):
4353
date_of_birth = DateProperty()
4454

4555
# Relationships
46-
state_ids = RelationshipTo('StateID', "HAS_STATE_ID")
56+
state_ids = RelationshipTo("StateID", "HAS_STATE_ID")
4757
units = Relationship(
48-
'backend.database.models.agency.Unit', "MEMBER_OF_UNIT")
58+
"backend.database.models.agency.Unit", "MEMBER_OF_UNIT"
59+
)
4960
litigation = Relationship(
50-
'backend.database.models.litigation.Litigation', "NAMED_IN")
61+
"backend.database.models.litigation.Litigation", "NAMED_IN"
62+
)
5163
allegations = Relationship(
52-
'backend.database.models.complaint.Allegation', "ACCUSED_OF")
64+
"backend.database.models.complaint.Allegation", "ACCUSED_OF"
65+
)
5366
investigations = Relationship(
54-
'backend.database.models.complaint.Investigation', "LEAD_BY")
55-
commands = Relationship(
56-
'backend.database.models.agency.Unit', "COMMANDS")
67+
"backend.database.models.complaint.Investigation", "LEAD_BY"
68+
)
69+
commands = Relationship("backend.database.models.agency.Unit", "COMMANDS")
5770
citations = RelationshipTo(
58-
'backend.database.models.source.Source', "UPDATED_BY", model=Citation)
71+
"backend.database.models.source.Source", "UPDATED_BY", model=Citation
72+
)
5973

6074
def __repr__(self):
61-
return f"<Officer {self.element_id}>"
75+
return f"<Officer {self.uid}>"

backend/tests/test_officers.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
"first_name": "John",
1111
"last_name": "Doe",
1212
"ethnicity": "White",
13-
"gender": "Male"
13+
"gender": "Male",
1414
},
1515
"hazel": {
1616
"first_name": "Hazel",
1717
"last_name": "Nutt",
1818
"ethnicity": "White",
19-
"gender": "Female"
19+
"gender": "Female",
2020
},
2121
"frank": {
2222
"first_name": "Frank",
2323
"last_name": "Furter",
2424
"ethnicity": "Black/African American",
25-
"gender": "Male"
26-
}
25+
"gender": "Male",
26+
},
2727
}
2828

2929
mock_agencies = {
@@ -33,42 +33,40 @@
3333
"hq_address": "3510 S Michigan Ave",
3434
"hq_city": "Chicago",
3535
"hq_zip": "60653",
36-
"jurisdiction": "MUNICIPAL"
36+
"jurisdiction": "MUNICIPAL",
3737
},
3838
"nypd": {
3939
"name": "New York Police Department",
4040
"website_url": "https://www1.nyc.gov/site/nypd/index.page",
4141
"hq_address": "1 Police Plaza",
4242
"hq_city": "New York",
4343
"hq_zip": "10038",
44-
"jurisdiction": "MUNICIPAL"
45-
}
44+
"jurisdiction": "MUNICIPAL",
45+
},
4646
}
4747

4848
mock_employment = {
4949
"john": {
5050
"agency": "Chicago Police Department",
5151
"earliest_employment": "2015-03-14 00:00:00",
5252
"badge_number": "1234",
53-
"currently_employed": True
53+
"currently_employed": True,
5454
},
5555
"hazel": {
5656
"agency": "Chicago Police Department",
5757
"earliest_employment": "2018-08-12 00:00:00",
5858
"badge_number": "5678",
59-
"currently_employed": True
59+
"currently_employed": True,
6060
},
6161
"frank": {
6262
"agency": "New York Police Department",
6363
"earliest_employment": "2019-05-03 00:00:00",
6464
"badge_number": "1234",
65-
"currently_employed": True
66-
}
65+
"currently_employed": True,
66+
},
6767
}
6868

69-
mock_sources = {
70-
"cpdp": {"name": "Citizens Police Data Project"}
71-
}
69+
mock_sources = {"cpdp": {"name": "Citizens Police Data Project"}}
7270

7371

7472
@pytest.fixture
@@ -82,17 +80,15 @@ def example_officers(db_session):
8280

8381

8482
def test_create_officer(
85-
db_session,
86-
client,
87-
contributor_access_token,
88-
example_agency):
83+
db_session, client, contributor_access_token, example_agency
84+
):
8985

9086
# Test that we can create an officer without an agency association
9187
request = {
9288
"first_name": "Max",
9389
"last_name": "Payne",
9490
"ethnicity": "White",
95-
"gender": "Male"
91+
"gender": "Male",
9692
}
9793
res = client.post(
9894
"/api/v1/officers/",
@@ -104,9 +100,7 @@ def test_create_officer(
104100
assert res.status_code == 200
105101
response = res.json
106102

107-
officer_obj = (
108-
Officer.nodes.get(uid=response["uid"])
109-
)
103+
officer_obj = Officer.nodes.get(uid=response["uid"])
110104
assert officer_obj.first_name == request["first_name"]
111105
assert officer_obj.last_name == request["last_name"]
112106
assert officer_obj.ethnicity == request["ethnicity"]
@@ -203,7 +197,7 @@ def test_officer_pagination(client, db_session, access_token, example_officers):
203197
# Create Officers in the database
204198
officers = Officer.nodes.all()
205199
per_page = 1
206-
expected_total_pages = math.ceil(len(officers)//per_page)
200+
expected_total_pages = math.ceil(len(officers) // per_page)
207201

208202
for page in range(1, expected_total_pages + 1):
209203
res = client.get(

0 commit comments

Comments
 (0)