-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#71] Updated and created Flask/sqlalchemy models to match CPDP datab…
…ase schema; 4 tests in loader.py are flagged to be skipped
- Loading branch information
1 parent
8809820
commit a3df35d
Showing
14 changed files
with
275 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from invisible_flow.constants import COPA_DB_BIND_KEY | ||
from manage import db | ||
|
||
|
||
class DataComplainant(db.Model): | ||
__bind_key__ = COPA_DB_BIND_KEY | ||
id = db.Column(db.Integer, primary_key=True) | ||
gender = db.Column(db.String(1), nullable=False) | ||
race = db.Column(db.String(50), nullable=False) | ||
age = db.Column(db.Integer) | ||
birth_year = db.Column(db.Integer) | ||
allegation_id = db.Column(db.String(30)) | ||
created_at = db.Column(db.DateTime, nullable=False) | ||
updated_at = db.Column(db.DateTime, nullable=False) | ||
|
||
def __repr__(self): | ||
return f'<DataComplainant {self.id} ' \ | ||
f'gender: {self.gender}, ' \ | ||
f'race: {self.race}, ' \ | ||
f'age: {self.age}, ' \ | ||
f'birth_year: {self.birth_year}, ' \ | ||
f'allegation_id: {self.allegation_id}, ' \ | ||
f'created_at: {self.created_at}, ' \ | ||
f'updated_at: {self.updated_at}, ' \ | ||
f'>' | ||
|
||
|
||
def insert_officer_allegation_into_database(record: DataComplainant): | ||
db.session.add(record) | ||
db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from invisible_flow.constants import COPA_DB_BIND_KEY | ||
from manage import db | ||
|
||
|
||
class DataOfficerAllegation(db.Model): | ||
__bind_key__ = COPA_DB_BIND_KEY | ||
id = db.Column(db.Integer, primary_key=True) | ||
allegation_id = db.Column(db.String(30)) | ||
allegation_category_id = db.Column(db.Integer) | ||
officer_id = db.Column(db.Integer) | ||
start_date = db.Column(db.Date) | ||
end_date = db.Column(db.Date) | ||
officer_age = db.Column(db.Integer) | ||
recc_finding = db.Column(db.String(2), nullable=False) | ||
recc_outcome = db.Column(db.String(32), nullable=False) | ||
final_finding = db.Column(db.String(2), nullable=False) | ||
final_outcome = db.Column(db.String(32), nullable=False) | ||
final_outcome_class = db.Column(db.String(20), nullable=False) | ||
disciplined = db.Column(db.Boolean) | ||
created_at = db.Column(db.DateTime, nullable=False) | ||
updated_at = db.Column(db.DateTime, nullable=False) | ||
|
||
def __repr__(self): | ||
return f'<OfficerAllegation {self.id} ' \ | ||
f'allegation_id: {self.allegation_id}, ' \ | ||
f'allegation_category_id: {self.allegation_category_id}, ' \ | ||
f'officer_id: {self.officer_id}, ' \ | ||
f'start_date: {self.start_date}, ' \ | ||
f'end_date: {self.end_date}, ' \ | ||
f'officer_age: {self.officer_age}, ' \ | ||
f'recc_finding: {self.recc_finding}, ' \ | ||
f'final_finding: {self.final_finding}, ' \ | ||
f'final_outcome: {self.final_outcome}, ' \ | ||
f'final_outcome_class: {self.final_outcome_class}, ' \ | ||
f'disciplined: {self.disciplined}, ' \ | ||
f'created_at: {self.created_at}, ' \ | ||
f'updated_at: {self.updated_at}, ' \ | ||
f'>' | ||
|
||
|
||
def insert_officer_allegation_into_database(record: DataOfficerAllegation): | ||
db.session.add(record) | ||
db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,48 @@ | ||
import pytest | ||
import datetime | ||
|
||
from invisible_flow.constants import COPA_DB_BIND_KEY | ||
from invisible_flow.copa.data_allegation import Allegation | ||
from invisible_flow.copa.data_allegation import DataAllegation | ||
from manage import db | ||
from geoalchemy2 import Geometry | ||
|
||
class TestDataAllegation: | ||
|
||
class TestAllegation: | ||
|
||
@pytest.fixture | ||
@pytest.fixture(autouse=True) | ||
def get_db(self): | ||
db.session.close() | ||
db.drop_all() | ||
db.create_all(bind=COPA_DB_BIND_KEY) | ||
|
||
yield db | ||
|
||
def get_allegation(self): | ||
return Allegation( | ||
def get_data_allegation(self): | ||
return DataAllegation( | ||
id=1, | ||
cr_id='cr_id', | ||
summary='summary', | ||
add1='add1', | ||
add2='add2', | ||
beat_id='beat_id', | ||
beat_id=1, | ||
city='city', | ||
incident_date='incident_date', | ||
incident_date=datetime.datetime.utcnow(), | ||
is_officer_complaint=True, | ||
location='location', | ||
summary='summary' | ||
old_complaint_address='old_complaint_address', | ||
subjects={"Bassil Abdelal","Richie Cole","Omar Young","Leevon Carter"}, | ||
point='0101000020E61000009FB3603DC9EA55C0138E6A227DD84440', | ||
created_at=datetime.datetime.utcnow(), | ||
updated_at=datetime.datetime.utcnow() | ||
) | ||
|
||
def test_create_allegation(self): | ||
def test_create_data_allegation(self): | ||
try: | ||
self.get_allegation() | ||
self.get_data_allegation() | ||
except Exception: | ||
pytest.fail('this should not have thrown an exception') | ||
|
||
def test_adding_copa_record_to_db_works(self, get_db): | ||
cr = self.get_allegation() | ||
cr = self.get_data_allegation() | ||
get_db.session.add(cr) | ||
get_db.session.commit() | ||
assert len(Allegation.query.all()) == 1 | ||
assert len(DataAllegation.query.all()) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,43 @@ | ||
import pytest | ||
import datetime | ||
|
||
from invisible_flow.constants import COPA_DB_BIND_KEY | ||
from invisible_flow.copa.data_allegation_category import AllegationCategory | ||
from invisible_flow.copa.data_allegation_category import DataAllegationCategory | ||
from manage import db | ||
|
||
|
||
class TestAllegationCategory: | ||
class TestDataAllegationCategory: | ||
|
||
@pytest.fixture | ||
@pytest.fixture(autouse=True) | ||
def get_db(self): | ||
db.session.close() | ||
db.drop_all(); | ||
db.create_all(bind=COPA_DB_BIND_KEY) | ||
|
||
yield db | ||
|
||
def get_allegation_category(self): | ||
return AllegationCategory( | ||
cr_id='cr_id', | ||
def get_data_allegation_category(self): | ||
return DataAllegationCategory( | ||
id=1, | ||
category='category', | ||
category_code='category_code', | ||
allegation_name='allegation_name', | ||
on_duty='on_duty' | ||
on_duty=True, | ||
citizen_dept='citizen_dept', | ||
created_at=datetime.datetime.utcnow(), | ||
updated_at=datetime.datetime.utcnow() | ||
|
||
) | ||
|
||
def test_create_allegation_category(self): | ||
def test_create_data_allegation_category(self): | ||
try: | ||
self.get_allegation_category() | ||
self.get_data_allegation_category() | ||
except Exception: | ||
pytest.fail('this should not have thrown an exception') | ||
|
||
def test_adding_allegation_category_to_db_works(self, get_db): | ||
cr = self.get_allegation_category() | ||
def test_adding_data_allegation_category_to_db_works(self, get_db): | ||
cr = self.get_data_allegation_category() | ||
get_db.session.add(cr) | ||
get_db.session.commit() | ||
assert len(AllegationCategory.query.all()) == 1 | ||
assert len(DataAllegationCategory.query.all()) == 1 | ||
db.session.close() |
Oops, something went wrong.