def test_get_involvements(self, police_witness_serializer_mock, investigator_allegation_serializer_mock): allegation = AllegationFactory() officer_1 = OfficerFactory() officer_2 = OfficerFactory() PoliceWitnessFactory(officer=officer_1, allegation=allegation) PoliceWitnessFactory(officer=officer_2, allegation=allegation) OfficerBadgeNumberFactory(officer=officer_1, star='456789') investigator_1 = InvestigatorFactory(officer=officer_1) investigator_2 = InvestigatorFactory(officer=officer_2) investigator_3 = InvestigatorFactory() investigator_allegation_1 = InvestigatorAllegationFactory(allegation=allegation, investigator=investigator_1) investigator_allegation_2 = InvestigatorAllegationFactory(allegation=allegation, investigator=investigator_2) investigator_allegation_3 = InvestigatorAllegationFactory(allegation=allegation, investigator=investigator_3) investigator_allegations = [investigator_allegation_1, investigator_allegation_2, investigator_allegation_3] expected_has_badge_numbers = { investigator_allegation_1.id: True, investigator_allegation_2.id: False, investigator_allegation_3.id: False, } result = CRSerializer(allegation).data investigator_allegations_arg = investigator_allegation_serializer_mock.call_args[0][0] police_witnesses_arg = police_witness_serializer_mock.call_args[0][0] expect(set(investigator_allegations_arg)).to.eq(set(investigator_allegations)) for obj in investigator_allegations_arg: expect(obj.has_badge_number).to.eq(expected_has_badge_numbers[obj.id]) expect(set(police_witnesses_arg)).to.eq(set([officer_1, officer_2])) expect(result['involvements']).to.eq( [{'officer_id': 1}, {'officer_id': 2}, {'officer_id': 4}, {'officer_id': 3}] )
def test_extra_data_populated(self): allegation = AllegationFactory(crid='1122123') OfficerAllegationFactory(allegation=allegation) InvestigatorAllegationFactory(allegation=allegation) PoliceWitnessFactory(allegation=allegation) indexer = CRPartialIndexer(updating_keys=['123', '456']) expect(indexer.coaccused_dict['1122123']).to.have.length(1) expect(indexer.investigator_dict['1122123']).to.have.length(1) expect(indexer.policewitness_dict['1122123']).to.have.length(1)
def test_relevant_complaints_via_police_witnesses(self): pinned_officer_1 = OfficerFactory(id=1) pinned_officer_2 = OfficerFactory(id=2) not_relevant_officer = OfficerFactory(id=999) relevant_allegation_11 = AllegationFactory(crid='11', incident_date=datetime( 2002, 2, 21, tzinfo=pytz.utc)) relevant_allegation_12 = AllegationFactory(crid='12', incident_date=datetime( 2002, 2, 22, tzinfo=pytz.utc)) relevant_allegation_21 = AllegationFactory(crid='21', incident_date=datetime( 2002, 2, 23, tzinfo=pytz.utc)) not_relevant_allegation = AllegationFactory(crid='999') pinboard = PinboardFactory( title='Test pinboard', description='Test description', ) pinboard.officers.set([pinned_officer_1, pinned_officer_2]) PoliceWitnessFactory(allegation=relevant_allegation_11, officer=pinned_officer_1) PoliceWitnessFactory(allegation=relevant_allegation_12, officer=pinned_officer_1) PoliceWitnessFactory(allegation=relevant_allegation_21, officer=pinned_officer_2) PoliceWitnessFactory(allegation=not_relevant_allegation, officer=not_relevant_officer) relevant_complaints = list(pinboard.relevant_complaints) expect(relevant_complaints).to.have.length(3) expect(relevant_complaints[0].crid).to.eq('21') expect(relevant_complaints[1].crid).to.eq('12') expect(relevant_complaints[2].crid).to.eq('11')
def test_police_witness_counts(self): officer = OfficerFactory() OfficerAllegationFactory.create_batch(2, officer=officer, final_finding='SU') OfficerAllegationFactory(officer=officer, final_finding='NS') allegation = AllegationFactory() PoliceWitnessFactory(officer=officer, allegation=allegation) rows = self.extract_data() expect(rows).to.have.length(4) expect({len(row['involvements']) for row in rows}).to.eq({0, 1}) for row in rows: if len(row['involvements']) == 1: expect(row['involvements'][0]['allegation_count']).to.eq(3) expect(row['involvements'][0]['sustained_count']).to.eq(2)
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_export_xlsx(self): allegation = AllegationFactory(crid='1009678', location='Tavern/Liquor Store', add1='37XX', add2='W 63RD ST', city='CHICAGO IL', old_complaint_address=None, incident_date=datetime(2007, 9, 28, 0, 0, tzinfo=pytz.utc), beat=AreaFactory(name='0823'), is_officer_complaint=True, coaccused_count=19) allegation1 = AllegationFactory( crid='1012803', location='Public Way - Other', add1='31XX', add2='N NEWCASTLE AVE', city='CHICAGO IL', old_complaint_address=None, incident_date=datetime(2005, 11, 1, 0, 0, tzinfo=pytz.utc), beat=AreaFactory(name='2511'), is_officer_complaint=False, coaccused_count=9) officer = OfficerFactory( id=8562, first_name='Jerome', last_name='Finnigan', middle_initial='A', middle_initial2=None, suffix_name=None, ) officer1 = OfficerFactory( first_name='Jeffery', last_name='Aaron', middle_initial='M', middle_initial2=None, suffix_name=None, gender='M', race='White', appointed_date=date(2005, 9, 26), resignation_date=None, rank='Sergeant of Police', birth_year=1971, active='Yes', complaint_percentile=Decimal('61.2357'), civilian_allegation_percentile=Decimal('61.2069'), internal_allegation_percentile=Decimal('76.9384'), trr_percentile=Decimal('79.8763'), honorable_mention_percentile=Decimal('94.8669'), allegation_count=6, sustained_count=0, honorable_mention_count=61, unsustained_count=0, discipline_count=0, civilian_compliment_count=4, trr_count=7, major_award_count=0, current_badge='1424', last_unit=PoliceUnitFactory(unit_name='003'), current_salary=101442, ) officer2 = OfficerFactory( first_name='Karina', last_name='Aaron', middle_initial=None, middle_initial2=None, suffix_name=None, gender='F', race='Hispanic', appointed_date=date(2005, 9, 26), resignation_date=None, rank='Police Officer', birth_year=1980, active='Yes', complaint_percentile=Decimal('72.0378'), civilian_allegation_percentile=Decimal('76.4252'), internal_allegation_percentile=Decimal('0.0000'), trr_percentile=Decimal('67.4458'), honorable_mention_percentile=Decimal('96.0992'), allegation_count=8, sustained_count=0, honorable_mention_count=71, unsustained_count=2, discipline_count=0, civilian_compliment_count=2, trr_count=4, major_award_count=0, current_badge='20373', last_unit=PoliceUnitFactory(unit_name='001'), current_salary=94122, ) allegation_category = AllegationCategoryFactory( category='Illegal Search', allegation_name='Improper Search Of Person', ) allegation_category1 = AllegationCategoryFactory( category='False Arrest', allegation_name='Illegal Arrest / False Arrest', ) OfficerAllegationFactory( officer=officer, allegation=allegation, allegation_category=allegation_category, start_date=date(2007, 9, 28), end_date=None, recc_finding='', recc_outcome='Unknown', final_finding='', final_outcome='Unknown', disciplined=None, ) OfficerAllegationFactory( officer=officer, allegation=allegation1, allegation_category=allegation_category1, start_date=date(2007, 12, 21), end_date=date(2008, 5, 29), recc_finding='', recc_outcome='Unknown', final_finding='', final_outcome='Unknown', disciplined=None, ) OfficerAllegationFactory( officer=officer1, allegation=allegation, allegation_category=allegation_category, start_date=date(1967, 10, 21), end_date=date(1980, 8, 1), recc_finding='', recc_outcome='Unknown', final_finding='SU', final_outcome='30 Day Suspension', disciplined=True, ) OfficerAllegationFactory( officer=officer2, allegation=allegation, allegation_category=allegation_category, start_date=date(1970, 8, 13), end_date=date(1973, 9, 15), recc_finding='', recc_outcome='Unknown', final_finding='SU', final_outcome='Suspended Over 30 Days', final_outcome_class='', disciplined=True, ) VictimFactory( allegation=allegation, gender='M', race='Hispanic', birth_year=1973, ) VictimFactory( allegation=allegation1, gender='', race='', birth_year=None, ) witness = OfficerFactory( first_name='Jeffery', last_name='Aaron', middle_initial='M', middle_initial2=None, suffix_name=None, gender='M', race='White', appointed_date=date(2005, 9, 26), resignation_date=None, rank='Sergeant of Police', birth_year=1971, active='Yes', complaint_percentile=Decimal('61.2357'), civilian_allegation_percentile=Decimal('61.2069'), internal_allegation_percentile=Decimal('76.9384'), trr_percentile=Decimal('79.8763'), honorable_mention_percentile=Decimal('94.8669'), allegation_count=6, sustained_count=0, honorable_mention_count=61, unsustained_count=0, discipline_count=0, civilian_compliment_count=4, trr_count=7, major_award_count=0, current_badge='1424', last_unit=PoliceUnitFactory(unit_name='003'), current_salary=101442, ) PoliceWitnessFactory( officer=witness, allegation=allegation, ) writer = AccusedXlsxWriter(officer, self.test_output_dir) writer.export_xlsx() self.covert_xlsx_to_csv('accused.xlsx') self.assert_csv_files_equal('accused_8562', [ 'Allegation', 'Coaccused Officer', 'Beat', 'Police Witness', 'Victim' ])
def test_emit_correct_format(self): allegation = AllegationFactory( crid='12345', summary='Summary', point=Point(12, 21), incident_date=datetime(2002, 2, 28, tzinfo=pytz.utc), add1='3510', add2='Michigan Ave', city='Chicago', location='Police Building', beat=AreaFactory(name='23'), is_officer_complaint=False, first_start_date=date(2003, 3, 28), first_end_date=date(2003, 4, 28), ) coaccused = OfficerFactory( id=1, first_name='Foo', last_name='Bar', gender='M', race='White', birth_year=1986, appointed_date=date(2001, 1, 1), rank='Officer', complaint_percentile=Decimal(0), civilian_allegation_percentile=Decimal(1.1), internal_allegation_percentile=Decimal(2.2), trr_percentile=Decimal(3.3), allegation_count=1, sustained_count=1, ) OfficerAllegationFactory( officer=coaccused, allegation=allegation, final_finding='SU', recc_outcome='Separation', final_outcome='Reprimand', start_date=date(2003, 3, 28), end_date=date(2003, 4, 28), allegation_category=AllegationCategoryFactory( category='Operation/Personnel Violations', allegation_name='NEGLECT OF DUTY/CONDUCT UNBECOMING - ON DUTY' ), disciplined=True ) ComplainantFactory(allegation=allegation, gender='M', race='White', age=30) ComplainantFactory(allegation=allegation, gender='F', race='Black', age=25) VictimFactory(allegation=allegation, gender='F', race='Black', age=25) VictimFactory(allegation=allegation, gender='M', race='Hispanic', age=40) officer = OfficerFactory( id=2, first_name='Jerome', last_name='Finnigan', gender='M', 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=3, first_name='German', last_name='Lauren', 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='Other', allegation=allegation, file_type='document', title='CR document', url='http://foo.com/', preview_image_url='http://web.com/image', ) AttachmentFileFactory( tag='Other', allegation=allegation, file_type='document', title='CR document', url='http://foo.com/', preview_image_url='http://web.com/image', show=False ) AttachmentFileFactory( allegation=allegation, file_type='document', tag='OCIR', title='CR document', url='http://foo.com/', preview_image_url='http://web.com/image', ) indexer = CRIndexer() rows = list(indexer.get_queryset()) row = [obj for obj in rows if obj['crid'] == '12345'][0] result = indexer.extract_datum(row) expect(dict(result)).to.eq({ 'crid': '12345', 'most_common_category': { 'category': 'Operation/Personnel Violations', 'allegation_name': 'NEGLECT OF DUTY/CONDUCT UNBECOMING - ON DUTY' }, 'category_names': ['Operation/Personnel Violations'], 'coaccused': [ { 'id': 1, 'full_name': 'Foo Bar', 'abbr_name': 'F. Bar', 'gender': 'Male', 'race': 'White', 'rank': 'Officer', 'final_finding': 'Sustained', 'recc_outcome': 'Separation', 'final_outcome': 'Reprimand', 'category': 'Operation/Personnel Violations', 'subcategory': 'NEGLECT OF DUTY/CONDUCT UNBECOMING - ON DUTY', 'start_date': '2003-03-28', 'end_date': '2003-04-28', 'age': 32, 'allegation_count': 1, 'sustained_count': 1, 'percentile_allegation': Decimal('0'), 'percentile_allegation_civilian': Decimal('1.1'), 'percentile_allegation_internal': Decimal('2.2'), 'percentile_trr': Decimal('3.3'), 'disciplined': True } ], 'complainants': [ {'gender': 'Male', 'race': 'White', 'age': 30}, {'gender': 'Female', 'race': 'Black', 'age': 25} ], 'victims': [ {'gender': 'Female', 'race': 'Black', 'age': 25}, {'gender': 'Male', 'race': 'Hispanic', 'age': 40} ], 'summary': 'Summary', 'point': {'lon': 12.0, 'lat': 21.0}, 'incident_date': '2002-02-28', 'start_date': '2003-03-28', 'end_date': '2003-04-28', 'address': '3510 Michigan Ave, Chicago', 'location': 'Police Building', 'beat': '23', 'involvements': [ { 'involved_type': 'investigator', 'officer_id': 3, 'full_name': 'German Lauren', 'abbr_name': 'G. Lauren', 'num_cases': 1, 'current_rank': 'IPRA investigator', 'percentile_allegation': Decimal('6.6000'), 'percentile_allegation_civilian': Decimal('7.7000'), 'percentile_allegation_internal': Decimal('8.8000'), 'percentile_trr': None }, { 'involved_type': 'police_witness', 'officer_id': 2, 'full_name': 'Jerome Finnigan', 'abbr_name': 'J. Finnigan', 'gender': 'Male', 'race': 'White', 'allegation_count': 1, 'sustained_count': 1, 'percentile_allegation': Decimal('4.4000'), 'percentile_allegation_civilian': None, 'percentile_allegation_internal': None, 'percentile_trr': Decimal('5.5000') } ], 'attachments': [ { 'title': 'CR document', 'file_type': 'document', 'url': 'http://foo.com/', 'preview_image_url': 'http://web.com/image' } ] })