Пример #1
0
    def test_get_queryset_with_police_district(self):
        area1 = AreaFactory(area_type='police-districts')
        RacePopulationFactory(race='White', count=1000, area=area1)
        AllegationFactory.create_batch(2, areas=[area1])

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

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

        area_indexer = AreaIndexer()
        expect(area_indexer.get_queryset().count()).to.eq(3)
        expect(area_indexer._percentiles).to.eq({
            area1.id: 0.0,
            area2.id: 50.0
        })
Пример #2
0
    def test_query(self):
        allegation_officer1, allegation_officer2 = OfficerFactory.create_batch(
            2)
        trr_officer1, trr_officer2 = OfficerFactory.create_batch(2)
        pinboard_officer1, pinboard_officer2 = OfficerFactory.create_batch(2)
        other_officer = OfficerFactory()

        pinboard_allegation1, pinboard_allegation2 = AllegationFactory.create_batch(
            2)
        allegation1, allegation2, allegation3, allegation4 = AllegationFactory.create_batch(
            4)

        trr1 = TRRFactory(officer=trr_officer1)
        trr2 = TRRFactory(officer=trr_officer2)

        allegation_category1 = AllegationCategoryFactory(
            category='Operation/Personnel Violations', )
        allegation_category2 = AllegationCategoryFactory(
            category='Illegal Search', )
        allegation_category3 = AllegationCategoryFactory(
            category='Verbal Abuse', )

        OfficerAllegationFactory(allegation=pinboard_allegation1,
                                 officer=allegation_officer1,
                                 allegation_category=allegation_category1)
        OfficerAllegationFactory(allegation=pinboard_allegation2,
                                 officer=allegation_officer1,
                                 allegation_category=allegation_category2)
        OfficerAllegationFactory(allegation=pinboard_allegation1,
                                 officer=allegation_officer2,
                                 allegation_category=allegation_category3)
        OfficerAllegationFactory(allegation=pinboard_allegation2,
                                 officer=allegation_officer2,
                                 allegation_category=allegation_category3)
        OfficerAllegationFactory(allegation=allegation3,
                                 officer=trr_officer1,
                                 allegation_category=None)
        OfficerAllegationFactory(allegation=allegation4,
                                 officer=trr_officer1,
                                 allegation_category=allegation_category1)
        OfficerAllegationFactory(allegation=pinboard_allegation1,
                                 officer=trr_officer1,
                                 allegation_category=None)
        OfficerAllegationFactory(allegation=pinboard_allegation2,
                                 officer=trr_officer2,
                                 allegation_category=None)
        OfficerAllegationFactory(allegation=pinboard_allegation2,
                                 officer=trr_officer2,
                                 allegation_category=allegation_category1)
        OfficerAllegationFactory(allegation=allegation1,
                                 officer=pinboard_officer1,
                                 allegation_category=None)
        OfficerAllegationFactory(allegation=allegation2,
                                 officer=pinboard_officer1,
                                 allegation_category=allegation_category2)
        OfficerAllegationFactory(allegation=allegation1,
                                 officer=other_officer,
                                 allegation_category=allegation_category2)

        pinboard = PinboardFactory(trrs=(trr1, trr2),
                                   allegations=(pinboard_allegation1,
                                                pinboard_allegation2),
                                   officers=(pinboard_officer1,
                                             pinboard_officer2))
        expect(list(ComplaintSummaryQuery(pinboard).query())).to.eq([{
            'category':
            None,
            'count':
            4
        }, {
            'category':
            'Operation/Personnel Violations',
            'count':
            3
        }, {
            'category':
            'Illegal Search',
            'count':
            2
        }, {
            'category':
            'Verbal Abuse',
            'count':
            2
        }])