def test_coaccused_count(self): allegation_1 = AllegationFactory() allegation_2 = AllegationFactory() OfficerAllegationFactory.create_batch(6, allegation=allegation_1) allegation_cache_manager.cache_data() allegation_1.refresh_from_db() allegation_2.refresh_from_db() expect(allegation_1.coaccused_count).to.eq(6) expect(allegation_2.coaccused_count).to.eq(0)
def test_first_end_date(self): allegation = AllegationFactory() first_end_date = date(2003, 3, 20) OfficerAllegationFactory(allegation=allegation, end_date=None) OfficerAllegationFactory(allegation=allegation, end_date=first_end_date) allegation_cache_manager.cache_data() allegation.refresh_from_db() expect(allegation.first_end_date).to.eq(first_end_date)
def test_search_investigator_cr_results(self): allegation_1 = AllegationFactory(crid='123456', incident_date=datetime( 2002, 2, 3, tzinfo=pytz.utc)) allegation_2 = AllegationFactory(crid='654321', incident_date=datetime( 2005, 2, 3, tzinfo=pytz.utc)) officer = OfficerFactory(id=123, first_name='Edward', last_name='May') investigator_1 = InvestigatorFactory(first_name='Jerome', last_name='Finnigan') investigator_2 = InvestigatorFactory(officer=officer) InvestigatorAllegationFactory(investigator=investigator_1, allegation=allegation_1) InvestigatorAllegationFactory(investigator=investigator_2, allegation=allegation_1) InvestigatorAllegationFactory(investigator=investigator_1, allegation=allegation_2) OfficerAllegationFactory( allegation=allegation_1, allegation_category__category='Illegal Search') OfficerAllegationFactory(allegation=allegation_2, allegation_category__category='') allegation_cache_manager.cache_data() self.rebuild_index() self.refresh_index() url = reverse('api-v2:search-mobile-list') response = self.client.get(url, { 'term': 'Jerome', }) results = response.data['INVESTIGATOR > CR'] expect(results).to.have.length(2) expected_results = { '123456': { 'id': '123456', 'crid': '123456', 'category': 'Illegal Search', 'incident_date': '2002-02-03' }, '654321': { 'id': '654321', 'crid': '654321', 'category': 'Unknown', 'incident_date': '2005-02-03' } } for cr_data in results: expect(cr_data).to.eq(expected_results[cr_data['id']])
def test_most_common_category(self): allegation = AllegationFactory() category1, category2 = AllegationCategoryFactory.create_batch(2) OfficerAllegationFactory(allegation=allegation, allegation_category=category2) OfficerAllegationFactory.create_batch(2, allegation=allegation, allegation_category=category1) OfficerAllegationFactory.create_batch(3, allegation=allegation, allegation_category=None) allegation_cache_manager.cache_data() allegation.refresh_from_db() expect(allegation.most_common_category).to.eq(category1)
def test_request_complaint_summary(self): allegation = AllegationFactory(crid='11', incident_date=datetime(2002, 2, 28, tzinfo=pytz.utc), summary='Summary') category = AllegationCategoryFactory(category='Use of Force') OfficerAllegationFactory( allegation=allegation, officer=OfficerFactory(appointed_date=date(2001, 1, 1)), start_date=date(2003, 2, 28), end_date=date(2004, 4, 28), allegation_category=category) OfficerAllegationFactory( allegation=allegation, officer=OfficerFactory(appointed_date=date(2001, 1, 1)), start_date=date(2003, 2, 28), end_date=date(2004, 4, 28), allegation_category=None) officer_cache_manager.build_cached_yearly_percentiles() officer_cache_manager.build_cached_columns() allegation_cache_manager.cache_data() response = self.client.get(reverse('api-v2:cr-complaint-summaries')) expect(response.status_code).to.eq(status.HTTP_200_OK) expect(response.data).to.eq([{ 'crid': '11', 'category_names': ['Unknown', 'Use of Force'], 'incident_date': '2002-02-28', 'summary': 'Summary' }])
def test_top_officers_by_allegation(self): OfficerFactory( id=1, first_name='Daryl', last_name='Mack', trr_percentile=12.0000, civilian_allegation_percentile=98.4344, internal_allegation_percentile=99.7840, complaint_percentile=99.3450, race='White', gender='M', birth_year=1975, rank='Police Officer' ) OfficerFactory( id=2, first_name='Ronald', last_name='Watts', trr_percentile=0.0000, civilian_allegation_percentile=98.4344, internal_allegation_percentile=99.7840, complaint_percentile=99.5000, race='White', gender='M', birth_year=1975, rank='Detective' ) OfficerFactory( id=3, first_name='Officer', last_name='low percentile', trr_percentile=0.0000, civilian_allegation_percentile=0.0000, internal_allegation_percentile=0.0000, complaint_percentile=96.3450, race='White', gender='M', birth_year=1975, rank='' ) OfficerFactory( id=4, first_name='Officer', last_name='no visual token', trr_percentile=0.0000, internal_allegation_percentile=0.0000, complaint_percentile=99.8800, race='White', gender='M', birth_year=1975, rank='Police Officer' ) OfficerFactory( id=5, first_name='Officer', last_name='filter out', trr_percentile=0.0000, civilian_allegation_percentile=0.0000, internal_allegation_percentile=0.0000, complaint_percentile=99.2000, race='White', gender='M', birth_year=1975, rank='Detective' ) OfficerFactory( id=6, first_name='Officer', last_name='no percentiles', complaint_percentile=99.8000, race='White', gender='M', birth_year=1975, rank='Police Officer' ) officer_cache_manager.build_cached_columns() allegation_cache_manager.cache_data() response = self.client.get(reverse('api-v2:officers-top-by-allegation'), {'limit': 2}) expect(response.status_code).to.eq(status.HTTP_200_OK) expect(response.data).to.have.length(2) expect(response.data).to.eq([{ 'id': 2, 'full_name': 'Ronald Watts', 'complaint_count': 0, 'sustained_count': 0, 'birth_year': 1975, 'race': 'White', 'gender': 'Male', 'rank': 'Detective', 'percentile_allegation': '99.5000', 'percentile_allegation_civilian': '98.4344', 'percentile_allegation_internal': '99.7840', 'percentile_trr': '0.0000', }, { 'id': 1, 'full_name': 'Daryl Mack', 'complaint_count': 0, 'sustained_count': 0, 'birth_year': 1975, 'race': 'White', 'gender': 'Male', 'rank': 'Police Officer', 'percentile_trr': '12.0000', 'percentile_allegation': '99.3450', 'percentile_allegation_civilian': '98.4344', 'percentile_allegation_internal': '99.7840', }])
def test_summary(self): officer = OfficerFactory( tags=[], first_name='Kevin', last_name='Kerl', id=123, race='White', gender='M', appointed_date=date(2017, 2, 27), rank='PO', resignation_date=date(2017, 12, 27), active=ACTIVE_YES_CHOICE, birth_year=1910, complaint_percentile=32.5, sustained_count=1, allegation_count=1, discipline_count=1, trr_count=1, civilian_compliment_count=1, honorable_mention_count=1, major_award_count=1, last_unit_id=1, current_badge='123456', current_salary=90000, has_unique_name=True ) allegation = AllegationFactory() allegation_category = AllegationCategoryFactory(category='Use of Force') OfficerHistoryFactory(officer=officer, unit=PoliceUnitFactory(id=1, unit_name='CAND', description='')) ComplainantFactory(allegation=allegation, race='White', age=18, gender='F') OfficerBadgeNumberFactory(officer=officer, star='123456', current=True) OfficerAllegationFactory( officer=officer, allegation=allegation, allegation_category=allegation_category, final_finding='SU', start_date=date(2000, 1, 1), disciplined=True ) AwardFactory(officer=officer, award_type='Complimentary Letter') AwardFactory(officer=officer, award_type='Honored Police Star') AwardFactory(officer=officer, award_type='Honorable Mention') SalaryFactory(officer=officer, salary=50000, year=2015) SalaryFactory(officer=officer, salary=90000, year=2017) TRRFactory(officer=officer) officer_cache_manager.build_cached_columns() allegation_cache_manager.cache_data() response = self.client.get(reverse('api-v2:officers-summary', kwargs={'pk': 123})) expect(response.status_code).to.eq(status.HTTP_200_OK) expected_data = { 'id': 123, 'unit': { 'id': 1, 'unit_name': 'CAND', 'description': '', 'long_unit_name': 'Unit CAND', }, 'date_of_appt': '2017-02-27', 'date_of_resignation': '2017-12-27', 'active': 'Active', 'rank': 'PO', 'full_name': 'Kevin Kerl', 'race': 'White', 'badge': '123456', 'historic_units': [{ 'id': 1, 'unit_name': 'CAND', 'description': '', 'long_unit_name': 'Unit CAND' }], 'gender': 'Male', 'birth_year': 1910, 'sustained_count': 1, 'civilian_compliment_count': 1, 'allegation_count': 1, 'discipline_count': 1, 'honorable_mention_count': 1, 'to': '/officer/123/kevin-kerl/', 'url': 'http://cpdb.lvh.me/officer/kevin-kerl/123', 'current_salary': 90000, 'trr_count': 1, 'major_award_count': 1, 'unsustained_count': 0, 'percentile_allegation': '32.5000', 'coaccusals': [], 'percentiles': [], 'tags': [], 'historic_badges': [], 'has_unique_name': True } expect(response.data).to.eq(expected_data)
def test_cr_new_documents(self): allegation_1 = AllegationFactory(crid='123', incident_date=datetime( 2001, 2, 28, tzinfo=pytz.utc)) allegation_2 = AllegationFactory(crid='456', incident_date=datetime( 2002, 2, 28, tzinfo=pytz.utc)) allegation_3 = AllegationFactory(crid='789', incident_date=datetime( 2003, 2, 28, tzinfo=pytz.utc)) allegation_4 = AllegationFactory(crid='321', incident_date=datetime( 2004, 2, 28, tzinfo=pytz.utc)) allegation_5 = AllegationFactory(crid='987', incident_date=datetime( 2005, 2, 28, tzinfo=pytz.utc)) allegation_category_1 = AllegationCategoryFactory( id=1, category='Category 1') allegation_category_12 = AllegationCategoryFactory( id=2, category='Category 2') OfficerAllegationFactory(allegation=allegation_1, allegation_category=allegation_category_1) OfficerAllegationFactory(allegation=allegation_1, allegation_category=allegation_category_1) OfficerAllegationFactory(allegation=allegation_1, allegation_category=allegation_category_12) AttachmentFileFactory(allegation=allegation_1, title='CR document 1', id=1, tag='CR', url='http://cr-document.com/1', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url1', external_created_at=datetime(2019, 1, 19, 12, 1, 1, tzinfo=pytz.utc)) AttachmentFileFactory(allegation=allegation_1, title='CR document 2', id=2, tag='CR', url='http://cr-document.com/2', file_type=MEDIA_TYPE_DOCUMENT, external_created_at=datetime(2019, 1, 14, 10, 12, 1, tzinfo=pytz.utc)) AttachmentFileFactory(allegation=allegation_2, title='CR document 3', id=3, tag='CR', url='http://cr-document.com/3', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url3', external_created_at=datetime(2019, 1, 15, 9, 3, 1, tzinfo=pytz.utc)) AttachmentFileFactory(allegation=allegation_2, title='CR document 4', id=4, tag='OCIR', url='http://cr-document.com/4', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url4', external_created_at=datetime(2019, 1, 19, 17, 12, 5, tzinfo=pytz.utc)) with freeze_time(datetime(2019, 1, 20, 13, 2, 15, tzinfo=pytz.utc)): AttachmentFileFactory(allegation=allegation_2, title='CR document 5', id=5, tag='AR', url='http://cr-document.com/5', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url5', external_created_at=None) AttachmentFileFactory(allegation=allegation_3, title='CR document 6', id=6, tag='CR', url='http://cr-document.com/6', file_type=MEDIA_TYPE_AUDIO, preview_image_url='http://preview.com/url6', external_created_at=datetime(2019, 1, 21, 6, 4, 12, tzinfo=pytz.utc)) AttachmentFileFactory(allegation=allegation_3, title='CR document 7', id=7, tag='CR', url='http://cr-document.com/7', file_type=MEDIA_TYPE_VIDEO, preview_image_url='http://preview.com/url7', external_created_at=datetime(2019, 1, 22, 4, 9, 12, tzinfo=pytz.utc)) attachment_file_1 = AttachmentFileFactory( title='Tracking document 1', id=8, tag='CR', url='http://cr-document.com/8', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url8', allegation=allegation_4, external_created_at=datetime(2014, 9, 14, 12, 0, 1, tzinfo=pytz.utc)) attachment_file_2 = AttachmentFileFactory( title='Tracking document 2', id=9, tag='CR', url='http://cr-document.com/9', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url9', allegation=allegation_4, external_created_at=datetime(2015, 9, 14, 12, 0, 1, tzinfo=pytz.utc)) AttachmentFileFactory(title='Not appear attachment', id=10, tag='CR', url='http://cr-document.com/10', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url10', allegation=allegation_4, external_created_at=datetime(2015, 6, 13, 12, 0, 1, tzinfo=pytz.utc)) attachment_file_3 = AttachmentFileFactory( title='Tracking document 3', id=11, tag='CR', url='http://cr-document.com/11', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url11', allegation=allegation_5, external_created_at=datetime(2015, 9, 14, 12, 0, 1, tzinfo=pytz.utc)) AttachmentFileFactory(allegation=allegation_1, title='CR document 12', id=12, tag='CR', url='http://cr-document.com/12', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url12', external_created_at=datetime(2015, 9, 14, 12, 0, 1, tzinfo=pytz.utc), show=False) attachment_file_4 = AttachmentFileFactory( title='Attachment not appear because is download event', id=13, tag='CR', url='http://cr-document.com/13', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url13', allegation=allegation_4, external_created_at=datetime(2015, 7, 13, 12, 0, 1, tzinfo=pytz.utc)) with freeze_time(datetime(2019, 1, 17, 12, 0, 1, tzinfo=pytz.utc)): AttachmentTrackingFactory(attachment_file=attachment_file_1) with freeze_time(datetime(2019, 1, 18, 12, 0, 1, tzinfo=pytz.utc)): AttachmentTrackingFactory(attachment_file=attachment_file_2) with freeze_time(datetime(2019, 1, 12, 12, 0, 1, tzinfo=pytz.utc)): AttachmentTrackingFactory(attachment_file=attachment_file_3) with freeze_time(datetime(2019, 10, 14, 12, 0, 1, tzinfo=pytz.utc)): AttachmentTrackingFactory(attachment_file=attachment_file_4, kind=constants.DOWNLOAD_EVENT_TYPE) allegation_cache_manager.cache_data() response = self.client.get(reverse('api-v2:cr-list-by-new-document'), {'limit': 5}) expect(response.status_code).to.eq(status.HTTP_200_OK) expect(len(response.data)).to.eq(4) expect(response.data).to.eq([ { 'crid': '123', 'latest_document': { 'id': '1', 'title': 'CR document 1', 'url': 'http://cr-document.com/1', 'preview_image_url': 'http://preview.com/url1', 'file_type': 'document' }, 'incident_date': '2001-02-28', 'category': 'Category 1' }, { 'crid': '321', 'latest_document': { 'id': '9', 'title': 'Tracking document 2', 'url': 'http://cr-document.com/9', 'preview_image_url': 'http://preview.com/url9', 'file_type': 'document' }, 'incident_date': '2004-02-28', }, { 'crid': '456', 'latest_document': { 'id': '3', 'title': 'CR document 3', 'url': 'http://cr-document.com/3', 'preview_image_url': 'http://preview.com/url3', 'file_type': 'document' }, 'incident_date': '2002-02-28', }, { 'crid': '987', 'latest_document': { 'id': '11', 'title': 'Tracking document 3', 'url': 'http://cr-document.com/11', 'preview_image_url': 'http://preview.com/url11', 'file_type': 'document' }, 'incident_date': '2005-02-28', }, ])
def test_retrieve(self): area = AreaFactory(name='Lincoln Square') officer1 = OfficerFactory( id=123, first_name='Mr', last_name='Foo', gender='M', race='White', rank='Officer', appointed_date=date(2001, 1, 1), birth_year=1993, complaint_percentile=4.4, civilian_allegation_percentile=1.1, internal_allegation_percentile=2.2, trr_percentile=3.3, allegation_count=1, sustained_count=1, ) OfficerBadgeNumberFactory(officer=officer1, star='12345', current=True) allegation = AllegationFactory(crid='12345', point=Point(12, 21), incident_date=datetime(2002, 2, 28, tzinfo=pytz.utc), add1=3510, add2='Michigan Ave', city='Chicago', location='Police Communications System', beat=area, is_officer_complaint=False, summary='Summary', first_start_date=date(2003, 3, 20), first_end_date=date(2006, 5, 26)) ComplainantFactory(allegation=allegation, gender='M', race='Black', age='18') VictimFactory(allegation=allegation, gender='M', race='Black', age=53) OfficerAllegationFactory( officer=officer1, allegation=allegation, final_finding='SU', disciplined=True, final_outcome='Separation', recc_outcome='10 Day Suspension', start_date=date(2003, 3, 20), end_date=date(2006, 5, 26), allegation_category=AllegationCategoryFactory( category='Operation/Personnel Violations', allegation_name='Secondary/Special Employment')) officer = OfficerFactory( id=3, first_name='Raymond', last_name='Piwinicki', appointed_date=date(2001, 5, 1), complaint_percentile=4.4, trr_percentile=5.5, allegation_count=1, sustained_count=1, ) OfficerAllegationFactory(officer=officer, final_finding='SU', start_date=date(2003, 2, 28), allegation__incident_date=datetime( 2002, 2, 28, tzinfo=pytz.utc), allegation__is_officer_complaint=False) PoliceWitnessFactory(officer=officer, allegation=allegation) investigator = OfficerFactory( id=1, first_name='Ellis', last_name='Skol', appointed_date=date(2001, 5, 1), complaint_percentile=6.6, civilian_allegation_percentile=7.7, internal_allegation_percentile=8.8, allegation_count=1, sustained_count=0, ) OfficerAllegationFactory(officer=investigator, final_finding='NS', start_date=date(2003, 2, 28), allegation__incident_date=datetime( 2002, 2, 28, tzinfo=pytz.utc), allegation__is_officer_complaint=False) investigator = InvestigatorFactory(officer=investigator) InvestigatorAllegationFactory(allegation=allegation, investigator=investigator, current_rank='IPRA investigator') AttachmentFileFactory(tag='TRR', allegation=allegation, title='CR document', id='123456', url='http://cr-document.com/', file_type=MEDIA_TYPE_DOCUMENT) AttachmentFileFactory(tag='TRR', allegation=allegation, title='CR arrest report document', url='http://cr-document.com/', file_type=MEDIA_TYPE_DOCUMENT) AttachmentFileFactory(tag='AR', allegation=allegation, title='CR document 2', id='654321', url='http://AR-document.com/', file_type=MEDIA_TYPE_DOCUMENT) officer_cache_manager.build_cached_columns() allegation_cache_manager.cache_data() response = self.client.get( reverse('api-v2:cr-detail', kwargs={'pk': '12345'})) expect(response.status_code).to.eq(status.HTTP_200_OK) expect(dict(response.data)).to.eq({ 'crid': '12345', 'most_common_category': { 'category': 'Operation/Personnel Violations', 'allegation_name': 'Secondary/Special Employment' }, 'coaccused': [{ 'id': 123, 'full_name': 'Mr Foo', 'gender': 'Male', 'race': 'White', 'rank': 'Officer', 'birth_year': 1993, 'recommended_outcome': '10 Day Suspension', 'final_outcome': 'Separation', 'final_finding': 'Sustained', 'category': 'Operation/Personnel Violations', 'complaint_count': 1, 'sustained_count': 1, 'percentile_allegation': '4.4000', 'percentile_allegation_civilian': '1.1000', 'percentile_allegation_internal': '2.2000', 'percentile_trr': '3.3000', 'disciplined': True }], 'complainants': [{ 'race': 'Black', 'gender': 'Male', 'age': 18 }], 'victims': [{ 'race': 'Black', 'gender': 'Male', 'age': 53 }], 'point': { 'lon': 12.0, 'lat': 21.0 }, 'summary': 'Summary', 'incident_date': '2002-02-28', 'start_date': '2003-03-20', 'end_date': '2006-05-26', 'address': '3510 Michigan Ave, Chicago', 'location': 'Police Communications System', 'beat': 'Lincoln Square', 'involvements': [{ 'involved_type': 'investigator', 'officer_id': 1, 'full_name': 'Ellis Skol', 'badge': 'CPD', 'percentile_allegation': '6.6000', 'percentile_allegation_civilian': '7.7000', 'percentile_allegation_internal': '8.8000', }, { 'involved_type': 'police_witness', 'officer_id': 3, 'full_name': 'Raymond Piwinicki', 'allegation_count': 1, 'sustained_count': 1, 'percentile_trr': '5.5000', 'percentile_allegation': '4.4000', }], 'attachments': [{ 'title': 'CR document', 'file_type': 'document', 'url': 'http://cr-document.com/', 'id': '123456', }] })
def test_extract_datum(self): allegation = AllegationFactory( crid='123456', incident_date=datetime(2017, 7, 27, tzinfo=pytz.utc), summary='abc', add1='3000', add2='Michigan Ave', city='Chicago IL' ) officer = OfficerFactory( id=10, first_name='Luke', last_name='Skywalker', allegation_count=4, complaint_percentile='99.70', trr_percentile='99.88', civilian_allegation_percentile='77.66', internal_allegation_percentile='66.55' ) officer2 = OfficerFactory( id=11, first_name='John', last_name='Doe', allegation_count=2, complaint_percentile='70.33', trr_percentile='66.88', civilian_allegation_percentile='33.66', internal_allegation_percentile='22.55' ) OfficerAllegationFactory(allegation=allegation, officer=officer) category1 = AllegationCategoryFactory( category='Operation/Personnel Violations', allegation_name='Secondary/Special Employment' ) category2 = AllegationCategoryFactory(category='Use of Force', allegation_name='sub category') OfficerAllegationFactory(allegation=allegation, allegation_category=category2, officer=officer2) OfficerAllegationFactory.create_batch(2, allegation=allegation, allegation_category=category1, officer=None) OfficerAllegationFactory.create_batch(3, allegation=allegation, allegation_category=None, officer=None) VictimFactory(allegation=allegation, gender='F', race='Black', age=25) VictimFactory(allegation=allegation, gender='', race='Black', age=25) VictimFactory(allegation=allegation, gender='F', race='Black', age=None) AttachmentFileFactory(id=1, allegation=allegation, text_content='') AttachmentFileFactory( id=2, allegation=allegation, show=False, text_content="CHICAGO POLICE DEPARTMENT RD I HT334604" ) AttachmentFileFactory(id=3, allegation=allegation, text_content='CHICAGO POLICE DEPARTMENT RD I HT334604') setattr(allegation, 'investigator_names', ['Jerome Finnigan']) allegation_cache_manager.cache_data() allegation.refresh_from_db() datum = CrIndexer().extract_datum(allegation) datum['victims'] = sorted( datum['victims'], key=lambda victim: (victim['gender'], victim['race'], victim.get('age', 0)) ) expect(datum).to.eq({ 'crid': '123456', 'category': 'Operation/Personnel Violations', 'sub_category': 'Secondary/Special Employment', 'incident_date': '2017-07-27', 'address': '3000 Michigan Ave, Chicago IL', 'summary': 'abc', 'to': '/complaint/123456/', 'investigator_names': ['Jerome Finnigan'], 'victims': [ {'gender': '', 'race': 'Black', 'age': 25}, {'gender': 'Female', 'race': 'Black'}, {'gender': 'Female', 'race': 'Black', 'age': 25}, ], 'coaccused': [ { 'id': 10, 'full_name': 'Luke Skywalker', 'allegation_count': 4, 'percentile_allegation': '99.7000', 'percentile_allegation_civilian': '77.6600', 'percentile_allegation_internal': '66.5500', 'percentile_trr': '99.8800', }, { 'id': 11, 'full_name': 'John Doe', 'allegation_count': 2, 'percentile_allegation': '70.3300', 'percentile_allegation_civilian': '33.6600', 'percentile_allegation_internal': '22.5500', 'percentile_trr': '66.8800', } ], 'attachment_files': [ {'id': 3, 'text_content': 'CHICAGO POLICE DEPARTMENT RD I HT334604'} ] })
def test_execute(self): allegation_1 = AllegationFactory(crid='123') allegation_2 = AllegationFactory(crid='456') allegation_3 = AllegationFactory(crid='789') allegation_4 = AllegationFactory(crid='321') allegation_5 = AllegationFactory(crid='987') allegation_category_1 = AllegationCategoryFactory(id=1) allegation_category_12 = AllegationCategoryFactory(id=2) OfficerAllegationFactory(allegation=allegation_1, allegation_category=allegation_category_1) OfficerAllegationFactory(allegation=allegation_1, allegation_category=allegation_category_1) OfficerAllegationFactory(allegation=allegation_1, allegation_category=allegation_category_12) attachment_file_1 = AttachmentFileFactory( allegation=allegation_1, title='CR document 1', id=1, tag='CR', url='http://cr-document.com/1', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url1', external_created_at=datetime(2019, 1, 19, 12, 1, 1, tzinfo=pytz.utc)) AttachmentFileFactory(allegation=allegation_1, title='CR document 2', id=2, tag='CR', url='http://cr-document.com/2', file_type=MEDIA_TYPE_DOCUMENT, external_created_at=datetime(2019, 1, 14, 10, 12, 1, tzinfo=pytz.utc)) attachment_file_2 = AttachmentFileFactory( allegation=allegation_2, title='CR document 3', id=3, tag='CR', url='http://cr-document.com/3', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url3', external_created_at=datetime(2019, 1, 15, 9, 3, 1, tzinfo=pytz.utc)) AttachmentFileFactory(allegation=allegation_2, title='CR document 4', id=4, tag='OCIR', url='http://cr-document.com/4', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url4', external_created_at=datetime(2019, 1, 19, 17, 12, 5, tzinfo=pytz.utc)) with freeze_time(datetime(2019, 1, 20, 13, 2, 15, tzinfo=pytz.utc)): AttachmentFileFactory(allegation=allegation_2, title='CR document 5', id=5, tag='AR', url='http://cr-document.com/5', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url5', external_created_at=None) AttachmentFileFactory(allegation=allegation_3, title='CR document 6', id=6, tag='CR', url='http://cr-document.com/6', file_type=MEDIA_TYPE_AUDIO, preview_image_url='http://preview.com/url6', external_created_at=datetime(2019, 1, 21, 6, 4, 12, tzinfo=pytz.utc)) AttachmentFileFactory(allegation=allegation_3, title='CR document 7', id=7, tag='CR', url='http://cr-document.com/7', file_type=MEDIA_TYPE_VIDEO, preview_image_url='http://preview.com/url7', external_created_at=datetime(2019, 1, 22, 4, 9, 12, tzinfo=pytz.utc)) attachment_file_3 = AttachmentFileFactory( title='Tracking document 1', id=8, tag='CR', url='http://cr-document.com/8', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url8', allegation=allegation_4, external_created_at=datetime(2014, 9, 14, 12, 0, 1, tzinfo=pytz.utc)) attachment_file_4 = AttachmentFileFactory( title='Tracking document 2', id=9, tag='CR', url='http://cr-document.com/9', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url9', allegation=allegation_4, external_created_at=datetime(2015, 9, 14, 12, 0, 1, tzinfo=pytz.utc)) AttachmentFileFactory(title='Not appear attachment', id=10, tag='CR', url='http://cr-document.com/10', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url10', allegation=allegation_4, external_created_at=datetime(2015, 6, 13, 12, 0, 1, tzinfo=pytz.utc)) attachment_file_5 = AttachmentFileFactory( title='Tracking document 3', id=11, tag='CR', url='http://cr-document.com/11', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url11', allegation=allegation_5, external_created_at=datetime(2015, 9, 14, 12, 0, 1, tzinfo=pytz.utc)) # Should not have this in result because show = False AttachmentFileFactory(allegation=allegation_1, title='CR document 12', id=12, tag='CR', url='http://cr-document.com/12', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url12', external_created_at=datetime(2015, 9, 14, 12, 0, 1, tzinfo=pytz.utc), show=False) # Should still count but not 1st row because is attached to a download event attachment_file_6 = AttachmentFileFactory( title='Attachment not appear because is download event', id=13, tag='CR', url='http://cr-document.com/13', file_type=MEDIA_TYPE_DOCUMENT, preview_image_url='http://preview.com/url13', allegation=allegation_4, external_created_at=datetime(2015, 7, 13, 12, 0, 1, tzinfo=pytz.utc)) with freeze_time(datetime(2019, 1, 17, 12, 0, 1, tzinfo=pytz.utc)): AttachmentTrackingFactory(attachment_file=attachment_file_3) with freeze_time(datetime(2019, 1, 18, 12, 0, 1, tzinfo=pytz.utc)): AttachmentTrackingFactory(attachment_file=attachment_file_4) with freeze_time(datetime(2019, 1, 12, 12, 0, 1, tzinfo=pytz.utc)): AttachmentTrackingFactory(attachment_file=attachment_file_5) with freeze_time(datetime(2019, 10, 14, 12, 0, 1, tzinfo=pytz.utc)): AttachmentTrackingFactory(attachment_file=attachment_file_6, kind=constants.DOWNLOAD_EVENT_TYPE) allegation_cache_manager.cache_data() results = LatestDocumentsQuery.execute(5) expected_results = [ { 'id': attachment_file_1.id, 'allegation_id': '123', 'last_active_at': datetime(2019, 1, 19, 12, 1, 1, tzinfo=pytz.utc), }, { 'id': attachment_file_4.id, 'allegation_id': '321', 'last_active_at': datetime(2019, 1, 18, 12, 0, 1, tzinfo=pytz.utc), }, { 'id': attachment_file_2.id, 'allegation_id': '456', 'last_active_at': datetime(2019, 1, 15, 9, 3, 1, tzinfo=pytz.utc), }, { 'id': attachment_file_5.id, 'allegation_id': '987', 'last_active_at': datetime(2019, 1, 12, 12, 0, 1, tzinfo=pytz.utc), }, ] expect(len(results)).to.eq(len(expected_results)) for index, attachment_data in enumerate(results): expected_attachment_data = expected_results[index] expect(attachment_data.id).to.eq(expected_attachment_data['id']) expect(attachment_data.allegation_id).to.eq( expected_attachment_data['allegation_id']) expect(attachment_data.last_active_at).to.eq( expected_attachment_data['last_active_at'])
def test_retrieve_data_range_too_small_cause_no_percentiles(self): officer = OfficerFactory( tags=[], first_name='Kevin', last_name='Kerl', id=123, race='White', gender='M', appointed_date=date(2002, 2, 27), rank='PO', resignation_date=date(2017, 12, 27), active=ACTIVE_YES_CHOICE, birth_year=1960, complaint_percentile=32.5, sustained_count=1, allegation_count=2, discipline_count=1, trr_count=1, civilian_compliment_count=1, honorable_mention_count=1, major_award_count=1, last_unit_id=1, current_badge='123456' ) allegation = AllegationFactory(incident_date=datetime(2002, 3, 1, tzinfo=pytz.utc)) internal_allegation = AllegationFactory( incident_date=datetime(2002, 4, 1, tzinfo=pytz.utc), is_officer_complaint=True ) allegation_category = AllegationCategoryFactory(category='Use of Force') OfficerHistoryFactory( officer=officer, effective_date=datetime(2002, 2, 27, tzinfo=pytz.utc), unit=PoliceUnitFactory(id=1, unit_name='CAND', description='') ) ComplainantFactory(allegation=allegation, race='White', age=18, gender='F') OfficerBadgeNumberFactory(officer=officer, star='123456', current=True) OfficerBadgeNumberFactory(officer=officer, star='789', current=False) OfficerAllegationFactory( officer=officer, allegation=allegation, allegation_category=allegation_category, final_finding='SU', start_date=date(2002, 3, 2), disciplined=True ) OfficerAllegationFactory( officer=officer, allegation=internal_allegation, final_finding='NS', start_date=date(2002, 3, 2), disciplined=False ) AwardFactory(officer=officer, award_type='Complimentary Letter', start_date=date(2014, 5, 1)) AwardFactory(officer=officer, award_type='Honored Police Star', start_date=date(2014, 6, 1)) AwardFactory(officer=officer, award_type='Honorable Mention', start_date=date(2014, 7, 1)) SalaryFactory(officer=officer, salary=50000, year=2002) SalaryFactory(officer=officer, salary=90000, year=2017) TRRFactory(officer=officer, trr_datetime=datetime(2002, 3, 1, tzinfo=pytz.utc)) second_officer = OfficerFactory( tags=[], first_name='Kevin', last_name='Osborn', id=456, race='Black', gender='M', appointed_date=date(2002, 1, 27), resignation_date=date(2017, 12, 27), rank='PO', active=ACTIVE_YES_CHOICE, birth_year=1970 ) TRRFactory(officer=second_officer, trr_datetime=datetime(2002, 5, 1, tzinfo=pytz.utc)) TRRFactory(officer=second_officer, trr_datetime=datetime(2002, 12, 1, tzinfo=pytz.utc)) OfficerFactory( tags=[], first_name='Kevin', last_name='Edward', id=789, race='Black', gender='M', appointed_date=date(2002, 3, 27), resignation_date=date(2017, 12, 27), rank='PO', active=ACTIVE_YES_CHOICE, birth_year=1970 ) officer_cache_manager.build_cached_columns() allegation_cache_manager.cache_data() response = self.client.get(reverse('api-v2:officers-mobile-detail', kwargs={'pk': 123})) expected_response = { 'officer_id': 123, 'unit': { 'unit_id': 1, 'unit_name': 'CAND', 'description': '', }, 'date_of_appt': '2002-02-27', 'date_of_resignation': '2017-12-27', 'active': 'Active', 'rank': 'PO', 'full_name': 'Kevin Kerl', 'race': 'White', 'badge': '123456', 'historic_badges': ['789'], 'gender': 'Male', 'birth_year': 1960, 'sustained_count': 1, 'unsustained_count': 1, 'civilian_compliment_count': 1, 'allegation_count': 2, 'discipline_count': 1, 'honorable_mention_count': 1, 'trr_count': 1, 'major_award_count': 1, 'percentile_allegation': '32.5000', 'percentiles': [] } expect(response.data).to.eq(expected_response)