def test_complainant_gender_aggregation(self): unit = PoliceUnitFactory() officer = OfficerFactory() allegation1 = AllegationFactory() allegation2 = AllegationFactory() OfficerHistoryFactory(officer=officer, unit=unit) OfficerAllegationFactory(officer=officer, allegation=allegation1, final_finding='SU') OfficerAllegationFactory(officer=officer, allegation=allegation2, final_finding='UN') ComplainantFactory(allegation=allegation1, gender='F') ComplainantFactory(allegation=allegation2, gender='') expect( sorted(unit.complainant_gender_aggregation, key=itemgetter('name'))).to.eq([{ 'name': 'Female', 'count': 1, 'sustained_count': 1 }, { 'name': 'Unknown', 'count': 1, 'sustained_count': 0 }])
def test_complainant_genders(self): allegation = AllegationFactory() ComplainantFactory(gender='F', allegation=allegation) expect(allegation.complainant_genders).to.eq(['Female']) ComplainantFactory(gender='U', allegation=allegation) expect(allegation.complainant_genders).to.eq(['Female', 'Unknown'])
def test_complainant_races(self): allegation = AllegationFactory() ComplainantFactory(race='White', allegation=allegation) expect(allegation.complainant_races).to.eq(['White']) ComplainantFactory(race='White/Hispinic', allegation=allegation) expect(allegation.complainant_races).to.eq(['White', 'White/Hispinic'])
def test_complainant_age_groups(self): allegation = AllegationFactory() ComplainantFactory(age=32, allegation=allegation) expect(allegation.complainant_age_groups).to.eq(['31-40']) ComplainantFactory(age=38, allegation=allegation) expect(allegation.complainant_age_groups).to.eq(['31-40']) ComplainantFactory(age=55, allegation=allegation) expect(allegation.complainant_age_groups).to.eq(['31-40', '51+']) allegation_no_complainant = AllegationFactory() expect(allegation_no_complainant.complainant_age_groups).to.eq(['Unknown'])
def test_complainant_race_aggregation(self): officer = OfficerFactory() allegation1 = AllegationFactory() allegation2 = AllegationFactory() allegation3 = AllegationFactory() OfficerAllegationFactory(officer=officer, allegation=allegation1, start_date=date(2010, 1, 1), final_finding='SU') OfficerAllegationFactory(officer=officer, allegation=allegation2, start_date=date(2011, 1, 1), final_finding='NS') OfficerAllegationFactory(officer=officer, allegation=allegation3, start_date=None, final_finding='NS') ComplainantFactory(allegation=allegation1, race='White') ComplainantFactory(allegation=allegation2, race='') ComplainantFactory(allegation=allegation3, race='White') expect(officer.complainant_race_aggregation).to.eq([{ 'name': 'White', 'count': 2, 'sustained_count': 1, 'items': [{ 'year': 2010, 'count': 1, 'sustained_count': 1, 'name': 'White' }] }, { 'name': 'Unknown', 'count': 1, 'sustained_count': 0, 'items': [{ 'year': 2011, 'count': 1, 'sustained_count': 0, 'name': 'Unknown' }] }])
def test_extract_info_complaint_record_complainant_null_age(self): allegation = AllegationFactory() ComplainantFactory(allegation=allegation, age=None) OfficerAllegationFactory(final_finding='UN', start_date=date(2000, 1, 2), allegation=allegation) rows = self.extract_data() expect(rows).to.have.length(1) expect(rows[0]['complaint_records']['facets'][2]).to.eq({ 'name': 'complainant age', 'entries': [{ 'name': 'Unknown', 'count': 1, 'sustained_count': 0, 'items': [{ 'year': 2000, 'name': 'Unknown', 'count': 1, 'sustained_count': 0 }] }] })
def test_complainant_age_aggregation(self): unit = PoliceUnitFactory() officer = OfficerFactory() allegation1 = AllegationFactory() allegation2 = AllegationFactory() OfficerHistoryFactory(officer=officer, unit=unit) OfficerAllegationFactory(officer=officer, allegation=allegation1, final_finding='SU') OfficerAllegationFactory(officer=officer, allegation=allegation2, final_finding='UN') ComplainantFactory(allegation=allegation1, age=25) ComplainantFactory(allegation=allegation2, age=None) expect(unit.complainant_age_aggregation).to.eq([{ 'name': '21-30', 'count': 1, 'sustained_count': 1 }, { 'name': 'Unknown', 'count': 1, 'sustained_count': 0 }])
def test_complainant_race_aggregation(self): unit = PoliceUnitFactory() officer = OfficerFactory() allegation = AllegationFactory() OfficerHistoryFactory(unit=unit, officer=officer) OfficerAllegationFactory(officer=officer, allegation=allegation, final_finding='NS') ComplainantFactory(allegation=allegation, race='White') expect(unit.complainant_race_aggregation).to.eq([{ 'name': 'White', 'count': 1, 'sustained_count': 0 }])
def test_complainant_gender_aggregation_with_duplicated_allegation(self): unit = PoliceUnitFactory() officer1 = OfficerFactory() officer2 = OfficerFactory() allegation = AllegationFactory() OfficerHistoryFactory(officer=officer1, unit=unit) OfficerHistoryFactory(officer=officer2, unit=unit) OfficerAllegationFactory(officer=officer1, allegation=allegation, final_finding='SU') OfficerAllegationFactory(officer=officer2, allegation=allegation, final_finding='SU') ComplainantFactory(allegation=allegation, gender='F') expect(unit.complainant_gender_aggregation).to.eq([{ 'name': 'Female', 'count': 1, 'sustained_count': 1 }])
def test_return_correct_response(self): officer = OfficerFactory(first_name='John', last_name='Hurley') OfficerAllegationFactory(allegation=self.allegation, officer=officer) complaint = OfficerAllegationFactory( allegation__point=Point([0.01, 0.01]), allegation__incident_date=datetime(2016, 2, 23, tzinfo=pytz.utc), officer=officer, allegation_category__category='False Arrest') ComplainantFactory(allegation=complaint.allegation, gender='M', race='Black', age='18') self.refresh_index() response = self.search(self.allegation.crid, { 'match': 'officers', 'distance': '10mi' }) expect(response.status_code).to.eq(status.HTTP_200_OK) expect(response.data).to.eq({ 'count': 1, 'previous': None, 'next': None, 'results': [{ 'crid': str(complaint.allegation.crid), 'coaccused': ['J. Hurley'], 'category_names': [ 'False Arrest', ], 'complainants': [{ 'race': 'Black', 'gender': 'Male', 'age': 18 }], 'point': { 'lat': 0.01, 'lon': 0.01 }, 'incident_date': '2016-02-23', }] })
def test_query_matching_allegation_with_same_officers(self): officer = OfficerFactory() OfficerAllegationFactory(allegation=self.allegation, officer=officer) complaint = OfficerAllegationFactory(allegation__point=Point( [0.01, 0.01]), officer=officer) ComplainantFactory(allegation=complaint.allegation, gender='M', race='Black', age='18') OfficerAllegationFactory(allegation__point=Point([0.01, 0.01])) self.refresh_index() response = self.search(self.allegation.crid, { 'match': 'officers', 'distance': '1mi' }) expect(response.status_code).to.eq(status.HTTP_200_OK) expect(response.data['count']).to.eq(1) expect(response.data['results'][0]['crid']).to.eq( str(complaint.allegation.crid))
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)
def test_extract_info_complaint_record_null_complainant(self): officer = OfficerFactory() OfficerAllegationFactory(officer=officer, final_finding='UN', start_date=date(2000, 1, 2)) allegation = AllegationFactory() ComplainantFactory(allegation=allegation, race='White', gender='M', age=21) OfficerAllegationFactory(officer=officer, allegation=allegation, final_finding='UN', start_date=None) rows = self.extract_data() expect(rows).to.have.length(1) expect(rows[0]['complaint_records']['facets'][1:]).to.eq([{ 'name': 'complainant race', 'entries': [{ 'name': 'Unknown', 'count': 1, 'sustained_count': 0, 'items': [{ 'year': 2000, 'name': 'Unknown', 'count': 1, 'sustained_count': 0 }] }, { 'name': 'White', 'count': 1, 'sustained_count': 0, 'items': [{ 'year': None, 'name': 'White', 'count': 1, 'sustained_count': 0 }] }] }, { 'name': 'complainant age', 'entries': [{ 'name': 'Unknown', 'count': 1, 'sustained_count': 0, 'items': [{ 'year': 2000, 'name': 'Unknown', 'count': 1, 'sustained_count': 0 }] }, { 'name': '20-30', 'count': 1, 'sustained_count': 0, 'items': [{ 'year': None, 'name': '20-30', 'count': 1, 'sustained_count': 0 }] }] }, { 'name': 'complainant gender', 'entries': [{ 'name': 'Unknown', 'count': 1, 'sustained_count': 0, 'items': [{ 'year': 2000, 'name': 'Unknown', 'count': 1, 'sustained_count': 0 }] }, { 'name': 'Male', 'count': 1, 'sustained_count': 0, 'items': [{ 'year': None, 'name': 'Male', 'count': 1, 'sustained_count': 0 }] }] }])
def test_extract_info(self): officer = OfficerFactory(id=123, first_name='Alex', last_name='Mack', rank='5', race='White', gender='M', appointed_date=date(2017, 2, 27), resignation_date=date(2017, 12, 27), active='Yes', birth_year=1910, complaint_percentile=99.8, honorable_mention_percentile=98, tags=['Jason VanDyke']) TRRFactory(officer=officer, trr_datetime=datetime(2002, 9, 29, tzinfo=pytz.utc)) SalaryFactory(officer=officer, salary=9000) AwardFactory(officer=officer, award_type='Honorable Mention') AwardFactory(officer=officer, award_type='Complimentary Letter') AwardFactory(officer=officer, award_type='Honored Police Star') AwardFactory(officer=officer, award_type='Lambert Tree') OfficerHistoryFactory(officer=officer, unit__id=1001, unit__unit_name='001', unit__description='Hyde Park D', effective_date=date(2010, 1, 1), end_date=date(2011, 1, 1)) OfficerHistoryFactory(officer=officer, unit__id=1002, unit__unit_name='002', unit__description='Tactical', effective_date=date(2011, 1, 2)) OfficerBadgeNumberFactory(officer=officer, star='123456', current=True) OfficerBadgeNumberFactory(officer=officer, star='123', current=False) OfficerBadgeNumberFactory(officer=officer, star='456', current=False) allegation = AllegationFactory( incident_date=datetime(2000, 4, 26, tzinfo=pytz.utc)) OfficerAllegationFactory( officer=officer, final_finding='SU', start_date=date(2000, 1, 1), allegation_category__category='Illegal Search', allegation=allegation, disciplined=True) ComplainantFactory(allegation=allegation, race='White', age=18, gender='M') rows = self.extract_data() expect(rows).to.have.length(1) expect(rows[0]).to.eq({ 'id': 123, 'full_name': 'Alex Mack', 'unit': { 'id': 1002, 'unit_name': '002', 'description': 'Tactical', 'long_unit_name': 'Unit 002' }, 'rank': '5', 'race': 'White', 'badge': '123456', 'badge_keyword': '123456', 'historic_badges': ['123', '456'], 'historic_badges_keyword': ['123', '456'], 'historic_units': [{ 'id': 1002, 'unit_name': '002', 'description': 'Tactical', 'long_unit_name': 'Unit 002', }, { 'id': 1001, 'unit_name': '001', 'description': 'Hyde Park D', 'long_unit_name': 'Unit 001', }], 'gender': 'Male', 'date_of_appt': '2017-02-27', 'date_of_resignation': '2017-12-27', 'active': 'Active', 'birth_year': 1910, 'complaint_records': { 'count': 1, 'sustained_count': 1, 'items': [{ 'year': 2000, 'count': 1, 'sustained_count': 1 }], 'facets': [{ 'name': 'category', 'entries': [{ 'name': 'Illegal Search', 'count': 1, 'sustained_count': 1, 'items': [{ 'year': 2000, 'name': 'Illegal Search', 'count': 1, 'sustained_count': 1 }] }] }, { 'name': 'complainant race', 'entries': [{ 'name': 'White', 'count': 1, 'sustained_count': 1, 'items': [{ 'year': 2000, 'name': 'White', 'count': 1, 'sustained_count': 1 }] }] }, { 'name': 'complainant age', 'entries': [{ 'name': '<20', 'count': 1, 'sustained_count': 1, 'items': [{ 'year': 2000, 'name': '<20', 'count': 1, 'sustained_count': 1 }] }] }, { 'name': 'complainant gender', 'entries': [{ 'name': 'Male', 'count': 1, 'sustained_count': 1, 'items': [{ 'year': 2000, 'name': 'Male', 'count': 1, 'sustained_count': 1 }] }] }] }, 'allegation_count': 1, 'complaint_percentile': Decimal('99.8'), 'honorable_mention_count': 1, 'honorable_mention_percentile': 98, 'has_visual_token': False, 'sustained_count': 1, 'discipline_count': 1, 'civilian_compliment_count': 1, 'trr_count': 1, 'major_award_count': 2, 'tags': ['Jason VanDyke'], 'to': '/officer/123/alex-mack/', 'url': 'http://test.com/officer/alex-mack/123', 'current_salary': 9000, 'unsustained_count': 0, 'coaccusals': [], 'current_allegation_percentile': None, 'percentiles': [], 'cr_incident_dates': ['2000-04-26'], 'trr_datetimes': ['2002-09-29'], 'internal_allegation_percentile': None, 'trr_percentile': None, 'civilian_allegation_percentile': None, })
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_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_gender_display(self): expect(ComplainantFactory(gender='M').gender_display).to.equal('Male') expect( ComplainantFactory(gender='F').gender_display).to.equal('Female') expect(ComplainantFactory(gender='X').gender_display).to.equal('X') expect(ComplainantFactory(gender='?').gender_display).to.equal('?')
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' } ] })
def test_query(self): trr_officer_1 = OfficerFactory() trr_officer_2 = OfficerFactory() pinboard_officer = OfficerFactory() other_officer = OfficerFactory() pinboard_allegation = AllegationFactory() allegation1 = AllegationFactory() allegation2 = AllegationFactory() allegation3 = AllegationFactory() allegation4 = AllegationFactory() other_allegation = AllegationFactory() OfficerAllegationFactory(allegation=pinboard_allegation, officer=other_officer) OfficerAllegationFactory(allegation=allegation1, officer=trr_officer_1) OfficerAllegationFactory(allegation=allegation2, officer=trr_officer_2) OfficerAllegationFactory(allegation=allegation3, officer=trr_officer_2) OfficerAllegationFactory(allegation=allegation4, officer=pinboard_officer) ComplainantFactory(allegation=pinboard_allegation, gender='M', race='White') ComplainantFactory(allegation=pinboard_allegation, gender='F', race='White') ComplainantFactory(allegation=pinboard_allegation, gender='F', race='White') ComplainantFactory(allegation=pinboard_allegation, gender='F', race='Black') ComplainantFactory(allegation=allegation1, gender='X', race='Black') ComplainantFactory(allegation=allegation1, gender='F', race='Black') ComplainantFactory(allegation=allegation1, gender='X', race='') ComplainantFactory(allegation=allegation1, gender='', race='Asian/Pacific') ComplainantFactory(allegation=allegation3, gender='F', race='Hispanic') ComplainantFactory(allegation=allegation4, gender='M', race='White') ComplainantFactory(allegation=other_allegation, gender='M', race='') ComplainantFactory(allegation=other_allegation, gender='F', race='Black') pinboard_trr1 = TRRFactory(officer=trr_officer_1) pinboard_trr2 = TRRFactory(officer=trr_officer_2) pinboard = PinboardFactory(trrs=(pinboard_trr1, pinboard_trr2), allegations=(pinboard_allegation, ), officers=(pinboard_officer, )) query_results = dict(ComplainantsSummaryQuery(pinboard).query()) expect(list(query_results['race'])).to.eq([{ 'race': 'Black', 'percentage': 0.3 }, { 'race': 'White', 'percentage': 0.4 }, { 'race': 'Hispanic', 'percentage': 0.1 }, { 'race': 'Other', 'percentage': 0.2 }]) expect(list(query_results['gender'])).to.eq([{ 'gender': 'M', 'percentage': 0.2 }, { 'gender': 'F', 'percentage': 0.5 }, { 'gender': 'Unknown', 'percentage': 0.3 }])
def test_complainants(self): allegation = AllegationFactory() ComplainantFactory(id=1, allegation=allegation) expect(allegation.complainants.count()).to.eq(1) expect(allegation.complainants[0].id).to.eq(1)
def test_summary(self): unit = PoliceUnitFactory(unit_name='123', description='foo') officer = OfficerFactory(race='White', gender='F', birth_year='1980') OfficerHistoryFactory(unit=unit, officer=officer, end_date=None) allegation = AllegationFactory() allegation_category = AllegationCategoryFactory( category='Use of Force') OfficerAllegationFactory(officer=officer, allegation=allegation, allegation_category=allegation_category, final_finding='SU') ComplainantFactory(allegation=allegation, race='Black', age=25, gender='M') self.refresh_index() response = self.client.get( reverse('api-v2:units-summary', kwargs={'pk': '123'})) expect(response.data).to.be.eq({ 'unit_name': '123', 'description': 'foo', 'member_records': { 'active_members': 1, 'total': 1, 'facets': [{ 'name': 'race', 'entries': [{ 'name': 'White', 'count': 1 }] }, { 'name': 'age', 'entries': [{ 'name': '31-40', 'count': 1 }] }, { 'name': 'gender', 'entries': [{ 'name': 'Female', 'count': 1 }] }] }, 'complaint_records': { 'count': 1, 'sustained_count': 1, 'facets': [{ 'name': 'category', 'entries': [{ 'name': 'Use of Force', 'count': 1, 'sustained_count': 1 }] }, { 'name': 'race', 'entries': [{ 'name': 'Black', 'count': 1, 'sustained_count': 1 }] }, { 'name': 'age', 'entries': [{ 'name': '21-30', 'count': 1, 'sustained_count': 1 }] }, { 'name': 'gender', 'entries': [{ 'name': 'Male', 'count': 1, 'sustained_count': 1 }] }] } })