Skip to content

Commit

Permalink
repr tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michplunkett committed Dec 20, 2024
1 parent e74eff2 commit 6ba9269
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion OpenOversight/app/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class Unit(BaseModel, TrackUpdates):
)

def __repr__(self):
return f"Unit: {self.description}"
return f"<Unit: {self.description}>"


class Face(BaseModel, TrackUpdates):
Expand Down Expand Up @@ -751,6 +751,9 @@ class Incident(BaseModel, TrackUpdates):
"Department", backref=db.backref("incidents", cascade_backrefs=False), lazy=True
)

def __repr__(self):
return f"<Incident ID: {self.id} : {self.report_number}>"


class User(UserMixin, BaseModel):
__tablename__ = "users"
Expand Down
7 changes: 6 additions & 1 deletion OpenOversight/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ def test_assignment_repr(mockdata):
)


def test_incident_repr(mockdata):
incident = Incident.query.first()
assert repr(incident) == f"<Incident ID: {incident.id} : {incident.report_number}>"


def test_job_repr(mockdata):
job = Job.query.first()
assert repr(job) == f"<Job ID {job.id}: {job.job_title}>"
Expand All @@ -158,7 +163,7 @@ def test_face_repr(mockdata):

def test_unit_repr(mockdata):
unit = Unit.query.first()
assert repr(unit) == f"Unit: {unit.description}"
assert repr(unit) == f"<Unit: {unit.description}>"


def test_user_repr(mockdata):
Expand Down
2 changes: 1 addition & 1 deletion OpenOversight/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_user_cannot_submit_invalid_file_extension(mockdata):

def test_unit_choices(mockdata):
unit_choices_result = [str(x) for x in unit_choices()]
assert "Unit: Bureau of Organized Crime" in unit_choices_result
assert "<Unit: Bureau of Organized Crime>" in unit_choices_result


@upload_s3_patch
Expand Down

0 comments on commit 6ba9269

Please sign in to comment.