diff --git a/OpenOversight/app/main/views.py b/OpenOversight/app/main/views.py index 29ae06537..6c5fb10d8 100644 --- a/OpenOversight/app/main/views.py +++ b/OpenOversight/app/main/views.py @@ -1,4 +1,3 @@ -import os import re import sys from datetime import datetime @@ -124,9 +123,6 @@ ) -# Ensure the file is read/write by the creator only -SAVED_UMASK = os.umask(0o077) - sitemap_endpoints = [] diff --git a/OpenOversight/app/models/database.py b/OpenOversight/app/models/database.py index 6ffd345a5..2924ac664 100644 --- a/OpenOversight/app/models/database.py +++ b/OpenOversight/app/models/database.py @@ -136,7 +136,7 @@ class Department(BaseModel, TrackUpdates): __table_args__ = (UniqueConstraint("name", "state", name="departments_name_state"),) def __repr__(self): - return f"" + return f"" def to_custom_dict(self): return { @@ -198,7 +198,7 @@ class Job(BaseModel, TrackUpdates): ) def __repr__(self): - return f"" + return f"" def __str__(self): return self.job_title @@ -212,6 +212,9 @@ class Note(BaseModel, TrackUpdates): officer_id = db.Column(db.Integer, db.ForeignKey("officers.id", ondelete="CASCADE")) officer = db.relationship("Officer", back_populates="notes") + def __repr__(self): + return f"" + class Description(BaseModel, TrackUpdates): __tablename__ = "descriptions" @@ -221,6 +224,9 @@ class Description(BaseModel, TrackUpdates): text_contents = db.Column(db.Text()) officer_id = db.Column(db.Integer, db.ForeignKey("officers.id", ondelete="CASCADE")) + def __repr__(self): + return f"" + class Officer(BaseModel, TrackUpdates): __tablename__ = "officers" @@ -279,6 +285,14 @@ class Officer(BaseModel, TrackUpdates): CheckConstraint("gender in ('M', 'F', 'Other')", name="gender_options"), ) + def __repr__(self): + if self.unique_internal_identifier: + return ( + f"" + ) + return f"" + def full_name(self): if self.middle_initial: middle_initial = ( @@ -339,14 +353,6 @@ def currently_on_force(self): return "Yes" if most_recent.resign_date is None else "No" return "Uncertain" - def __repr__(self): - if self.unique_internal_identifier: - return ( - f"" - ) - return f"" - class Salary(BaseModel, TrackUpdates): __tablename__ = "salaries" @@ -365,7 +371,7 @@ class Salary(BaseModel, TrackUpdates): is_fiscal_year = db.Column(db.Boolean, index=False, unique=False, nullable=False) def __repr__(self): - return f"" @property def total_pay(self) -> float: @@ -406,7 +412,7 @@ class Assignment(BaseModel, TrackUpdates): resign_date = db.Column(db.Date, index=True, unique=False, nullable=True) def __repr__(self): - return f"" + return f"" @property def start_date_or_min(self): @@ -433,7 +439,7 @@ class Unit(BaseModel, TrackUpdates): ) def __repr__(self): - return f"Unit: {self.description}" + return f"" class Face(BaseModel, TrackUpdates): @@ -485,7 +491,7 @@ class Face(BaseModel, TrackUpdates): __table_args__ = (UniqueConstraint("officer_id", "img_id", name="unique_faces"),) def __repr__(self): - return f"" + return f"" class Image(BaseModel, TrackUpdates): @@ -512,7 +518,7 @@ class Image(BaseModel, TrackUpdates): ) def __repr__(self): - return f"" + return f"" incident_links = db.Table( @@ -644,6 +650,9 @@ class LicensePlate(BaseModel, TrackUpdates): def validate_state(self, key, state): return state_validator(state) + def __repr__(self): + return f"" + class Link(BaseModel, TrackUpdates): __tablename__ = "links" @@ -660,6 +669,9 @@ class Link(BaseModel, TrackUpdates): def validate_url(self, key, url): return url_validator(url) + def __repr__(self): + return f"" + class Incident(BaseModel, TrackUpdates): __tablename__ = "incidents" @@ -704,6 +716,9 @@ class Incident(BaseModel, TrackUpdates): "Department", backref=db.backref("incidents", cascade_backrefs=False), lazy=True ) + def __repr__(self): + return f"" + class User(UserMixin, BaseModel): __tablename__ = "users" diff --git a/OpenOversight/app/utils/constants.py b/OpenOversight/app/utils/constants.py index 91e2e6fb9..61c2aaa74 100644 --- a/OpenOversight/app/utils/constants.py +++ b/OpenOversight/app/utils/constants.py @@ -1,6 +1,3 @@ -import os - - # Cache Key Constants KEY_DEPT_ALL_ASSIGNMENTS = "all_department_assignments" KEY_DEPT_ALL_INCIDENTS = "all_department_incidents" @@ -44,7 +41,6 @@ ENCODING_UTF_8 = "utf-8" FILE_TYPE_HTML = "html" FILE_TYPE_PLAIN = "plain" -SAVED_UMASK = os.umask(0o077) # Ensure the file is read/write by the creator only # File Name Constants SERVICE_ACCOUNT_FILE = "service_account_key.json" diff --git a/OpenOversight/tests/test_models.py b/OpenOversight/tests/test_models.py index 8919ba4c1..4f49e35cf 100644 --- a/OpenOversight/tests/test_models.py +++ b/OpenOversight/tests/test_models.py @@ -10,6 +10,7 @@ from OpenOversight.app.models.database import ( Assignment, Department, + Description, Face, Image, Incident, @@ -17,6 +18,7 @@ LicensePlate, Link, Location, + Note, Officer, Salary, Unit, @@ -30,7 +32,7 @@ def test_department_repr(mockdata): department = Department.query.first() assert ( repr(department) - == f"" + == f"" ) @@ -93,7 +95,7 @@ def test_officer_repr(session): ).first() assert ( - repr(officer_uii) == f"" ) @@ -107,7 +109,7 @@ def test_officer_repr(session): ).first() assert ( - repr(officer_no_uii) == f"" ) @@ -118,7 +120,7 @@ def test_officer_repr(session): assert ( repr(officer_no_mi) - == f"" ) @@ -137,28 +139,33 @@ def test_assignment_repr(mockdata): assignment = Assignment.query.first() assert ( repr(assignment) - == f"" + == f"" ) +def test_incident_repr(mockdata): + incident = Incident.query.first() + assert repr(incident) == f"" + + def test_job_repr(mockdata): job = Job.query.first() - assert repr(job) == f"" + assert repr(job) == f"" def test_image_repr(mockdata): image = Image.query.first() - assert repr(image) == f"" + assert repr(image) == f"" def test_face_repr(mockdata): face = Face.query.first() - assert repr(face) == f"" + assert repr(face) == f"" def test_unit_repr(mockdata): unit = Unit.query.first() - assert repr(unit) == f"Unit: {unit.description}" + assert repr(unit) == f"" def test_user_repr(mockdata): @@ -168,7 +175,33 @@ def test_user_repr(mockdata): def test_salary_repr(mockdata): salary = Salary.query.first() - assert repr(salary) == f"" + + +def test_link_repr(mockdata): + link = Link.query.first() + assert repr(link) == f"" + + +def test_note_repr(mockdata): + note = Note.query.first() + assert repr(note) == f"" + + +def test_description_repr(mockdata): + description = Description.query.first() + assert ( + repr(description) + == f"" + ) + + +def test_license_plate_repr(mockdata): + license_plate = LicensePlate.query.first() + assert ( + repr(license_plate) + == f"" + ) def test_password_not_printed(mockdata): diff --git a/OpenOversight/tests/test_utils.py b/OpenOversight/tests/test_utils.py index 99bf113f0..ee3104082 100644 --- a/OpenOversight/tests/test_utils.py +++ b/OpenOversight/tests/test_utils.py @@ -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 "" in unit_choices_result @upload_s3_patch