def test_extract_datum_most_common_category(self): allegation = AllegationFactory() cat1 = AllegationCategoryFactory( category='Use Of Forces', allegation_name='Sub Force' ) cat2 = AllegationCategoryFactory( category='Traffic', allegation_name='Sub traffic' ) OfficerAllegationFactory.create_batch( 2, allegation=allegation, allegation_category=cat1 ) OfficerAllegationFactory( allegation=allegation, allegation_category=cat2 ) rows = self.extract_data() expect(rows).to.have.length(1) expect(rows[0]['most_common_category']).to.eq({ 'category': 'Use Of Forces', 'allegation_name': 'Sub Force' })
def test_data(self): officer_1 = OfficerFactory(id=1) officer_2 = OfficerFactory(id=2) officer_3 = OfficerFactory(id=3) officer_4 = OfficerFactory(id=4) officers = [officer_1, officer_2, officer_3, officer_4] allegation_1 = AllegationFactory(crid='123') allegation_2 = AllegationFactory(crid='456') allegation_3 = AllegationFactory(crid='789') AllegationFactory(crid='987') OfficerAllegationFactory( officer=officer_1, allegation=allegation_1 ) OfficerAllegationFactory( officer=officer_1, allegation=allegation_2 ) OfficerAllegationFactory( officer=officer_2, allegation=allegation_2 ) expected_data = [allegation_1.crid, allegation_2.crid, allegation_3.crid] results = [item.crid for item in list(GeographyCrsDataQuery([allegation_3.crid], officers).data())] expect(results).to.eq(expected_data)
def test_sustained_count(self): unit = PoliceUnitFactory() officer = OfficerFactory() OfficerHistoryFactory(unit=unit, officer=officer) OfficerAllegationFactory(officer=officer, final_finding='SU') OfficerAllegationFactory(officer=officer, final_finding='UN') expect(unit.sustained_count).to.eq(1)
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_relevant_complaints_via_accused_officers(self): pinned_officer_1 = OfficerFactory(id=1) pinned_officer_2 = OfficerFactory(id=2) pinned_officer_3 = OfficerFactory(id=3) relevant_allegation_1 = AllegationFactory(crid='1', incident_date=datetime( 2002, 2, 21, tzinfo=pytz.utc)) relevant_allegation_2 = AllegationFactory(crid='2', incident_date=datetime( 2002, 2, 22, tzinfo=pytz.utc)) AllegationFactory(crid='not relevant') pinboard = PinboardFactory( title='Test pinboard', description='Test description', ) pinboard.officers.set( [pinned_officer_1, pinned_officer_2, pinned_officer_3]) OfficerAllegationFactory(officer=pinned_officer_1, allegation=relevant_allegation_1) OfficerAllegationFactory(officer=pinned_officer_2, allegation=relevant_allegation_2) relevant_complaints = list(pinboard.relevant_complaints) expect(relevant_complaints).to.have.length(2) expect(relevant_complaints[0].crid).to.eq('2') expect(relevant_complaints[1].crid).to.eq('1')
def test_search(self): officer_1 = OfficerFactory(id=1, first_name='Jerome', last_name='Finnigan') officer_2 = OfficerFactory(id=2, first_name='Edward', last_name='May') officer_3 = OfficerFactory(id=3) officer_4 = OfficerFactory(id=4) allegation_1 = AllegationFactory( incident_date=datetime(2004, 10, 10, tzinfo=pytz.utc)) allegation_2 = AllegationFactory( incident_date=datetime(2009, 10, 6, tzinfo=pytz.utc)) OfficerAllegationFactory(officer=officer_1, allegation=allegation_1) OfficerAllegationFactory(officer=officer_3, allegation=allegation_2) TRRFactory(trr_datetime=datetime(2004, 10, 10, tzinfo=pytz.utc), officer=officer_2) TRRFactory(trr_datetime=datetime(2010, 5, 7, tzinfo=pytz.utc), officer=officer_4) self.rebuild_index() self.refresh_index() response = DateOfficerWorker().search('', dates=['2004-10-10']) expect({record.id for record in response.hits}).to.eq({1, 2})
def test_retrieve_single_search_date_officers_result(self): officer_1 = OfficerFactory(id=1, first_name='Jerome', last_name='Finnigan') officer_2 = OfficerFactory(id=2, first_name='Edward', last_name='May') officer_3 = OfficerFactory(id=3) officer_4 = OfficerFactory(id=4) allegation_1 = AllegationFactory( incident_date=datetime(2004, 10, 10, tzinfo=pytz.utc)) allegation_2 = AllegationFactory( incident_date=datetime(2009, 10, 6, tzinfo=pytz.utc)) OfficerAllegationFactory(officer=officer_1, allegation=allegation_1) OfficerAllegationFactory(officer=officer_3, allegation=allegation_2) TRRFactory(trr_datetime=datetime(2004, 10, 10, tzinfo=pytz.utc), officer=officer_2) TRRFactory(trr_datetime=datetime(2010, 5, 7, tzinfo=pytz.utc), officer=officer_4) self.rebuild_index() self.refresh_index() url = reverse('api:suggestion-single') response = self.client.get(url, { 'term': '10-10-2004', 'contentType': 'DATE > OFFICERS' }) results = response.data['results'] expect({record['id'] for record in results}).to.eq({'1', '2'})
def test_compute_allegation_metric(self): officer = OfficerFactory(id=1, appointed_date=date(2010, 3, 14)) OfficerAllegationFactory( officer=officer, allegation__incident_date=datetime(2014, 12, 31, tzinfo=pytz.utc), ) OfficerAllegationFactory.create_batch( 3, officer=officer, allegation__incident_date=datetime(2016, 1, 16, tzinfo=pytz.utc), ) OfficerAllegationFactory( officer=officer, allegation__incident_date=datetime(2016, 7, 2, tzinfo=pytz.utc), ) officers = officer_percentile._compute_metric( 2016, PERCENTILE_ALLEGATION_GROUP) expect(officers).to.have.length(1) validate_object( officers[0], { 'officer_id': 1, 'year': 2016, 'start_date': date(2015, 1, 1), 'end_date': date(2016, 7, 1), 'service_year': 1.4986, 'num_allegation': 3, 'metric_allegation': 2.0019, })
def test_category(self): officer_allegation = OfficerAllegationFactory(allegation_category=None) expect(officer_allegation.category).to.eq(None) allegation_category = AllegationCategoryFactory(category='category') officer_allegation = OfficerAllegationFactory( allegation_category=allegation_category) expect(officer_allegation.category).to.eq('category')
def test_subcategory(self): officer_allegation = OfficerAllegationFactory(allegation_category=None) expect(officer_allegation.subcategory).to.eq(None) allegation_category = AllegationCategoryFactory( allegation_name='subcategory') officer_allegation = OfficerAllegationFactory( allegation_category=allegation_category) expect(officer_allegation.subcategory).to.eq('subcategory')
def test_relevant_documents_via_accused_officers(self): pinned_officer_1 = OfficerFactory(id=1) pinned_officer_2 = OfficerFactory(id=2) pinned_officer_3 = OfficerFactory(id=3) relevant_allegation_1 = AllegationFactory(crid='1', incident_date=datetime( 2002, 2, 21, tzinfo=pytz.utc)) relevant_allegation_2 = AllegationFactory(crid='2', incident_date=datetime( 2002, 2, 22, tzinfo=pytz.utc)) not_relevant_allegation = AllegationFactory(crid='not relevant') relevant_document_1 = AttachmentFileFactory( id=1, file_type='document', allegation=relevant_allegation_1, show=True) relevant_document_2 = AttachmentFileFactory( id=2, file_type='document', allegation=relevant_allegation_2, show=True) AttachmentFileFactory(id=998, file_type='document', title='relevant but not show', allegation=relevant_allegation_1, show=False) AttachmentFileFactory(id=999, file_type='document', title='not relevant', allegation=not_relevant_allegation, show=True) pinboard = PinboardFactory( title='Test pinboard', description='Test description', ) pinboard.officers.set( [pinned_officer_1, pinned_officer_2, pinned_officer_3]) OfficerAllegationFactory(officer=pinned_officer_1, allegation=relevant_allegation_1) OfficerAllegationFactory(officer=pinned_officer_2, allegation=relevant_allegation_2) relevant_documents = list(pinboard.relevant_documents) expect(relevant_documents).to.have.length(2) expect(relevant_documents[0].id).to.eq(relevant_document_2.id) expect(relevant_documents[0].allegation.crid).to.eq('2') expect(relevant_documents[1].id).to.eq(relevant_document_1.id) expect(relevant_documents[1].allegation.crid).to.eq('1')
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_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_coaccused_counts(self): officer = OfficerFactory() OfficerAllegationFactory.create_batch(2, officer=officer, final_finding='SU') OfficerAllegationFactory(officer=officer, final_finding='NS') rows = self.extract_data() expect(rows).to.have.length(3) for row in rows: expect(row['coaccused']).to.have.length(1) expect(row['coaccused'][0]['allegation_count']).to.eq(3) expect(row['coaccused'][0]['sustained_count']).to.eq(2)
def test_get_category_names(self): allegation = AllegationFactory() category1 = AllegationCategoryFactory(category='Use of Force') category2 = AllegationCategoryFactory(category='Illegal Search') OfficerAllegationFactory(allegation=allegation, allegation_category=category1) OfficerAllegationFactory(allegation=allegation, allegation_category=category2) expect(allegation.category_names).to.eq(['Illegal Search', 'Use of Force']) OfficerAllegationFactory(allegation=allegation, allegation_category=None) expect(allegation.category_names).to.eq(['Illegal Search', 'Unknown', 'Use of Force'])
def test_allegation_count(self): officer_1 = OfficerFactory() officer_2 = OfficerFactory() OfficerAllegationFactory.create_batch(2, final_finding='NS', officer=officer_1) OfficerAllegationFactory(final_finding='SU', officer=officer_1) officer_cache_manager.build_cached_columns() officer_1.refresh_from_db() officer_2.refresh_from_db() expect(officer_1.allegation_count).to.eq(3) expect(officer_2.allegation_count).to.eq(0)
def test_complaint_count_with_duplicated_allegation(self): unit = PoliceUnitFactory() officer1 = OfficerFactory() officer2 = OfficerFactory() OfficerHistoryFactory(unit=unit, officer=officer1) OfficerHistoryFactory(unit=unit, officer=officer2) allegation = AllegationFactory() OfficerAllegationFactory(officer=officer1, allegation=allegation) OfficerAllegationFactory(officer=officer2, allegation=allegation) expect(unit.complaint_count).to.eq(1)
def test_coaccusals_with_alias(self): officer = OfficerFactory(id=456) OfficerAliasFactory(old_officer_id=123, new_officer=officer) allegation = AllegationFactory() coaccused = OfficerFactory(id=333) OfficerAllegationFactory(officer=officer, allegation=allegation) OfficerAllegationFactory(officer=coaccused, allegation=allegation) response = self.client.get(reverse('api-v2:officers-coaccusals', kwargs={'pk': 123})) expect(response.status_code).to.eq(status.HTTP_200_OK) expect(response.data[0]['id']).to.eq(333)
def test_new_timeline_item_no_join(self): officer = OfficerFactory(id=123, appointed_date=None, rank='Police Officer') unit = PoliceUnitFactory(unit_name='001', description='unit_001') OfficerHistoryFactory(officer=officer, unit=unit, effective_date=date(2010, 1, 1), end_date=date(2011, 12, 31)) allegation = AllegationFactory( crid='123456', coaccused_count=4, incident_date=datetime(2011, 8, 23, tzinfo=pytz.utc) ) OfficerAllegationFactory( final_finding='UN', final_outcome='Unknown', officer=officer, allegation=allegation, allegation_category=AllegationCategoryFactory(category='category', allegation_name='sub category') ) OfficerAllegationFactory.create_batch(3, allegation=allegation) SalaryFactory(officer=officer, year=2001, rank='Police Officer', spp_date=date(2001, 9, 23)) cache_managers.cache_all() response = self.client.get(reverse('api-v2:officers-new-timeline-items', kwargs={'pk': 123})) expect(response.status_code).to.eq(status.HTTP_200_OK) expect(response.data).to.eq([ { 'date': '2011-08-23', 'kind': 'CR', 'crid': '123456', 'category': 'category', 'subcategory': 'sub category', 'finding': 'Unfounded', 'outcome': 'Unknown', 'coaccused': 4, 'unit_name': '001', 'unit_description': 'unit_001', 'rank': 'Police Officer', 'victims': [], 'attachments': [], }, { 'date': '2010-01-01', 'kind': 'UNIT_CHANGE', 'unit_name': '001', 'unit_description': 'unit_001', 'rank': 'Police Officer', }, { 'date': '2001-09-23', 'kind': 'RANK_CHANGE', 'unit_name': '', 'unit_description': '', 'rank': 'Police Officer', } ])
def test_sustained_count_with_duplicated_allegation(self): unit = PoliceUnitFactory() officer1 = OfficerFactory() officer2 = OfficerFactory() OfficerHistoryFactory(unit=unit, officer=officer1) OfficerHistoryFactory(unit=unit, officer=officer2) allegation = AllegationFactory() OfficerAllegationFactory(officer=officer1, allegation=allegation, final_finding='SU') OfficerAllegationFactory(officer=officer2, allegation=allegation, final_finding='SU') expect(unit.sustained_count).to.eq(1)
def test_discipline_count(self): officer_1 = OfficerFactory() officer_2 = OfficerFactory() OfficerAllegationFactory.create_batch(2, officer=officer_1, disciplined=True) OfficerAllegationFactory(officer=officer_1, disciplined=False) OfficerAllegationFactory(officer=officer_2, disciplined=False) officer_cache_manager.build_cached_columns() officer_1.refresh_from_db() officer_2.refresh_from_db() expect(officer_1.discipline_count).to.eq(2) expect(officer_2.discipline_count).to.eq(0)
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_relevant_complaints_order_officers(self): pinned_officer_1 = OfficerFactory(id=1, allegation_count=3) pinned_officer_2 = OfficerFactory(id=2) pinned_officer_3 = OfficerFactory(id=3) officer_4 = OfficerFactory(id=4, allegation_count=2) officer_5 = OfficerFactory(id=5, allegation_count=4) relevant_allegation_1 = AllegationFactory(crid='1', incident_date=datetime( 2002, 2, 21, tzinfo=pytz.utc)) relevant_allegation_2 = AllegationFactory(crid='2', incident_date=datetime( 2002, 2, 22, tzinfo=pytz.utc)) AllegationFactory(crid='not relevant') pinboard = PinboardFactory( title='Test pinboard', description='Test description', ) pinboard.officers.set( [pinned_officer_1, pinned_officer_2, pinned_officer_3]) OfficerAllegationFactory(officer=pinned_officer_1, allegation=relevant_allegation_1) OfficerAllegationFactory(officer=officer_4, allegation=relevant_allegation_1) OfficerAllegationFactory(officer=officer_5, allegation=relevant_allegation_1) OfficerAllegationFactory(officer=pinned_officer_2, allegation=relevant_allegation_2) relevant_complaints = list(pinboard.relevant_complaints) expect(relevant_complaints).to.have.length(2) expect(relevant_complaints[0].crid).to.eq('2') expect(relevant_complaints[0].prefetched_officer_allegations ).to.have.length(1) expect(relevant_complaints[0].prefetched_officer_allegations[0]. officer.id).to.eq(2) expect(relevant_complaints[1].crid).to.eq('1') expect(relevant_complaints[1].prefetched_officer_allegations ).to.have.length(3) expect(relevant_complaints[1].prefetched_officer_allegations[0]. officer.id).to.eq(5) expect(relevant_complaints[1].prefetched_officer_allegations[1]. officer.id).to.eq(1) expect(relevant_complaints[1].prefetched_officer_allegations[2]. officer.id).to.eq(4)
def test_query(self): allegation_officer1 = OfficerFactory() allegation_officer2 = OfficerFactory() trr_officer_1 = OfficerFactory() trr_officer_2 = OfficerFactory() pinboard_officer1 = OfficerFactory() pinboard_officer2 = OfficerFactory() other_officer = OfficerFactory() pinboard_allegation = AllegationFactory() OfficerAllegationFactory(allegation=pinboard_allegation, officer=allegation_officer1) OfficerAllegationFactory(allegation=pinboard_allegation, officer=allegation_officer2) pinboard_trr1 = TRRFactory(officer=trr_officer_1) pinboard_trr2 = TRRFactory(officer=trr_officer_2) trr1 = TRRFactory(officer=allegation_officer1) trr2 = TRRFactory(officer=allegation_officer2) trr3 = TRRFactory(officer=allegation_officer2) trr4 = TRRFactory(officer=allegation_officer2) trr5 = TRRFactory(officer=pinboard_officer1) TRRFactory(officer=pinboard_officer2) other_trr1 = TRRFactory(officer=other_officer) other_trr2 = TRRFactory(officer=other_officer) ActionResponseFactory(trr=pinboard_trr1, force_type=None) ActionResponseFactory(trr=pinboard_trr2, force_type='Verbal Commands') ActionResponseFactory(trr=trr1, force_type='Physical Force - Stunning') ActionResponseFactory(trr=trr1, force_type=None) ActionResponseFactory(trr=trr2, force_type='Physical Force - Stunning') ActionResponseFactory(trr=trr3, force_type='Verbal Commands') ActionResponseFactory(trr=trr4, force_type='Physical Force - Stunning') ActionResponseFactory(trr=trr5, force_type='Physical Force - Stunning') ActionResponseFactory(trr=other_trr1, force_type='Taser') ActionResponseFactory(trr=other_trr2, force_type='Chemical') pinboard = PinboardFactory(trrs=(pinboard_trr1, pinboard_trr2), allegations=(pinboard_allegation, ), officers=(pinboard_officer1, pinboard_officer2)) expect(list(TrrSummaryQuery(pinboard).query())).to.eq([{ 'force_type': 'Physical Force - Stunning', 'count': 4 }, { 'force_type': 'Verbal Commands', 'count': 2 }, { 'force_type': None, 'count': 2 }])
def test_upload_cr_attachment_request_to_foia_with_cpd_after_2006_has_badge_number( self, airtable_mock): airtable_mock.insert.return_value = {'id': 'some_airtable_record_id'} allegation = AllegationFactory(crid='123456', incident_date=datetime(2007, 12, 31, tzinfo=pytz.utc)) attachment_request = AttachmentRequestFactory( allegation=allegation, email='*****@*****.**') officer_1 = OfficerFactory(id=1, first_name='Marry', last_name='Jane') officer_2 = OfficerFactory(id=2, first_name='John', last_name='Henry') OfficerBadgeNumberFactory(officer=officer_1, star='12345') OfficerBadgeNumberFactory(officer=officer_2, star='56789') investigator_1 = InvestigatorFactory(officer=officer_1) investigator_2 = InvestigatorFactory(officer=officer_1) InvestigatorAllegationFactory(allegation=allegation, current_star=None, investigator=investigator_1) InvestigatorAllegationFactory(allegation=allegation, current_star=None, investigator=investigator_2) OfficerAllegationFactory(allegation=allegation, officer=officer_1) OfficerAllegationFactory(allegation=allegation, officer=officer_2) expected_airtable_data = { 'Explanation': 'Officers: John Henry(ID 2), Marry Jane(ID 1)', 'Project': ['CPDP'], 'Agency': ['CPD_AGENCY_ID'], 'Requested For': 'CR 123456', 'Requestor': [{ 'id': 'usrGiZFcyZ6wHTYWd', 'email': '*****@*****.**', 'name': 'Rajiv Sinclair' }], 'Date requested by user': attachment_request.created_at.strftime('%Y-%m-%d'), 'Requester Email': '*****@*****.**' } CRRequestAirTableUploader.upload() attachment_request.refresh_from_db() airtable_mock.insert.assert_called_with(expected_airtable_data) expect( attachment_request.airtable_id).to.be.eq('some_airtable_record_id')
def test_query(self): allegation_officer1 = OfficerFactory(race='White', gender='F') allegation_officer2 = OfficerFactory(race='Hispanic', gender='M') trr_officer_1 = OfficerFactory(race='White', gender='M') trr_officer_2 = OfficerFactory(race='', gender='M') pinboard_officer1 = OfficerFactory(race='White', gender='M') pinboard_officer2 = OfficerFactory(race='Black', gender='') pinboard_officer3 = OfficerFactory(race='Asian/Pacific', gender='X') OfficerFactory(race='White', gender='') OfficerFactory(race='Black', gender='') pinboard_allegation = AllegationFactory() OfficerAllegationFactory(allegation=pinboard_allegation, officer=allegation_officer1) OfficerAllegationFactory(allegation=pinboard_allegation, officer=allegation_officer2) 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_officer1, pinboard_officer2, pinboard_officer3)) query_results = dict(OfficersSummaryQuery(pinboard).query()) expect(list(query_results['race'])).to.eq([{ 'race': 'Black', 'percentage': 0.14 }, { 'race': 'White', 'percentage': 0.43 }, { 'race': 'Hispanic', 'percentage': 0.14 }, { 'race': 'Other', 'percentage': 0.29 }]) expect(list(query_results['gender'])).to.eq([{ 'gender': 'M', 'percentage': 0.57 }, { 'gender': 'F', 'percentage': 0.14 }, { 'gender': 'Unknown', 'percentage': 0.29 }])
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_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_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', }] })