Esempio n. 1
0
 def test_extract_datum_with_police_hq(self):
     police_district_area = AreaFactory(area_type='police_district', name='22nd')
     beat_area = AreaFactory(
         name='1',
         tags=['tag'],
         median_income=343,
         area_type='beat',
         police_hq=police_district_area)
     expect(
         AreaIndexer().extract_datum(beat_area)
     ).to.be.eq({
         'name': '1',
         'url': beat_area.v1_url,
         'area_type': 'beat',
         'tags': ['tag', 'beat'],
         'allegation_count': 0,
         'officers_most_complaint': [],
         'most_common_complaint': [],
         'race_count': [],
         'allegation_percentile': None,
         'median_income': 343,
         'commander': None,
         'alderman': None,
         'police_hq': '22nd'
     })
    def test_build_terms(self):
        class MyAreaTermBuilder(AreaTermBuilder):
            slug = 'my_area_type'
            query_key = 'my_query_key'

        AreaFactory(area_type='my_area_type', name='1st')
        AreaFactory(area_type='my_area_type', name='2nd')
        expect(MyAreaTermBuilder.build_terms()).to.eq([
            {
                'name': '1st',
                'link': 'http://cpdb.lvh.me/url-mediator/session-builder?my_query_key=1st'
            }, {
                'name': '2nd',
                'link': 'http://cpdb.lvh.me/url-mediator/session-builder?my_query_key=2nd'
            }
        ])
Esempio n. 3
0
    def test_extract_datum_police_district_has_no_description(self):
        area = AreaFactory(
            name='name',
            tags=['tag'],
            median_income=343,
            area_type='police-districts',
            alderman='IronMan',
        )

        expect(
            AreaIndexer().extract_datum(area)
        ).to.be.eq({
            'name': 'name',
            'url': area.v1_url,
            'area_type': 'police-district',
            'tags': ['tag', 'police district'],
            'allegation_count': 0,
            'officers_most_complaint': [],
            'most_common_complaint': [],
            'race_count': [],
            'median_income': 343,
            'alderman': 'IronMan',
            'commander': None,
            'allegation_percentile': None,
            'police_hq': None,
        })
Esempio n. 4
0
    def test_extract_datum_with_ward_name(self):
        area = AreaFactory(
            name='name',
            tags=['tag'],
            median_income=343,
            area_type='wards',
            alderman='IronMan',
            description='Other Name'
        )
        RacePopulationFactory(
            area=area,
            race='Asian',
            count=101
        )

        expect(
            AreaIndexer().extract_datum(area)
        ).to.be.eq({
            'name': 'name',
            'url': area.v1_url,
            'area_type': 'ward',
            'tags': ['tag', 'ward'],
            'allegation_count': 0,
            'officers_most_complaint': [],
            'most_common_complaint': [],
            'race_count': [{
                'race': 'Asian',
                'count': 101
            }],
            'median_income': 343,
            'alderman': 'IronMan',
            'commander': None,
            'allegation_percentile': None,
            'police_hq': None
        })
Esempio n. 5
0
    def test_get_beat(self):
        allegation = AllegationFactory(beat=None)
        result = CRSerializer(allegation).data
        expect(result).to.exclude('beat')

        allegation = AllegationFactory(beat=AreaFactory(name='23'))
        result = CRSerializer(allegation).data
        expect(result['beat']).to.eq('23')
 def test_get_community_discipline_count(self):
     area = AreaFactory(area_type=COMMUNITY_AREA_CHOICE)
     self.make_officer_allegation(5, area, incident_date=datetime(1988, 1, 1, tzinfo=pytz.utc), disciplined=True)
     self.make_officer_allegation(5, area, incident_date=datetime(2016, 7, 1, tzinfo=pytz.utc), disciplined=False)
     self.make_officer_allegation(2, area, incident_date=datetime(1987, 12, 31, tzinfo=pytz.utc), disciplined=False)
     self.make_officer_allegation(2, area, incident_date=datetime.now(pytz.utc), disciplined=True)
     result = json.loads(self.command.get_community_data())
     expect(result['features']).to.have.length(1)
     expect(result['features'][0]['properties']['allegation_count']).to.eq(12)
     expect(result['features'][0]['properties']['discipline_count']).to.eq(7)
    def test_fix_community_area_type(self):
        AreaFactory(area_type='Community', name='UPPER CASE')
        self.assertEqual(Area.objects.filter(area_type='Community').count(), 1)
        self.assertEqual(Area.objects.filter(area_type='community').count(), 0)

        call_command('fix_community_area_type')

        self.assertEqual(Area.objects.filter(area_type='Community').count(), 0)
        self.assertEqual(Area.objects.filter(area_type='community').count(), 1)
        self.assertEqual(Area.objects.first().name, 'Upper Case')
Esempio n. 8
0
    def test_get_queryset_with_police_district(self):
        area1 = AreaFactory(area_type='police-districts')
        RacePopulationFactory(race='White', count=1000, area=area1)
        AllegationFactory.create_batch(2, areas=[area1])

        area2 = AreaFactory(area_type='police-districts')
        RacePopulationFactory(race='Black', count=100, area=area2)
        AllegationFactory(areas=[area2])

        area3 = AreaFactory(area_type='community')
        RacePopulationFactory(race='Black', count=10, area=area3)
        AllegationFactory.create_batch(3, areas=[area3])

        area_indexer = AreaIndexer()
        expect(area_indexer.get_queryset().count()).to.eq(3)
        expect(area_indexer._percentiles).to.eq({
            area1.id: 0.0,
            area2.id: 50.0
        })
    def test_get_community_most_complaints_officers(self):
        area = AreaFactory(area_type=COMMUNITY_AREA_CHOICE)
        officer1 = OfficerFactory(id=12, first_name='John', last_name='Fenedy')
        officer2 = OfficerFactory(id=23, first_name='Jerome', last_name='Finnigan')
        officer3 = OfficerFactory(id=34, first_name='Raymond', last_name='Piwnicki')
        officer4 = OfficerFactory(id=45, first_name='Sean', last_name='Campbell')
        min_date = datetime(1988, 1, 1, tzinfo=pytz.utc)
        max_date = datetime(2016, 7, 1, tzinfo=pytz.utc)
        before_min_date = datetime(1987, 12, 31, tzinfo=pytz.utc)
        today = datetime.now(pytz.utc)

        self.make_officer_allegation(7, area=area, incident_date=min_date, officer=officer1)
        self.make_officer_allegation(6, area=area, incident_date=min_date, officer=officer2)
        self.make_officer_allegation(5, area=area, incident_date=min_date, officer=officer3)
        self.make_officer_allegation(4, area=area, incident_date=min_date, officer=officer4)
        self.make_officer_allegation(7, area=area, incident_date=max_date, officer=officer1)
        self.make_officer_allegation(6, area=area, incident_date=max_date, officer=officer2)
        self.make_officer_allegation(5, area=area, incident_date=max_date, officer=officer3)
        self.make_officer_allegation(4, area=area, incident_date=max_date, officer=officer4)

        self.make_officer_allegation(2, area=area, incident_date=before_min_date, officer=officer1)
        self.make_officer_allegation(2, area=area, incident_date=before_min_date, officer=officer2)
        self.make_officer_allegation(2, area=area, incident_date=before_min_date, officer=officer3)
        self.make_officer_allegation(2, area=area, incident_date=before_min_date, officer=officer4)
        self.make_officer_allegation(2, area=area, incident_date=today, officer=officer1)
        self.make_officer_allegation(2, area=area, incident_date=today, officer=officer2)
        self.make_officer_allegation(2, area=area, incident_date=today, officer=officer3)
        self.make_officer_allegation(2, area=area, incident_date=today, officer=officer4)

        result = json.loads(self.command.get_community_data())
        expect(result['features']).to.have.length(1)
        expect(result['features'][0]['properties']['most_complaints_officers']).to.eq([
            {
                'full_name': 'John Fenedy',
                'complaints_count': 16,
                'id': 12
            },
            {
                'full_name': 'Jerome Finnigan',
                'complaints_count': 14,
                'id': 23
            },
            {
                'full_name': 'Raymond Piwnicki',
                'complaints_count': 12,
                'id': 34
            }
        ])
 def test_get_community_data(self):
     area = AreaFactory(
         area_type=COMMUNITY_AREA_CHOICE,
         name='Hyde Park',
         id=123,
         median_income='$60,400',
         polygon=MultiPolygon(Polygon((
             (87.940101, 42.023135),
             (87.523661, 42.023135),
             (87.523661, 41.644286),
             (87.940101, 41.644286),
             (87.940101, 42.023135))))
     )
     RacePopulationFactory(area=area, race='White', count=1000)
     RacePopulationFactory(area=area, race='Black', count=500)
     expect(self.command.get_community_data()).to.eq(json.dumps({
         'type': 'FeatureCollection',
         'features': [{
             'type': 'Feature',
             'properties': {
                 'id': 123,
                 'name': 'Hyde Park',
                 'allegation_count': 0,
                 'discipline_count': 0,
                 'most_complaints_officers': [],
                 'population': 1500,
                 'median_income': '$60,400',
                 'race_count': [{
                     'race': 'White',
                     'count': 1000
                 }, {
                     'race': 'Black',
                     'count': 500
                 }]
             },
             'geometry': {
                 'type': 'MultiPolygon',
                 'coordinates': [[[
                     [87.940101, 42.023135],
                     [87.523661, 42.023135],
                     [87.523661, 41.644286],
                     [87.940101, 41.644286],
                     [87.940101, 42.023135]
                 ]]]
             }
         }]
     }))
Esempio n. 11
0
    def test_extract_datum(self):
        commander = OfficerFactory(first_name='Captain', last_name='America')
        area = AreaFactory(
            name='name',
            tags=['tag'],
            median_income=343,
            area_type='police-districts',
            commander=commander,
            description='Other Name'
        )
        RacePopulationFactory(
            area=area,
            race='Asian',
            count=101
        )
        area_indexer = AreaIndexer()
        area_indexer._percentiles = {area.id: 0}

        expect(
            area_indexer.extract_datum(area)
        ).to.be.eq({
            'name': 'Other Name',
            'url': area.v1_url,
            'area_type': 'police-district',
            'tags': ['tag', 'police district'],
            'allegation_count': 0,
            'officers_most_complaint': [],
            'most_common_complaint': [],
            'race_count': [{
                'race': 'Asian',
                'count': 101
            }],
            'allegation_percentile': 0,
            'median_income': 343,
            'commander': {
                'id': commander.id,
                'full_name': 'Captain America',
                'allegation_count': 0,
            },
            'alderman': None,
            'police_hq': None
        })
Esempio n. 12
0
    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',
            }]
        })
Esempio n. 13
0
    def test_extract_datum_with_officers_most_complaint(self):
        area = AreaFactory(
            name='name',
            tags=['tag'],
            median_income=343,
            area_type='police-districts',
            alderman='IronMan',
        )
        area.get_officers_most_complaints = Mock(return_value=[
            OfficerFactory.build(
                id=123,
                first_name='A',
                last_name='B',
                allegation_count=5,
                civilian_allegation_percentile=0,
                internal_allegation_percentile=0,
                trr_percentile=0,
                complaint_percentile=0
            ),
            OfficerFactory.build(
                id=456,
                first_name='E',
                last_name='F',
                allegation_count=3,
                civilian_allegation_percentile=Decimal(33.3333),
                internal_allegation_percentile=0,
                trr_percentile=Decimal(33.3333),
                complaint_percentile=Decimal(33.3333)
            ),
            OfficerFactory.build(
                id=999,
                first_name='X',
                last_name='Y',
                allegation_count=2,
                complaint_percentile=None
            )
        ])
        area_indexer = AreaIndexer()

        expect(area_indexer.extract_datum(area)).to.be.eq({
            'name': 'name',
            'url': area.v1_url,
            'area_type': 'police-district',
            'tags': ['tag', 'police district'],
            'allegation_count': 0,
            'most_common_complaint': [],
            'race_count': [],
            'median_income': 343,
            'alderman': 'IronMan',
            'commander': None,
            'allegation_percentile': None,
            'police_hq': None,
            'officers_most_complaint': [
                {
                    'id': 123,
                    'name': 'A B',
                    'count': 5,
                    'percentile_allegation_civilian': '0.0000',
                    'percentile_allegation_internal': '0.0000',
                    'percentile_trr': '0.0000',
                    'percentile_allegation': '0.0000',
                }, {
                    'id': 456,
                    'name': 'E F',
                    'count': 3,
                    'percentile_allegation_civilian': '33.3333',
                    'percentile_allegation_internal': '0.0000',
                    'percentile_trr': '33.3333',
                    'percentile_allegation': '33.3333',
                }, {
                    'id': 999,
                    'name': 'X Y',
                    'count': 2
                }
            ],
        })
Esempio n. 14
0
 def test_get_queryset(self):
     area_indexer = AreaIndexer()
     expect(area_indexer.get_queryset().count()).to.eq(0)
     AreaFactory()
     expect(area_indexer.get_queryset().count()).to.eq(1)
     expect(area_indexer._percentiles).to.have.length(0)
Esempio n. 15
0
    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'
        ])
Esempio n. 16
0
    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'
                }
            ]
        })