def test_victims(self):
        allegation = AllegationFactory()
        victim1 = VictimFactory(allegation=allegation)
        victim2 = VictimFactory(allegation=allegation)

        officer_allegation = OfficerAllegationFactory(allegation=allegation)
        expect(list(officer_allegation.victims)).to.eq([victim1, victim2])
 def test_serialization(self):
     victim = VictimFactory(race='Black', gender='M', age=53)
     expect(VictimSerializer(victim).data).to.eq({
         'race': 'Black',
         'gender': 'Male',
         'age': 53,
     })
示例#3
0
    def test_serialization(self):
        pinned_officer = OfficerFactory(
            id=1,
            rank='Police Officer',
            first_name='Jerome',
            last_name='Finnigan',
            trr_percentile='11.11',
            complaint_percentile='22.22',
            civilian_allegation_percentile='33.33',
            internal_allegation_percentile='44.44',
            allegation_count=2,
        )

        relevant_allegation = AllegationFactory(
            crid='1',
            incident_date=datetime(2002, 2, 21, tzinfo=pytz.utc),
            most_common_category=AllegationCategoryFactory(
                category='Operation/Personnel Violations',
                allegation_name='Subcategory'),
            point=Point([0.01, 0.02]))
        VictimFactory(gender='M',
                      race='Black',
                      age=35,
                      allegation=relevant_allegation)
        pinboard = PinboardFactory(
            id='66ef1560',
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set([pinned_officer])
        OfficerAllegationFactory(officer=pinned_officer,
                                 allegation=relevant_allegation)

        expect(pinboard.relevant_complaints.count()).to.eq(1)
        expect(
            AllegationMobileSerializer(
                pinboard.relevant_complaints.first()).data).to.eq({
                    'crid':
                    '1',
                    'category':
                    'Operation/Personnel Violations',
                    'incident_date':
                    '2002-02-21',
                    'officers': [{
                        'id': 1,
                        'rank': 'Police Officer',
                        'full_name': 'Jerome Finnigan',
                        'percentile_trr': '11.1100',
                        'percentile_allegation': '22.2200',
                        'percentile_allegation_civilian': '33.3300',
                        'percentile_allegation_internal': '44.4400',
                    }],
                    'point': {
                        'lon': 0.01,
                        'lat': 0.02
                    },
                })
示例#4
0
    def test_serialization(self):
        category = AllegationCategoryFactory(category='Use of Force', allegation_name='Subcategory')
        allegation = AllegationFactory(
            crid=123,
            old_complaint_address='16XX N TALMAN AVE, CHICAGO IL',
            most_common_category=category,
            incident_date=datetime(2002, 1, 1, tzinfo=pytz.utc),
            coaccused_count=12,
            point=Point(-35.5, 68.9),
        )
        VictimFactory(
            gender='M',
            race='Black',
            age=35,
            allegation=allegation
        )

        expect(AllegationSerializer(allegation).data).to.eq({
            'crid': '123',
            'address': '16XX N TALMAN AVE, CHICAGO IL',
            'category': 'Use of Force',
            'incident_date': '2002-01-01',
            'victims': [
                {
                    'gender': 'Male',
                    'race': 'Black',
                    'age': 35
                }
            ],
            'point': {
                'lon': -35.5,
                'lat': 68.9
            },
            'to': '/complaint/123/',
            'sub_category': 'Subcategory',
        })
示例#5
0
    def test_serialization(self):
        category = AllegationCategoryFactory(
            category='Use of Force',
            allegation_name='Improper Search Of Person')
        allegation = AllegationFactory(
            crid='123',
            is_officer_complaint=True,
            incident_date=datetime(2005, 12, 31, tzinfo=pytz.utc),
            most_common_category=category,
            old_complaint_address='34XX Douglas Blvd',
        )
        attachment = AttachmentFileFactory(tag='TRR',
                                           allegation=allegation,
                                           title='CR document',
                                           id='123456',
                                           url='http://cr-document.com/',
                                           file_type=MEDIA_TYPE_DOCUMENT)
        officer = OfficerFactory(id=8562,
                                 first_name='Jerome',
                                 last_name='Finnigan',
                                 allegation_count=5,
                                 trr_percentile=80,
                                 complaint_percentile=85,
                                 civilian_allegation_percentile=90,
                                 internal_allegation_percentile=95)
        officer_allegation = OfficerAllegationFactory(
            id=1,
            officer=officer,
            allegation=allegation,
            recc_outcome='10 Day Suspension',
            final_finding='SU',
            final_outcome='Separation',
            disciplined=True,
            allegation_category=category)
        VictimFactory(gender='M', race='Black', age=35, allegation=allegation)

        setattr(allegation, 'prefetch_filtered_attachment_files', [attachment])
        allegation.officerallegation_set.set([officer_allegation])

        expect(SocialGraphCRDetailSerializer(allegation).data).to.eq({
            'kind':
            'CR',
            'crid':
            '123',
            'to':
            '/complaint/123/',
            'category':
            'Use of Force',
            'subcategory':
            'Improper Search Of Person',
            'incident_date':
            '2005-12-31',
            'address':
            '34XX Douglas Blvd',
            'victims': [{
                'gender': 'Male',
                'race': 'Black',
                'age': 35
            }],
            'coaccused': [{
                'id': 8562,
                'full_name': 'Jerome Finnigan',
                'allegation_count': 5,
                'percentile_allegation': '85.0000',
                'percentile_allegation_civilian': '90.0000',
                'percentile_allegation_internal': '95.0000',
                'percentile_trr': '80.0000',
            }],
            'attachments': [{
                'id': '123456',
                'title': 'CR document',
                'url': 'http://cr-document.com/',
                'file_type': MEDIA_TYPE_DOCUMENT,
            }],
            'officer_ids': [8562],
        })
示例#6
0
    def test_new_timeline_item(self):
        officer = OfficerFactory(id=123, appointed_date=date(2000, 1, 1), rank='Police Officer')

        unit1 = PoliceUnitFactory(unit_name='001', description='unit_001')
        unit2 = PoliceUnitFactory(unit_name='002', description='unit_002')
        OfficerHistoryFactory(officer=officer, unit=unit1, effective_date=date(2010, 1, 1), end_date=date(2011, 12, 31))
        OfficerHistoryFactory(officer=officer, unit=unit2, effective_date=date(2012, 1, 1), end_date=None)

        AwardFactory(officer=officer, start_date=date(2011, 3, 23), award_type='Honorable Mention')
        AwardFactory(officer=officer, start_date=date(2015, 3, 23), award_type='Complimentary Letter')
        AwardFactory(officer=officer, start_date=date(2011, 3, 23), award_type='Life Saving Award')
        allegation = AllegationFactory(
            crid='123456',
            coaccused_count=4,
            incident_date=datetime(2011, 8, 23, tzinfo=pytz.utc)
        )
        VictimFactory(allegation=allegation, gender='M', race='White', age=34)
        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)

        allegation2 = AllegationFactory(
            crid='654321',
            point=Point(35.5, 68.9),
            coaccused_count=1,
            incident_date=datetime(2015, 8, 23, tzinfo=pytz.utc)
        )
        OfficerAllegationFactory(
            final_finding='UN', final_outcome='9 Day Suspension',
            officer=officer, allegation=allegation2,
            allegation_category=AllegationCategoryFactory(category='Use of Force', allegation_name='sub category')
        )

        trr2011 = TRRFactory(
            officer=officer,
            trr_datetime=datetime(2011, 9, 23, tzinfo=pytz.utc),
            taser=True,
            firearm_used=False
        )
        trr2015 = TRRFactory(
            officer=officer,
            trr_datetime=datetime(2015, 9, 23, tzinfo=pytz.utc),
            taser=False,
            firearm_used=False
        )
        SalaryFactory(officer=officer, year=2001, rank='Police Officer', spp_date=date(2001, 9, 23))
        SalaryFactory(officer=officer, year=2000, rank='Junior Police Officer', spp_date=date(2000, 1, 1))

        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([
            {
                'trr_id': trr2015.id,
                'date': '2015-09-23',
                'kind': 'FORCE',
                'taser': False,
                'firearm_used': False,
                'unit_name': '002',
                'unit_description': 'unit_002',
                'rank': 'Police Officer',
            }, {
                'date': '2015-08-23',
                'kind': 'CR',
                'crid': '654321',
                'category': 'Use of Force',
                'subcategory': 'sub category',
                'finding': 'Unfounded',
                'outcome': '9 Day Suspension',
                'coaccused': 1,
                'unit_name': '002',
                'unit_description': 'unit_002',
                'rank': 'Police Officer',
                'point': {
                    'lon': 35.5,
                    'lat': 68.9
                },
                'victims': [],
                'attachments': []
            }, {
                'date': '2012-01-01',
                'kind': 'UNIT_CHANGE',
                'unit_name': '002',
                'unit_description': 'unit_002',
                'rank': 'Police Officer',
            }, {
                'trr_id': trr2011.id,
                'date': '2011-09-23',
                'kind': 'FORCE',
                'taser': True,
                'firearm_used': False,
                'unit_name': '001',
                'unit_description': 'unit_001',
                'rank': 'Police Officer',
            }, {
                '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': [
                    {
                        'race': 'White',
                        'age': 34,
                        'gender': 'Male',
                    }
                ],
                'attachments': [],
            }, {
                'date': '2011-03-23',
                'kind': 'AWARD',
                'award_type': 'Life Saving Award',
                'unit_name': '001',
                'unit_description': 'unit_001',
                'rank': 'Police Officer',
            }, {
                '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',
            }, {
                'date': '2000-01-01',
                'kind': 'JOINED',
                'unit_name': '',
                'unit_description': '',
                'rank': 'Junior Police Officer',
            },
        ])
    def test_serialization(self):
        pinned_officer = OfficerFactory(
            id=1,
            rank='Police Officer',
            first_name='Jerome',
            last_name='Finnigan',
            allegation_count=10,
            trr_percentile='99.99',
            complaint_percentile='88.88',
            civilian_allegation_percentile='77.77',
            internal_allegation_percentile='66.66',
        )

        relevant_allegation = AllegationFactory(
            crid='1',
            add1='LTK street',
            incident_date=datetime(2002, 2, 21, tzinfo=pytz.utc),
            most_common_category=AllegationCategoryFactory(
                category='Operation/Personnel Violations', allegation_name='Miscellaneous'
            ),
            point=Point([0.01, 0.02]),
        )

        VictimFactory(allegation=relevant_allegation, gender='F', age=65)
        VictimFactory(allegation=relevant_allegation, gender='M', age=54)

        AttachmentFileFactory(
            id=1,
            file_type='document',
            title='relevant document 1',
            allegation=relevant_allegation,
            show=True,
            preview_image_url="https://assets.documentcloud.org/CRID-1-CR-p1-normal.gif",
            url='http://cr-1-document.com/',
        )

        pinboard = PinboardFactory(
            id='66ef1560',
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set([pinned_officer])
        OfficerAllegationFactory(officer=pinned_officer, allegation=relevant_allegation)

        expect(pinboard.relevant_documents.count()).to.eq(1)
        expect(AllegationSerializer(pinboard.relevant_documents[0].allegation).data).to.eq({
            'crid': '1',
            'address': 'LTK street',
            'category': 'Operation/Personnel Violations',
            'incident_date': '2002-02-21',
            'coaccused': [{
                'id': 1,
                'rank': 'Police Officer',
                'full_name': 'Jerome Finnigan',
                'percentile_allegation': '88.8800',
                'percentile_allegation_civilian': '77.7700',
                'percentile_allegation_internal': '66.6600',
                'percentile_trr': '99.9900',
                'allegation_count': 10,
            }],
            'point': {
                'lon': 0.01,
                'lat': 0.02,
            },
            'victims': [
                {
                    'gender': 'Female',
                    'race': 'Black',
                    'age': 65
                },
                {
                    'gender': 'Male',
                    'race': 'Black',
                    'age': 54
                }
            ],
            'sub_category': 'Miscellaneous',
            'to': '/complaint/1/',
        })
        expect(DocumentSerializer(pinboard.relevant_documents.first()).data).to.eq({
            'id': 1,
            'preview_image_url': "https://assets.documentcloud.org/CRID-1-CR-p1-normal.gif",
            'url': 'http://cr-1-document.com/',
            'allegation': {
                'address': 'LTK street',
                'crid': '1',
                'category': 'Operation/Personnel Violations',
                'incident_date': '2002-02-21',
                'coaccused': [{
                    'id': 1,
                    'rank': 'Police Officer',
                    'full_name': 'Jerome Finnigan',
                    'allegation_count': 10,
                    'percentile_allegation': '88.8800',
                    'percentile_allegation_civilian': '77.7700',
                    'percentile_allegation_internal': '66.6600',
                    'percentile_trr': '99.9900',
                }],
                'point': {
                    'lon': 0.01,
                    'lat': 0.02,
                },
                'victims': [
                    {
                        'gender': 'Female',
                        'race': 'Black',
                        'age': 65
                    },
                    {
                        'gender': 'Male',
                        'race': 'Black',
                        'age': 54
                    }
                ],
                'sub_category': 'Miscellaneous',
                'to': '/complaint/1/',
            },
        })
示例#8
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',
            }]
        })
    def test_serialization(self):
        category = AllegationCategoryFactory(category='Use of Force',
                                             allegation_name='Subcategory')
        category2 = AllegationCategoryFactory(category='Verbal Abuse',
                                              allegation_name='Miscellaneous')
        allegation = AllegationFactory(
            crid=123,
            old_complaint_address='16XX N TALMAN AVE, CHICAGO IL',
            most_common_category=category,
            incident_date=datetime(2002, 1, 1, tzinfo=pytz.utc),
            coaccused_count=12,
            point=Point(-35.5, 68.9),
        )
        VictimFactory(gender='M', race='Black', age=35, allegation=allegation)
        coaccused = OfficerFactory(id=2,
                                   first_name='Walter',
                                   last_name='White',
                                   allegation_count=6,
                                   sustained_count=5,
                                   birth_year=1940,
                                   race='White',
                                   gender='M',
                                   rank='Sergeant of Police',
                                   complaint_percentile=0.0,
                                   civilian_allegation_percentile=1.1,
                                   internal_allegation_percentile=2.2,
                                   trr_percentile=3.3,
                                   resignation_date=date(2015, 4, 14))
        OfficerAllegationFactory(
            officer=coaccused,
            allegation=allegation,
            recc_outcome='11 Day Suspension',
            final_outcome='Separation',
            final_finding='SU',
            allegation_category=category2,
            disciplined=True,
        )

        expect(PinnedAllegationSerializer(allegation).data).to.eq({
            'crid':
            '123',
            'address':
            '16XX N TALMAN AVE, CHICAGO IL',
            'category':
            'Use of Force',
            'incident_date':
            '2002-01-01',
            'victims': [{
                'gender': 'Male',
                'race': 'Black',
                'age': 35
            }],
            'point': {
                'lon': -35.5,
                'lat': 68.9
            },
            'to':
            '/complaint/123/',
            'sub_category':
            'Subcategory',
            'coaccused': [{
                'id': 2,
                'full_name': 'Walter White',
                'complaint_count': 6,
                'sustained_count': 5,
                'birth_year': 1940,
                'recommended_outcome': '11 Day Suspension',
                'final_outcome': 'Separation',
                'final_finding': 'Sustained',
                'category': 'Verbal Abuse',
                'disciplined': True,
                'race': 'White',
                'gender': 'Male',
                'rank': 'Sergeant of Police',
                'percentile_trr': '3.3000',
                'percentile_allegation': '0.0000',
                'percentile_allegation_civilian': '1.1000',
                'percentile_allegation_internal': '2.2000'
            }],
        })
    def test_serialization(self):
        officer = OfficerFactory(id=123)
        allegation = AllegationFactory(
            crid='CR123',
            incident_date=datetime(2002, 2, 3, tzinfo=pytz.utc),
            coaccused_count=3,
            point=Point([0.01, 0.02]),
        )
        allegation_category = AllegationCategoryFactory(
            category='some category', allegation_name='some sub category')
        officer_allegation = OfficerAllegationFactory(
            officer=officer,
            allegation=allegation,
            start_date=date(2002, 2, 3),
            allegation_category=allegation_category,
            final_finding='SU',
            final_outcome='9 Day Suspension')

        attachment = AttachmentFileFactory(
            tag='Other',
            allegation=allegation,
            title='title',
            id='123456',
            url='url',
            preview_image_url='preview_image_url',
            file_type='document')
        VictimFactory(allegation=allegation, gender='M', race='Black', age=30)

        setattr(officer_allegation, 'unit_name', 'Unit 001')
        setattr(officer_allegation, 'unit_description', 'District 001')
        setattr(officer_allegation, 'rank_name', 'Police Officer')
        setattr(allegation, 'prefetch_filtered_attachments', [attachment])

        expect(CRNewTimelineSerializer(officer_allegation).data).to.eq({
            'unit_name':
            'Unit 001',
            'unit_description':
            'District 001',
            'rank':
            'Police Officer',
            'priority_sort':
            30,
            'kind':
            'CR',
            'date_sort':
            date(2002, 2, 3),
            'date':
            '2002-02-03',
            'crid':
            'CR123',
            'category':
            'some category',
            'subcategory':
            'some sub category',
            'finding':
            'Sustained',
            'outcome':
            '9 Day Suspension',
            'coaccused':
            3,
            'attachments': [{
                'title': 'title',
                'url': 'url',
                'preview_image_url': 'preview_image_url',
                'file_type': 'document',
                'id': '123456',
            }],
            'point': {
                'lon': 0.01,
                'lat': 0.02
            },
            'victims': [{
                'gender': 'Male',
                'race': 'Black',
                'age': 30
            }]
        })
示例#11
0
    def test_extract_datum(self):
        allegation = AllegationFactory(
            crid='123456',
            incident_date=datetime(2017, 7, 27, tzinfo=pytz.utc),
            summary='abc',
            add1='3000',
            add2='Michigan Ave',
            city='Chicago IL'
        )
        officer = OfficerFactory(
            id=10,
            first_name='Luke',
            last_name='Skywalker',
            allegation_count=4,
            complaint_percentile='99.70',
            trr_percentile='99.88',
            civilian_allegation_percentile='77.66',
            internal_allegation_percentile='66.55'
        )
        officer2 = OfficerFactory(
            id=11,
            first_name='John', last_name='Doe',
            allegation_count=2,
            complaint_percentile='70.33',
            trr_percentile='66.88',
            civilian_allegation_percentile='33.66',
            internal_allegation_percentile='22.55'
        )
        OfficerAllegationFactory(allegation=allegation, officer=officer)

        category1 = AllegationCategoryFactory(
            category='Operation/Personnel Violations',
            allegation_name='Secondary/Special Employment'
        )
        category2 = AllegationCategoryFactory(category='Use of Force', allegation_name='sub category')
        OfficerAllegationFactory(allegation=allegation, allegation_category=category2, officer=officer2)
        OfficerAllegationFactory.create_batch(2, allegation=allegation, allegation_category=category1, officer=None)
        OfficerAllegationFactory.create_batch(3, allegation=allegation, allegation_category=None, officer=None)

        VictimFactory(allegation=allegation, gender='F', race='Black', age=25)
        VictimFactory(allegation=allegation, gender='', race='Black', age=25)
        VictimFactory(allegation=allegation, gender='F', race='Black', age=None)

        AttachmentFileFactory(id=1, allegation=allegation, text_content='')
        AttachmentFileFactory(
            id=2, allegation=allegation, show=False,
            text_content="CHICAGO POLICE DEPARTMENT RD I HT334604"
        )
        AttachmentFileFactory(id=3, allegation=allegation, text_content='CHICAGO POLICE DEPARTMENT RD I HT334604')

        setattr(allegation, 'investigator_names', ['Jerome Finnigan'])
        allegation_cache_manager.cache_data()
        allegation.refresh_from_db()

        datum = CrIndexer().extract_datum(allegation)
        datum['victims'] = sorted(
            datum['victims'],
            key=lambda victim: (victim['gender'], victim['race'], victim.get('age', 0))
        )

        expect(datum).to.eq({
            'crid': '123456',
            'category': 'Operation/Personnel Violations',
            'sub_category': 'Secondary/Special Employment',
            'incident_date': '2017-07-27',
            'address': '3000 Michigan Ave, Chicago IL',
            'summary': 'abc',
            'to': '/complaint/123456/',
            'investigator_names': ['Jerome Finnigan'],
            'victims': [
                {'gender': '', 'race': 'Black', 'age': 25},
                {'gender': 'Female', 'race': 'Black'},
                {'gender': 'Female', 'race': 'Black', 'age': 25},
            ],
            'coaccused': [
                {
                    'id': 10, 'full_name': 'Luke Skywalker', 'allegation_count': 4,
                    'percentile_allegation': '99.7000',
                    'percentile_allegation_civilian': '77.6600',
                    'percentile_allegation_internal': '66.5500',
                    'percentile_trr': '99.8800',
                },
                {
                    'id': 11, 'full_name': 'John Doe', 'allegation_count': 2,
                    'percentile_allegation': '70.3300',
                    'percentile_allegation_civilian': '33.6600',
                    'percentile_allegation_internal': '22.5500',
                    'percentile_trr': '66.8800',
                }
            ],
            'attachment_files': [
                {'id': 3, 'text_content': 'CHICAGO POLICE DEPARTMENT RD I HT334604'}
            ]
        })
示例#12
0
    def test_serialization(self):
        category = AllegationCategoryFactory(category='Use of Force', allegation_name='Subcategory')
        allegation = AllegationFactory(
            crid=123,
            incident_date=datetime(2002, 1, 1, tzinfo=pytz.utc),
            most_common_category=category,
            coaccused_count=12,
            point=Point(-35.5, 68.9),
            old_complaint_address='34XX Douglas Blvd'
        )
        officer = OfficerFactory(
            id=1,
            first_name='Jerome',
            last_name='Finnigan',
            allegation_count=20,
            trr_percentile=80,
            complaint_percentile=85,
            civilian_allegation_percentile=90,
            internal_allegation_percentile=95
        )
        OfficerAllegationFactory(
            officer=officer,
            allegation=allegation,
            recc_outcome='Separation',
            final_outcome='30 Day Suspension',
            final_finding='UN',
            allegation_category=category,
            disciplined=True
        )
        VictimFactory(
            gender='M',
            race='Black',
            age=35,
            allegation=allegation
        )

        expected_data = {
            'incident_date': '2002-01-01',
            'crid': '123',
            'category': 'Use of Force',
            'subcategory': 'Subcategory',
            'kind': 'CR',
            'address': '34XX Douglas Blvd',
            'to': '/complaint/123/',
            'victims': [
                {
                    'gender': 'Male',
                    'race': 'Black',
                    'age': 35,
                }
            ],
            'coaccused': [
                {
                    'id': 1,
                    'full_name': 'Jerome Finnigan',
                    'allegation_count': 20,
                    'percentile_trr': '80.0000',
                    'percentile_allegation': '85.0000',
                    'percentile_allegation_civilian': '90.0000',
                    'percentile_allegation_internal': '95.0000',
                }
            ]
        }
        expect(CRDetailSerializer(allegation).data).to.eq(expected_data)
示例#13
0
 def test_gender_display(self):
     expect(VictimFactory(gender='M').gender_display).to.equal('Male')
     expect(VictimFactory(gender='F').gender_display).to.equal('Female')
     expect(VictimFactory(gender='X').gender_display).to.equal('X')
     expect(VictimFactory(gender='?').gender_display).to.equal('?')
示例#14
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'
        ])
示例#15
0
    def test_extract_datum_victim_blank_gender(self):
        VictimFactory(gender='')

        rows = self.extract_data()
        expect(rows).to.have.length(1)
        expect(rows[0]['victims'][0]['gender']).to.be.none()
示例#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'
                }
            ]
        })