def test_member_age_aggregation(self):
     unit = PoliceUnitFactory()
     OfficerHistoryFactory(unit=unit,
                           officer=OfficerFactory(birth_year='1980'))
     OfficerHistoryFactory(unit=unit,
                           officer=OfficerFactory(birth_year=None))
     expect(sorted(unit.member_age_aggregation,
                   key=itemgetter('name'))).to.eq([{
                       'name': '31-40',
                       'count': 1
                   }, {
                       'name': 'Unknown',
                       'count': 1
                   }])
Ejemplo n.º 2
0
 def test_member_race_aggregation(self):
     unit = PoliceUnitFactory()
     OfficerHistoryFactory(unit=unit, officer=OfficerFactory(race='White'))
     OfficerHistoryFactory(unit=unit, officer=OfficerFactory(race=''))
     expect(sorted(unit.member_race_aggregation, key=itemgetter('name'))).to.eq([
         {
             'name': 'Unknown',
             'count': 1
         },
         {
             'name': 'White',
             'count': 1
         }
     ])
Ejemplo n.º 3
0
 def setUp(self):
     super(UnitOfficerWorkerTestCase, self).setUp()
     officer1 = OfficerFactory(first_name='Kevin', last_name='Osborn')
     officer2 = OfficerFactory(first_name='Kevin', last_name='Cascone')
     officer3 = OfficerFactory(first_name='Cristiano', last_name='Cascone')
     OfficerAllegationFactory(officer=officer1)
     unit1 = PoliceUnitFactory(unit_name='001', description='foo')
     OfficerHistoryFactory(officer=officer1, unit=unit1)
     OfficerHistoryFactory(officer=officer2, unit=unit1)
     OfficerHistoryFactory(officer=officer3,
                           unit__unit_name='002',
                           unit__description='bar')
     self.rebuild_index()
     self.refresh_index()
Ejemplo n.º 4
0
 def test_complainant_gender_aggregation_with_duplicated_allegation(self):
     unit = PoliceUnitFactory()
     officer1 = OfficerFactory()
     officer2 = OfficerFactory()
     allegation = AllegationFactory()
     OfficerHistoryFactory(officer=officer1, unit=unit)
     OfficerHistoryFactory(officer=officer2, unit=unit)
     OfficerAllegationFactory(officer=officer1, allegation=allegation, final_finding='SU')
     OfficerAllegationFactory(officer=officer2, allegation=allegation, final_finding='SU')
     ComplainantFactory(allegation=allegation, gender='F')
     expect(unit.complainant_gender_aggregation).to.eq([{
         'name': 'Female',
         'count': 1,
         'sustained_count': 1
     }])
    def test_sustained_count_with_duplicated_allegation(self):
        unit = PoliceUnitFactory()
        officer1 = OfficerFactory()
        officer2 = OfficerFactory()
        OfficerHistoryFactory(unit=unit, officer=officer1)
        OfficerHistoryFactory(unit=unit, officer=officer2)
        allegation = AllegationFactory()
        OfficerAllegationFactory(officer=officer1,
                                 allegation=allegation,
                                 final_finding='SU')
        OfficerAllegationFactory(officer=officer2,
                                 allegation=allegation,
                                 final_finding='SU')

        expect(unit.sustained_count).to.eq(1)
Ejemplo n.º 6
0
    def test_new_timeline_item_with_alias(self):
        officer = OfficerFactory(id=456, appointed_date=date(2000, 1, 1))
        OfficerAliasFactory(old_officer_id=123, new_officer=officer)
        unit = PoliceUnitFactory(unit_name='001', description='unit_001')
        OfficerHistoryFactory(officer=officer, unit=unit, effective_date=date(2010, 1, 1), end_date=date(2011, 12, 31))
        AwardFactory(officer=officer, start_date=date(2011, 3, 23), award_type='Life Saving Award')

        response = self.client.get(reverse('api-v2:officers-new-timeline-items', kwargs={'pk': 123}))
        expect(response.data).to.eq([
            {
                'date': '2011-03-23',
                'kind': 'AWARD',
                'award_type': 'Life Saving Award',
                'unit_name': '001',
                'unit_description': 'unit_001'
            },
            {
                'date': '2010-01-01',
                'kind': 'UNIT_CHANGE',
                'unit_name': '001',
                'unit_description': 'unit_001'
            },
            {
                'date': '2000-01-01',
                'kind': 'JOINED',
                'unit_name': '',
                'unit_description': ''
            }
        ])
    def test_serialization(self):
        officer = OfficerFactory(id=123)
        unit = PoliceUnitFactory(
            id=4,
            unit_name='004',
            description='District 004',
        )
        officer_history = OfficerHistoryFactory(officer=officer,
                                                unit=unit,
                                                effective_date=date(
                                                    2002, 2, 3))
        setattr(officer_history, 'rank_name', 'Police Officer')

        expect(UnitChangeNewTimelineSerializer(officer_history).data).to.eq({
            'unit_name':
            '004',
            'unit_description':
            'District 004',
            'rank':
            'Police Officer',
            'priority_sort':
            20,
            'kind':
            'UNIT_CHANGE',
            'date_sort':
            date(2002, 2, 3),
            'date':
            '2002-02-03'
        })
 def test_complainant_gender_aggregation(self):
     unit = PoliceUnitFactory()
     officer = OfficerFactory()
     allegation1 = AllegationFactory()
     allegation2 = AllegationFactory()
     OfficerHistoryFactory(officer=officer, unit=unit)
     OfficerAllegationFactory(officer=officer,
                              allegation=allegation1,
                              final_finding='SU')
     OfficerAllegationFactory(officer=officer,
                              allegation=allegation2,
                              final_finding='UN')
     ComplainantFactory(allegation=allegation1, gender='F')
     ComplainantFactory(allegation=allegation2, gender='')
     expect(
         sorted(unit.complainant_gender_aggregation,
                key=itemgetter('name'))).to.eq([{
                    'name': 'Female',
                    'count': 1,
                    'sustained_count': 1
                }, {
                    'name': 'Unknown',
                    'count': 1,
                    'sustained_count': 0
                }])
Ejemplo n.º 9
0
 def test_sustained_count(self):
     unit = PoliceUnitFactory()
     officer = OfficerFactory()
     OfficerHistoryFactory(unit=unit, officer=officer)
     OfficerAllegationFactory(officer=officer, final_finding='SU')
     OfficerAllegationFactory(officer=officer, final_finding='UN')
     expect(unit.sustained_count).to.eq(1)
Ejemplo n.º 10
0
    def test_new_timeline_item_merge_rank_and_unit_change_join(self):
        officer = OfficerFactory(id=123, appointed_date=date(2000, 1, 1), rank='Police Officer')

        first_unit = PoliceUnitFactory(unit_name='001', description='unit_001')
        unit = PoliceUnitFactory(unit_name='002', description='unit_002')
        OfficerHistoryFactory(
            officer=officer,
            unit=first_unit,
            effective_date=date(2000, 1, 1),
            end_date=date(2009, 12, 31))
        OfficerHistoryFactory(
            officer=officer,
            unit=unit,
            effective_date=date(2010, 1, 1),
            end_date=date(2011, 12, 31))

        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([
            {
                'date': '2010-01-01',
                'kind': 'UNIT_CHANGE',
                'unit_name': '002',
                'unit_description': 'unit_002',
                'rank': 'Police Officer',
            }, {
                'date': '2001-09-23',
                'kind': 'RANK_CHANGE',
                'unit_name': '001',
                'unit_description': 'unit_001',
                'rank': 'Police Officer',
            }, {
                'date': '2000-01-01',
                'kind': 'JOINED',
                'unit_name': '001',
                'unit_description': 'unit_001',
                'rank': 'Junior Police Officer',
            }
        ])
Ejemplo n.º 11
0
    def test_extract_datum(self):
        datum = PoliceUnitFactory(unit_name='011', description='description')
        officer = OfficerFactory()
        officer2 = OfficerFactory()
        OfficerHistoryFactory(officer=officer, unit=datum, end_date=None)
        OfficerHistoryFactory(officer=officer2, unit=datum)

        expect(
            UnitIndexer().extract_datum(datum)
        ).to.be.eq({
            'name': '011',
            'description': 'description',
            'url': datum.v1_url,
            'to': datum.v2_to,
            'active_member_count': 1,
            'member_count': 2,
            'long_name': 'Unit 011',
        })
    def test_member_race_aggregation_in_case_officer_left_and_rejoin(self):
        unit1 = PoliceUnitFactory()
        unit2 = PoliceUnitFactory()
        officer = OfficerFactory(race='White')
        OfficerHistoryFactory(officer=officer, unit=unit1)
        OfficerHistoryFactory(officer=officer, unit=unit2)
        OfficerHistoryFactory(officer=officer, unit=unit1)
        OfficerHistoryFactory(officer=OfficerFactory(race='White'), unit=unit1)
        OfficerHistoryFactory(officer=OfficerFactory(race=''), unit=unit1)

        expect(sorted(unit1.member_race_aggregation,
                      key=itemgetter('name'))).to.eq([{
                          'name': 'Unknown',
                          'count': 1
                      }, {
                          'name': 'White',
                          'count': 2
                      }])
Ejemplo n.º 13
0
 def test_complaint_category_aggregation_with_duplicated_allegation(self):
     unit = PoliceUnitFactory()
     officer1 = OfficerFactory()
     officer2 = OfficerFactory()
     allegation = AllegationFactory()
     allegation_category = AllegationCategoryFactory(category='Use of Force')
     OfficerHistoryFactory(officer=officer1, unit=unit)
     OfficerHistoryFactory(officer=officer2, unit=unit)
     OfficerAllegationFactory(
         officer=officer1, allegation=allegation, allegation_category=allegation_category, final_finding='NS'
     )
     OfficerAllegationFactory(
         officer=officer2, allegation=allegation, allegation_category=allegation_category, final_finding='NS'
     )
     expect(unit.complaint_category_aggregation).to.eq([{
         'name': 'Use of Force',
         'count': 1,
         'sustained_count': 0
     }])
Ejemplo n.º 14
0
    def test_rank_change_timeline(self, rank_change_new_timeline_serializer_mock):
        officer = OfficerFactory(id=123, appointed_date=date(2001, 2, 3))

        salary_1 = SalaryFactory(
            year=2001, rank='Police Officer', officer=officer, rank_changed=True, spp_date=date(2001, 5, 3)
        )
        salary_2 = SalaryFactory(
            year=2002, rank='Senior Police Officer', officer=officer, rank_changed=True, spp_date=date(2002, 5, 3)
        )
        SalaryFactory(
            year=2001, rank='Junior Police Officer', officer=officer, rank_changed=True, spp_date=date(2001, 2, 3)
        )
        SalaryFactory(
            year=2003, rank='Senior Police Officer', officer=officer, rank_changed=False, spp_date=date(2003, 5, 3)
        )

        unit_1 = PoliceUnitFactory(unit_name='001', description='District 001')
        unit_2 = PoliceUnitFactory(unit_name='002', description='District 002')
        OfficerHistoryFactory(
            officer=officer, unit=unit_1, effective_date=date(2001, 1, 3), end_date=date(2002, 1, 2)
        )
        OfficerHistoryFactory(
            officer=officer, unit=unit_2, effective_date=date(2002, 1, 3), end_date=date(2018, 1, 3)
        )

        other_officer = OfficerFactory(id=456)
        SalaryFactory(
            year=2001, rank='Police Officer', officer=other_officer, rank_changed=True, spp_date=date(2001, 5, 3)
        )

        expect(OfficerTimelineQuery(officer)._rank_change_timeline).to.eq([{'id': 1}, {'id': 2}])

        rank_change_timeline_queryset_arg = rank_change_new_timeline_serializer_mock.call_args[0][0]

        salary_1_arg, salary_2_arg = rank_change_timeline_queryset_arg

        expect(salary_1_arg.id).to.eq(salary_1.id)
        expect(salary_1_arg.unit_name).to.eq('001')
        expect(salary_1_arg.unit_description).to.eq('District 001')

        expect(salary_2_arg.id).to.eq(salary_2.id)
        expect(salary_2_arg.unit_name).to.eq('002')
        expect(salary_2_arg.unit_description).to.eq('District 002')
Ejemplo n.º 15
0
 def test_get_unit_by_date(self):
     officer = OfficerFactory()
     unit_100 = PoliceUnitFactory()
     unit_101 = PoliceUnitFactory()
     OfficerHistoryFactory(
         officer=officer,
         unit=unit_100,
         effective_date=date(2000, 1, 1),
         end_date=date(2005, 12, 31),
     )
     OfficerHistoryFactory(
         officer=officer,
         unit=unit_101,
         effective_date=date(2006, 1, 1),
         end_date=date(2010, 12, 31),
     )
     expect(officer.get_unit_by_date(date(1999, 1, 1))).to.be.none()
     expect(officer.get_unit_by_date(date(2001, 1, 1))).to.eq(unit_100)
     expect(officer.get_unit_by_date(date(2007, 1, 1))).to.eq(unit_101)
     expect(officer.get_unit_by_date(date(2011, 1, 1))).to.be.none()
Ejemplo n.º 16
0
    def test_member_age_aggregation_in_case_officer_left_and_rejoin(self):
        unit1 = PoliceUnitFactory()
        unit2 = PoliceUnitFactory()
        officer = OfficerFactory(birth_year='1980')
        OfficerHistoryFactory(officer=officer, unit=unit1)
        OfficerHistoryFactory(officer=officer, unit=unit2)
        OfficerHistoryFactory(officer=officer, unit=unit1)
        OfficerHistoryFactory(officer=OfficerFactory(birth_year='1985'), unit=unit1)
        OfficerHistoryFactory(officer=OfficerFactory(birth_year=None), unit=unit1)

        expect(sorted(unit1.member_age_aggregation, key=itemgetter('name'))).to.eq([
            {
                'name': '31-40',
                'count': 2
            },
            {
                'name': 'Unknown',
                'count': 1
            }
        ])
Ejemplo n.º 17
0
    def test_new_timeline_item_no_join(self):
        officer = OfficerFactory(id=123, appointed_date=None, rank='Police Officer')

        unit = PoliceUnitFactory(unit_name='001', description='unit_001')
        OfficerHistoryFactory(officer=officer, unit=unit, effective_date=date(2010, 1, 1), end_date=date(2011, 12, 31))

        allegation = AllegationFactory(
            crid='123456',
            coaccused_count=4,
            incident_date=datetime(2011, 8, 23, tzinfo=pytz.utc)
        )
        OfficerAllegationFactory(
            final_finding='UN', final_outcome='Unknown',
            officer=officer, allegation=allegation,
            allegation_category=AllegationCategoryFactory(category='category', allegation_name='sub category')
        )
        OfficerAllegationFactory.create_batch(3, allegation=allegation)

        SalaryFactory(officer=officer, year=2001, rank='Police Officer', spp_date=date(2001, 9, 23))

        cache_managers.cache_all()

        response = self.client.get(reverse('api-v2:officers-new-timeline-items', kwargs={'pk': 123}))

        expect(response.status_code).to.eq(status.HTTP_200_OK)
        expect(response.data).to.eq([
            {
                'date': '2011-08-23',
                'kind': 'CR',
                'crid': '123456',
                'category': 'category',
                'subcategory': 'sub category',
                'finding': 'Unfounded',
                'outcome': 'Unknown',
                'coaccused': 4,
                'unit_name': '001',
                'unit_description': 'unit_001',
                'rank': 'Police Officer',
                'victims': [],
                'attachments': [],
            }, {
                'date': '2010-01-01',
                'kind': 'UNIT_CHANGE',
                'unit_name': '001',
                'unit_description': 'unit_001',
                'rank': 'Police Officer',
            }, {
                'date': '2001-09-23',
                'kind': 'RANK_CHANGE',
                'unit_name': '',
                'unit_description': '',
                'rank': 'Police Officer',
            }
        ])
Ejemplo n.º 18
0
 def test_complainant_race_aggregation(self):
     unit = PoliceUnitFactory()
     officer = OfficerFactory()
     allegation = AllegationFactory()
     OfficerHistoryFactory(unit=unit, officer=officer)
     OfficerAllegationFactory(officer=officer, allegation=allegation, final_finding='NS')
     ComplainantFactory(allegation=allegation, race='White')
     expect(unit.complainant_race_aggregation).to.eq([{
         'name': 'White',
         'count': 1,
         'sustained_count': 0
     }])
Ejemplo n.º 19
0
    def test_award_timeline(self, award_new_timeline_serializer_mock):
        officer = OfficerFactory(id=123, appointed_date=date(2001, 2, 3))

        award_1 = AwardFactory(officer=officer, start_date=date(2002, 1, 3), award_type='Honored Police Star')
        award_2 = AwardFactory(officer=officer, start_date=date(2003, 1, 5), award_type='Life Saving Award')
        AwardFactory(officer=officer, start_date=date(2007, 2, 3), award_type='Complimentary Letter')
        AwardFactory(officer=officer, start_date=date(2008, 2, 3), award_type='Department Commendation')
        AwardFactory(officer=officer, start_date=date(2011, 2, 3), award_type='Citizen Honorable Mention')
        AwardFactory(officer=officer, start_date=None, award_type='Life Saving')

        unit_1 = PoliceUnitFactory(unit_name='001', description='District 001')
        unit_2 = PoliceUnitFactory(unit_name='002', description='District 002')
        OfficerHistoryFactory(
            officer=officer, unit=unit_1, effective_date=date(2002, 1, 3), end_date=date(2003, 1, 2)
        )
        OfficerHistoryFactory(
            officer=officer, unit=unit_2, effective_date=date(2003, 1, 3), end_date=date(2018, 1, 3)
        )
        SalaryFactory(
            year=2001, rank='Police Officer', officer=officer, rank_changed=True, spp_date=date(2001, 5, 3)
        )
        SalaryFactory(
            year=2002, rank='Senior Police Officer', officer=officer, rank_changed=True, spp_date=date(2002, 5, 3)
        )

        expect(OfficerTimelineQuery(officer)._award_timeline).to.eq([{'id': 1}, {'id': 2}])

        award_timeline_queryset_arg = award_new_timeline_serializer_mock.call_args[0][0]
        award_1_arg, award_2_arg = sorted(award_timeline_queryset_arg, key=attrgetter('id'))

        expect(award_1_arg.id).to.eq(award_1.id)
        expect(award_1_arg.unit_name).to.eq('001')
        expect(award_1_arg.unit_description).to.eq('District 001')
        expect(award_1_arg.rank_name).to.eq('Police Officer')

        expect(award_2_arg.id).to.eq(award_2.id)
        expect(award_2_arg.unit_name).to.eq('002')
        expect(award_2_arg.unit_description).to.eq('District 002')
        expect(award_2_arg.rank_name).to.eq('Senior Police Officer')
 def test_complaint_category_aggregation(self):
     unit = PoliceUnitFactory()
     officer = OfficerFactory()
     OfficerHistoryFactory(unit=unit, officer=officer)
     OfficerAllegationFactory(officer=officer,
                              allegation_category=AllegationCategoryFactory(
                                  category='Use of Force'),
                              final_finding='NS')
     expect(unit.complaint_category_aggregation).to.eq([{
         'name': 'Use of Force',
         'count': 1,
         'sustained_count': 0
     }])
Ejemplo n.º 21
0
    def test_cr_timeline(self, cr_new_timeline_serializer_mock):
        officer = OfficerFactory(id=123)
        OfficerAllegationFactory(id=1, officer=officer, allegation__incident_date=datetime(2002, 2, 3, tzinfo=pytz.utc))
        OfficerAllegationFactory(id=2, officer=officer, allegation__incident_date=datetime(2003, 1, 5, tzinfo=pytz.utc))
        OfficerAllegationFactory(id=3, officer=officer, allegation__incident_date=None)

        unit_1 = PoliceUnitFactory(unit_name='001', description='District 001')
        unit_2 = PoliceUnitFactory(unit_name='002', description='District 002')
        OfficerHistoryFactory(
            officer=officer, unit=unit_1, effective_date=date(2002, 1, 3), end_date=date(2003, 1, 2)
        )
        OfficerHistoryFactory(
            officer=officer, unit=unit_2, effective_date=date(2003, 1, 3), end_date=date(2018, 1, 3)
        )
        SalaryFactory(
            year=2001, rank='Police Officer', officer=officer, rank_changed=True, spp_date=date(2001, 5, 3)
        )
        SalaryFactory(
            year=2002, rank='Senior Police Officer', officer=officer, rank_changed=True, spp_date=date(2002, 5, 3)
        )

        other_officer = OfficerFactory(id=456)
        OfficerAllegationFactory(id=4, officer=other_officer, start_date=date(2003, 1, 5))

        expect(OfficerTimelineQuery(officer)._cr_timeline).to.eq([{'id': 1}, {'id': 2}])

        cr_timeline_queryset_arg = cr_new_timeline_serializer_mock.call_args[0][0]
        officer_allegation_1_arg, officer_allegation_2_arg = sorted(cr_timeline_queryset_arg, key=attrgetter('id'))

        expect(officer_allegation_1_arg.id).to.eq(1)
        expect(officer_allegation_1_arg.unit_name).to.eq('001')
        expect(officer_allegation_1_arg.unit_description).to.eq('District 001')
        expect(officer_allegation_1_arg.rank_name).to.eq('Police Officer')

        expect(officer_allegation_2_arg.id).to.eq(2)
        expect(officer_allegation_2_arg.unit_name).to.eq('002')
        expect(officer_allegation_2_arg.unit_description).to.eq('District 002')
        expect(officer_allegation_2_arg.rank_name).to.eq('Senior Police Officer')
Ejemplo n.º 22
0
    def test_unit_change_timeline(self, unit_change_new_timeline_serializer_mock):
        officer = OfficerFactory(id=123, appointed_date=date(2001, 2, 3))
        officer_history_1 = OfficerHistoryFactory(
            officer=officer, effective_date=date(2002, 1, 3), end_date=date(2002, 1, 3)
        )
        officer_history_2 = OfficerHistoryFactory(
            officer=officer, effective_date=date(2003, 1, 3), end_date=date(2018, 1, 3)
        )
        OfficerHistoryFactory(
            officer=officer, effective_date=None, end_date=date(2018, 1, 3)
        )
        OfficerHistoryFactory(
            officer=officer, effective_date=None, end_date=date(2001, 2, 3)
        )
        SalaryFactory(
            year=2001, rank='Police Officer', officer=officer, rank_changed=True, spp_date=date(2001, 5, 3)
        )
        SalaryFactory(
            year=2002, rank='Senior Police Officer', officer=officer, rank_changed=True, spp_date=date(2002, 5, 3)
        )

        other_officer = OfficerFactory(id=456)
        OfficerHistoryFactory(
            officer=other_officer, effective_date=date(2002, 1, 3), end_date=date(2002, 1, 3)
        )

        expect(OfficerTimelineQuery(officer)._unit_change_timeline).to.eq([{'id': 1}, {'id': 2}])

        unit_change_timeline_queryset_arg = unit_change_new_timeline_serializer_mock.call_args[0][0]
        officer_allegation_1_arg, officer_allegation_2_arg = unit_change_timeline_queryset_arg

        expect(officer_allegation_1_arg.id).to.eq(officer_history_1.id)
        expect(officer_allegation_1_arg.rank_name).to.eq('Police Officer')

        expect(officer_allegation_2_arg.id).to.eq(officer_history_2.id)
        expect(officer_allegation_2_arg.rank_name).to.eq('Senior Police Officer')
Ejemplo n.º 23
0
    def test_search_unit_officer(self):
        officer = OfficerFactory()
        OfficerHistoryFactory(officer=officer, unit=PoliceUnitFactory(unit_name='123'))

        self.rebuild_index()
        self.refresh_index()

        url = reverse('api:suggestion-list')
        response = self.client.get(url, {
            'term': 12,
        })

        results = response.data['UNIT > OFFICERS']
        expect(results).to.have.length(1)

        expect(results[0]['name']).to.eq(officer.full_name)
Ejemplo n.º 24
0
 def test_complainant_age_aggregation(self):
     unit = PoliceUnitFactory()
     officer = OfficerFactory()
     allegation1 = AllegationFactory()
     allegation2 = AllegationFactory()
     OfficerHistoryFactory(officer=officer, unit=unit)
     OfficerAllegationFactory(officer=officer, allegation=allegation1, final_finding='SU')
     OfficerAllegationFactory(officer=officer, allegation=allegation2, final_finding='UN')
     ComplainantFactory(allegation=allegation1, age=25)
     ComplainantFactory(allegation=allegation2, age=None)
     expect(unit.complainant_age_aggregation).to.eq([{
         'name': '21-30',
         'count': 1,
         'sustained_count': 1
     }, {
         'name': 'Unknown',
         'count': 1,
         'sustained_count': 0
     }])
Ejemplo n.º 25
0
    def test_join_timeline(self, join_new_timeline_serializer_mock):
        officer = OfficerFactory(id=123, appointed_date=date(2001, 2, 3))

        SalaryFactory(
            year=2001, rank='Police Officer', officer=officer, rank_changed=True, spp_date=date(2001, 2, 3)
        )

        unit = PoliceUnitFactory(unit_name='001', description='District 001')
        OfficerHistoryFactory(
            officer=officer, unit=unit, effective_date=date(2001, 1, 3), end_date=date(2001, 2, 3)
        )

        expect(OfficerTimelineQuery(officer)._join_timeline).to.eq([{'id': 1}])

        join_timeline_queryset_arg = join_new_timeline_serializer_mock.call_args[0][0]
        officer_arg, = join_timeline_queryset_arg

        expect(officer_arg.id).to.eq(officer.id)
        expect(officer_arg.unit_name).to.eq('001')
        expect(officer_arg.unit_description).to.eq('District 001')
        expect(officer_arg.rank_name).to.eq('Police Officer')
Ejemplo n.º 26
0
    def test_extract_info(self):
        officer = OfficerFactory(id=123,
                                 first_name='Alex',
                                 last_name='Mack',
                                 rank='5',
                                 race='White',
                                 gender='M',
                                 appointed_date=date(2017, 2, 27),
                                 resignation_date=date(2017, 12, 27),
                                 active='Yes',
                                 birth_year=1910,
                                 complaint_percentile=99.8,
                                 honorable_mention_percentile=98,
                                 tags=['Jason VanDyke'])
        TRRFactory(officer=officer,
                   trr_datetime=datetime(2002, 9, 29, tzinfo=pytz.utc))
        SalaryFactory(officer=officer, salary=9000)
        AwardFactory(officer=officer, award_type='Honorable Mention')
        AwardFactory(officer=officer, award_type='Complimentary Letter')
        AwardFactory(officer=officer, award_type='Honored Police Star')
        AwardFactory(officer=officer, award_type='Lambert Tree')
        OfficerHistoryFactory(officer=officer,
                              unit__id=1001,
                              unit__unit_name='001',
                              unit__description='Hyde Park D',
                              effective_date=date(2010, 1, 1),
                              end_date=date(2011, 1, 1))
        OfficerHistoryFactory(officer=officer,
                              unit__id=1002,
                              unit__unit_name='002',
                              unit__description='Tactical',
                              effective_date=date(2011, 1, 2))
        OfficerBadgeNumberFactory(officer=officer, star='123456', current=True)
        OfficerBadgeNumberFactory(officer=officer, star='123', current=False)
        OfficerBadgeNumberFactory(officer=officer, star='456', current=False)

        allegation = AllegationFactory(
            incident_date=datetime(2000, 4, 26, tzinfo=pytz.utc))
        OfficerAllegationFactory(
            officer=officer,
            final_finding='SU',
            start_date=date(2000, 1, 1),
            allegation_category__category='Illegal Search',
            allegation=allegation,
            disciplined=True)
        ComplainantFactory(allegation=allegation,
                           race='White',
                           age=18,
                           gender='M')

        rows = self.extract_data()
        expect(rows).to.have.length(1)
        expect(rows[0]).to.eq({
            'id':
            123,
            'full_name':
            'Alex Mack',
            'unit': {
                'id': 1002,
                'unit_name': '002',
                'description': 'Tactical',
                'long_unit_name': 'Unit 002'
            },
            'rank':
            '5',
            'race':
            'White',
            'badge':
            '123456',
            'badge_keyword':
            '123456',
            'historic_badges': ['123', '456'],
            'historic_badges_keyword': ['123', '456'],
            'historic_units': [{
                'id': 1002,
                'unit_name': '002',
                'description': 'Tactical',
                'long_unit_name': 'Unit 002',
            }, {
                'id': 1001,
                'unit_name': '001',
                'description': 'Hyde Park D',
                'long_unit_name': 'Unit 001',
            }],
            'gender':
            'Male',
            'date_of_appt':
            '2017-02-27',
            'date_of_resignation':
            '2017-12-27',
            'active':
            'Active',
            'birth_year':
            1910,
            'complaint_records': {
                'count':
                1,
                'sustained_count':
                1,
                'items': [{
                    'year': 2000,
                    'count': 1,
                    'sustained_count': 1
                }],
                'facets': [{
                    'name':
                    'category',
                    'entries': [{
                        'name':
                        'Illegal Search',
                        'count':
                        1,
                        'sustained_count':
                        1,
                        'items': [{
                            'year': 2000,
                            'name': 'Illegal Search',
                            'count': 1,
                            'sustained_count': 1
                        }]
                    }]
                }, {
                    'name':
                    'complainant race',
                    'entries': [{
                        'name':
                        'White',
                        'count':
                        1,
                        'sustained_count':
                        1,
                        'items': [{
                            'year': 2000,
                            'name': 'White',
                            'count': 1,
                            'sustained_count': 1
                        }]
                    }]
                }, {
                    'name':
                    'complainant age',
                    'entries': [{
                        'name':
                        '<20',
                        'count':
                        1,
                        'sustained_count':
                        1,
                        'items': [{
                            'year': 2000,
                            'name': '<20',
                            'count': 1,
                            'sustained_count': 1
                        }]
                    }]
                }, {
                    'name':
                    'complainant gender',
                    'entries': [{
                        'name':
                        'Male',
                        'count':
                        1,
                        'sustained_count':
                        1,
                        'items': [{
                            'year': 2000,
                            'name': 'Male',
                            'count': 1,
                            'sustained_count': 1
                        }]
                    }]
                }]
            },
            'allegation_count':
            1,
            'complaint_percentile':
            Decimal('99.8'),
            'honorable_mention_count':
            1,
            'honorable_mention_percentile':
            98,
            'has_visual_token':
            False,
            'sustained_count':
            1,
            'discipline_count':
            1,
            'civilian_compliment_count':
            1,
            'trr_count':
            1,
            'major_award_count':
            2,
            'tags': ['Jason VanDyke'],
            'to':
            '/officer/123/alex-mack/',
            'url':
            'http://test.com/officer/alex-mack/123',
            'current_salary':
            9000,
            'unsustained_count':
            0,
            'coaccusals': [],
            'current_allegation_percentile':
            None,
            'percentiles': [],
            'cr_incident_dates': ['2000-04-26'],
            'trr_datetimes': ['2002-09-29'],
            'internal_allegation_percentile':
            None,
            'trr_percentile':
            None,
            'civilian_allegation_percentile':
            None,
        })
Ejemplo n.º 27
0
 def test_unit_name(self):
     history = OfficerHistoryFactory(unit=PoliceUnitFactory(unit_name='abc'))
     expect(history.unit_name).to.eq('abc')
Ejemplo n.º 28
0
    def test_summary(self):
        officer = OfficerFactory(
            tags=[],
            first_name='Kevin', last_name='Kerl', id=123, race='White', gender='M',
            appointed_date=date(2017, 2, 27), rank='PO', resignation_date=date(2017, 12, 27),
            active=ACTIVE_YES_CHOICE, birth_year=1910, complaint_percentile=32.5,
            sustained_count=1, allegation_count=1, discipline_count=1, trr_count=1,
            civilian_compliment_count=1, honorable_mention_count=1, major_award_count=1,
            last_unit_id=1, current_badge='123456', current_salary=90000, has_unique_name=True
        )
        allegation = AllegationFactory()
        allegation_category = AllegationCategoryFactory(category='Use of Force')
        OfficerHistoryFactory(officer=officer, unit=PoliceUnitFactory(id=1, unit_name='CAND', description=''))
        ComplainantFactory(allegation=allegation, race='White', age=18, gender='F')
        OfficerBadgeNumberFactory(officer=officer, star='123456', current=True)
        OfficerAllegationFactory(
            officer=officer, allegation=allegation, allegation_category=allegation_category,
            final_finding='SU', start_date=date(2000, 1, 1), disciplined=True
        )
        AwardFactory(officer=officer, award_type='Complimentary Letter')
        AwardFactory(officer=officer, award_type='Honored Police Star')
        AwardFactory(officer=officer, award_type='Honorable Mention')
        SalaryFactory(officer=officer, salary=50000, year=2015)
        SalaryFactory(officer=officer, salary=90000, year=2017)
        TRRFactory(officer=officer)

        officer_cache_manager.build_cached_columns()
        allegation_cache_manager.cache_data()

        response = self.client.get(reverse('api-v2:officers-summary', kwargs={'pk': 123}))
        expect(response.status_code).to.eq(status.HTTP_200_OK)
        expected_data = {
            'id': 123,
            'unit': {
                'id': 1,
                'unit_name': 'CAND',
                'description': '',
                'long_unit_name': 'Unit CAND',
            },
            'date_of_appt': '2017-02-27',
            'date_of_resignation': '2017-12-27',
            'active': 'Active',
            'rank': 'PO',
            'full_name': 'Kevin Kerl',
            'race': 'White',
            'badge': '123456',
            'historic_units': [{
                'id': 1,
                'unit_name': 'CAND',
                'description': '',
                'long_unit_name': 'Unit CAND'
            }],
            'gender': 'Male',
            'birth_year': 1910,
            'sustained_count': 1,
            'civilian_compliment_count': 1,
            'allegation_count': 1,
            'discipline_count': 1,
            'honorable_mention_count': 1,
            'to': '/officer/123/kevin-kerl/',
            'url': 'http://cpdb.lvh.me/officer/kevin-kerl/123',
            'current_salary': 90000,
            'trr_count': 1,
            'major_award_count': 1,
            'unsustained_count': 0,
            'percentile_allegation': '32.5000',
            'coaccusals': [],
            'percentiles': [],
            'tags': [],
            'historic_badges': [],
            'has_unique_name': True
        }
        expect(response.data).to.eq(expected_data)
Ejemplo n.º 29
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',
            },
        ])
Ejemplo n.º 30
0
 def test_member_count(self):
     unit = PoliceUnitFactory()
     OfficerHistoryFactory(officer=OfficerFactory(), unit=unit)
     OfficerHistoryFactory(officer=OfficerFactory(), unit=unit)
     expect(unit.member_count).to.eq(2)