Ejemplo n.º 1
0
    def test_is_empty(self):
        officer_1 = OfficerFactory(id=1)
        officer_2 = OfficerFactory(id=2)

        allegation_1 = AllegationFactory(crid='123abc')
        allegation_2 = AllegationFactory(crid='456def')

        trr_1 = TRRFactory(id=1, officer=OfficerFactory(id=3))
        trr_2 = TRRFactory(id=2, officer=OfficerFactory(id=4))

        pinboard_full = PinboardFactory(
            officers=(officer_1, officer_2),
            allegations=(allegation_1, allegation_2),
            trrs=(trr_1, trr_2),
        )

        pinboard_with_officers = PinboardFactory(officers=(officer_1,
                                                           officer_2), )

        pinboard_with_allegations = PinboardFactory(
            allegations=(allegation_1, allegation_2), )

        pinboard_with_trrs = PinboardFactory(trrs=(trr_1, trr_2), )

        pinboard_empty = PinboardFactory()

        expect(pinboard_full.is_empty).to.be.false()
        expect(pinboard_with_officers.is_empty).to.be.false()
        expect(pinboard_with_allegations.is_empty).to.be.false()
        expect(pinboard_with_trrs.is_empty).to.be.false()
        expect(pinboard_empty.is_empty).to.be.true()
Ejemplo n.º 2
0
 def test_clone_duplicate_with_copy_copy_number_in_title(self):
     pinboard = PinboardFactory(
         title='Pinboard title copy copy',
         description='Pinboard title',
         officers=(),
         allegations=(),
         trrs=(),
     )
     cloned_pinboard = pinboard.clone(is_duplicated=True)
     expect(cloned_pinboard.title).to.eq('Pinboard title copy copy 2')
Ejemplo n.º 3
0
    def test_str(self):
        pinboard = PinboardFactory(
            id='abcd1234',
            title='Pinboard title',
        )

        pinboard_no_title = PinboardFactory(
            id='dcba4321',
            title='',
        )

        expect(str(pinboard)).to.eq('abcd1234 - Pinboard title')
        expect(str(pinboard_no_title)).to.eq('dcba4321')
Ejemplo n.º 4
0
    def test_get_queryset_with_search_term(self):
        PinboardFactory(id='66ef1560', title='', description='')
        PinboardFactory(id='66ff1560', title='', description='')
        PinboardFactory(id='67ef1560', title='', description='')
        PinboardFactory(id='67ff1560', title='66 officers', description='')
        PinboardFactory(id='67af1560',
                        title='Repeater',
                        description='66 officers')

        queryset, use_distinct = self.attachment_admin.get_search_results(
            self.request, None, '66')
        expect({pinboard.id
                for pinboard in queryset
                }).to.eq({'66ef1560', '66ff1560', '67ff1560'})
        expect(use_distinct).to.be.true()
Ejemplo n.º 5
0
    def test_relevant_complaints_via_accused_officers(self):
        pinned_officer_1 = OfficerFactory(id=1)
        pinned_officer_2 = OfficerFactory(id=2)
        pinned_officer_3 = OfficerFactory(id=3)
        relevant_allegation_1 = AllegationFactory(crid='1',
                                                  incident_date=datetime(
                                                      2002,
                                                      2,
                                                      21,
                                                      tzinfo=pytz.utc))
        relevant_allegation_2 = AllegationFactory(crid='2',
                                                  incident_date=datetime(
                                                      2002,
                                                      2,
                                                      22,
                                                      tzinfo=pytz.utc))
        AllegationFactory(crid='not relevant')
        pinboard = PinboardFactory(
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set(
            [pinned_officer_1, pinned_officer_2, pinned_officer_3])
        OfficerAllegationFactory(officer=pinned_officer_1,
                                 allegation=relevant_allegation_1)
        OfficerAllegationFactory(officer=pinned_officer_2,
                                 allegation=relevant_allegation_2)

        relevant_complaints = list(pinboard.relevant_complaints)

        expect(relevant_complaints).to.have.length(2)
        expect(relevant_complaints[0].crid).to.eq('2')
        expect(relevant_complaints[1].crid).to.eq('1')
    def test_serialization_with_non_existing_pinned_item_ids(self):
        pinned_officer = OfficerFactory(id=1)
        pinned_allegation = AllegationFactory(crid='123abc')
        pinboard = PinboardFactory(
            id='66ef1560',
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set([pinned_officer])
        pinboard.allegations.set([pinned_allegation])

        pinboard_data = {
            'id': '123abc',
            'title': 'title',
            'description': 'description',
            'officer_ids': [1, 2, 4, 5],
            'crids': ['xyz789', '123abc', '456def'],
            'trr_ids': [0, 3, 1],
        }

        serializer = PinboardDetailSerializer(data=pinboard_data)
        expect(serializer.is_valid()).to.be.true()
        expect(serializer.data).to.eq({
            'title': 'title',
            'description': 'description',
            'officer_ids': [1],
            'crids': ['123abc'],
            'trr_ids': [],
            'not_found_items': {
                'officer_ids': [2, 4, 5],
                'crids': ['xyz789', '456def'],
                'trr_ids': [0, 3, 1],
            }
        })
    def test_serialization_with_data(self):
        pinned_officer = OfficerFactory(id=1)
        pinned_allegation = AllegationFactory(crid='1')
        pinboard = PinboardFactory(
            id='66ef1560',
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set([pinned_officer])
        pinboard.allegations.set([pinned_allegation])

        pinboard_data = {
            'id': '123abc',
            'title': 'title',
            'description': 'description',
            'officer_ids': [1],
            'crids': ['1'],
            'trr_ids': [],
        }

        serializer = PinboardDetailSerializer(data=pinboard_data)
        expect(serializer.is_valid()).to.be.true()
        expect(serializer.data).to.eq({
            'title': 'title',
            'description': 'description',
            'officer_ids': [1],
            'crids': ['1'],
            'trr_ids': [],
        })
Ejemplo n.º 8
0
    def test_relevant_documents_not_showing_audios_and_videos(self):
        pinned_officer_1 = OfficerFactory(id=1)
        relevant_allegation = AllegationFactory(crid='1',
                                                incident_date=datetime(
                                                    2002,
                                                    2,
                                                    21,
                                                    tzinfo=pytz.utc))
        OfficerAllegationFactory(officer=pinned_officer_1,
                                 allegation=relevant_allegation)
        AttachmentFileFactory(file_type='document',
                              allegation=relevant_allegation,
                              show=True)
        AttachmentFileFactory(file_type='document',
                              allegation=relevant_allegation,
                              show=True)
        AttachmentFileFactory(file_type='audio',
                              allegation=relevant_allegation,
                              show=True)
        AttachmentFileFactory(file_type='video',
                              allegation=relevant_allegation,
                              show=True)

        pinboard = PinboardFactory(
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set([pinned_officer_1])

        relevant_documents = list(pinboard.relevant_documents)

        expect(relevant_documents).to.have.length(2)
        expect(relevant_documents[0].file_type).to.eq('document')
        expect(relevant_documents[1].file_type).to.eq('document')
    def test_str(self):
        pinboard = PinboardFactory(
            title='Example pinboard 1',
            description='Example pinboard 1',
        )
        example_pinboard = ExamplePinboardFactory(pinboard=pinboard)

        expect(str(example_pinboard)).to.eq(str(pinboard))
Ejemplo n.º 10
0
 def test_trr_ids(self):
     pinned_trr_1 = TRRFactory(id=1)
     pinned_trr_2 = TRRFactory(id=2)
     pinboard = PinboardFactory(
         title='Test pinboard',
         description='Test description',
     )
     pinboard.trrs.set([pinned_trr_1, pinned_trr_2])
     expect(list(pinboard.trr_ids)).to.eq([1, 2])
Ejemplo n.º 11
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
                    },
                })
Ejemplo n.º 12
0
 def test_crids(self):
     pinned_allegation_1 = AllegationFactory(crid='1')
     pinned_allegation_2 = AllegationFactory(crid='2')
     pinboard = PinboardFactory(
         title='Test pinboard',
         description='Test description',
     )
     pinboard.allegations.set([pinned_allegation_1, pinned_allegation_2])
     expect(list(pinboard.crids)).to.eq(['1', '2'])
Ejemplo n.º 13
0
    def test_relevant_documents_via_accused_officers(self):
        pinned_officer_1 = OfficerFactory(id=1)
        pinned_officer_2 = OfficerFactory(id=2)
        pinned_officer_3 = OfficerFactory(id=3)
        relevant_allegation_1 = AllegationFactory(crid='1',
                                                  incident_date=datetime(
                                                      2002,
                                                      2,
                                                      21,
                                                      tzinfo=pytz.utc))
        relevant_allegation_2 = AllegationFactory(crid='2',
                                                  incident_date=datetime(
                                                      2002,
                                                      2,
                                                      22,
                                                      tzinfo=pytz.utc))
        not_relevant_allegation = AllegationFactory(crid='not relevant')
        relevant_document_1 = AttachmentFileFactory(
            id=1,
            file_type='document',
            allegation=relevant_allegation_1,
            show=True)
        relevant_document_2 = AttachmentFileFactory(
            id=2,
            file_type='document',
            allegation=relevant_allegation_2,
            show=True)
        AttachmentFileFactory(id=998,
                              file_type='document',
                              title='relevant but not show',
                              allegation=relevant_allegation_1,
                              show=False)
        AttachmentFileFactory(id=999,
                              file_type='document',
                              title='not relevant',
                              allegation=not_relevant_allegation,
                              show=True)

        pinboard = PinboardFactory(
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set(
            [pinned_officer_1, pinned_officer_2, pinned_officer_3])
        OfficerAllegationFactory(officer=pinned_officer_1,
                                 allegation=relevant_allegation_1)
        OfficerAllegationFactory(officer=pinned_officer_2,
                                 allegation=relevant_allegation_2)

        relevant_documents = list(pinboard.relevant_documents)

        expect(relevant_documents).to.have.length(2)
        expect(relevant_documents[0].id).to.eq(relevant_document_2.id)
        expect(relevant_documents[0].allegation.crid).to.eq('2')
        expect(relevant_documents[1].id).to.eq(relevant_document_1.id)
        expect(relevant_documents[1].allegation.crid).to.eq('1')
Ejemplo n.º 14
0
    def test_relevant_complaints_order_officers(self):
        pinned_officer_1 = OfficerFactory(id=1, allegation_count=3)
        pinned_officer_2 = OfficerFactory(id=2)
        pinned_officer_3 = OfficerFactory(id=3)
        officer_4 = OfficerFactory(id=4, allegation_count=2)
        officer_5 = OfficerFactory(id=5, allegation_count=4)
        relevant_allegation_1 = AllegationFactory(crid='1',
                                                  incident_date=datetime(
                                                      2002,
                                                      2,
                                                      21,
                                                      tzinfo=pytz.utc))
        relevant_allegation_2 = AllegationFactory(crid='2',
                                                  incident_date=datetime(
                                                      2002,
                                                      2,
                                                      22,
                                                      tzinfo=pytz.utc))
        AllegationFactory(crid='not relevant')
        pinboard = PinboardFactory(
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set(
            [pinned_officer_1, pinned_officer_2, pinned_officer_3])
        OfficerAllegationFactory(officer=pinned_officer_1,
                                 allegation=relevant_allegation_1)
        OfficerAllegationFactory(officer=officer_4,
                                 allegation=relevant_allegation_1)
        OfficerAllegationFactory(officer=officer_5,
                                 allegation=relevant_allegation_1)
        OfficerAllegationFactory(officer=pinned_officer_2,
                                 allegation=relevant_allegation_2)

        relevant_complaints = list(pinboard.relevant_complaints)

        expect(relevant_complaints).to.have.length(2)
        expect(relevant_complaints[0].crid).to.eq('2')
        expect(relevant_complaints[0].prefetched_officer_allegations
               ).to.have.length(1)
        expect(relevant_complaints[0].prefetched_officer_allegations[0].
               officer.id).to.eq(2)

        expect(relevant_complaints[1].crid).to.eq('1')
        expect(relevant_complaints[1].prefetched_officer_allegations
               ).to.have.length(3)
        expect(relevant_complaints[1].prefetched_officer_allegations[0].
               officer.id).to.eq(5)
        expect(relevant_complaints[1].prefetched_officer_allegations[1].
               officer.id).to.eq(1)
        expect(relevant_complaints[1].prefetched_officer_allegations[2].
               officer.id).to.eq(4)
Ejemplo n.º 15
0
    def test_query(self):
        allegation_officer1 = OfficerFactory()
        allegation_officer2 = OfficerFactory()
        trr_officer_1 = OfficerFactory()
        trr_officer_2 = OfficerFactory()
        pinboard_officer1 = OfficerFactory()
        pinboard_officer2 = OfficerFactory()
        other_officer = OfficerFactory()

        pinboard_allegation = AllegationFactory()
        OfficerAllegationFactory(allegation=pinboard_allegation,
                                 officer=allegation_officer1)
        OfficerAllegationFactory(allegation=pinboard_allegation,
                                 officer=allegation_officer2)

        pinboard_trr1 = TRRFactory(officer=trr_officer_1)
        pinboard_trr2 = TRRFactory(officer=trr_officer_2)
        trr1 = TRRFactory(officer=allegation_officer1)
        trr2 = TRRFactory(officer=allegation_officer2)
        trr3 = TRRFactory(officer=allegation_officer2)
        trr4 = TRRFactory(officer=allegation_officer2)
        trr5 = TRRFactory(officer=pinboard_officer1)
        TRRFactory(officer=pinboard_officer2)
        other_trr1 = TRRFactory(officer=other_officer)
        other_trr2 = TRRFactory(officer=other_officer)

        ActionResponseFactory(trr=pinboard_trr1, force_type=None)
        ActionResponseFactory(trr=pinboard_trr2, force_type='Verbal Commands')
        ActionResponseFactory(trr=trr1, force_type='Physical Force - Stunning')
        ActionResponseFactory(trr=trr1, force_type=None)
        ActionResponseFactory(trr=trr2, force_type='Physical Force - Stunning')
        ActionResponseFactory(trr=trr3, force_type='Verbal Commands')
        ActionResponseFactory(trr=trr4, force_type='Physical Force - Stunning')
        ActionResponseFactory(trr=trr5, force_type='Physical Force - Stunning')
        ActionResponseFactory(trr=other_trr1, force_type='Taser')
        ActionResponseFactory(trr=other_trr2, force_type='Chemical')

        pinboard = PinboardFactory(trrs=(pinboard_trr1, pinboard_trr2),
                                   allegations=(pinboard_allegation, ),
                                   officers=(pinboard_officer1,
                                             pinboard_officer2))
        expect(list(TrrSummaryQuery(pinboard).query())).to.eq([{
            'force_type': 'Physical Force - Stunning',
            'count': 4
        }, {
            'force_type': 'Verbal Commands',
            'count': 2
        }, {
            'force_type': None,
            'count': 2
        }])
Ejemplo n.º 16
0
    def test_clone(self):
        officer_1 = OfficerFactory(id=1)
        officer_2 = OfficerFactory(id=2)

        allegation_1 = AllegationFactory(crid='123abc')
        allegation_2 = AllegationFactory(crid='456def')

        trr_1 = TRRFactory(id=1, officer=OfficerFactory(id=3))
        trr_2 = TRRFactory(id=2, officer=OfficerFactory(id=4))

        pinboard = PinboardFactory(
            title='Pinboard title',
            description='Pinboard title',
            officers=(officer_1, officer_2),
            allegations=(allegation_1, allegation_2),
            trrs=(trr_1, trr_2),
        )
        cloned_pinboard = pinboard.clone()
        cloned_pinboard.refresh_from_db()

        officers = set(pinboard.officers.all().values_list('id', flat=True))
        allegations = set(pinboard.allegations.all().values_list('crid',
                                                                 flat=True))
        trrs = set(pinboard.trrs.all().values_list('id', flat=True))

        cloned_officers = set(cloned_pinboard.officers.all().values_list(
            'id', flat=True))
        cloned_allegations = set(cloned_pinboard.allegations.all().values_list(
            'crid', flat=True))
        cloned_trrs = set(cloned_pinboard.trrs.all().values_list('id',
                                                                 flat=True))

        expect(pinboard.title).to.eq(cloned_pinboard.title)
        expect(pinboard.description).to.eq(cloned_pinboard.description)
        expect(officers).to.eq(cloned_officers)
        expect(allegations).to.eq(cloned_allegations)
        expect(trrs).to.eq(cloned_trrs)
        expect(cloned_pinboard.source_pinboard).to.eq(pinboard)
Ejemplo n.º 17
0
    def test_relevant_complaints_via_investigator(self):
        pinned_investigator_1 = OfficerFactory(id=1)
        pinned_investigator_2 = OfficerFactory(id=2)
        pinned_investigator_3 = OfficerFactory(id=3)
        not_relevant_officer = OfficerFactory(id=999)
        relevant_allegation_1 = AllegationFactory(crid='1',
                                                  incident_date=datetime(
                                                      2002,
                                                      2,
                                                      21,
                                                      tzinfo=pytz.utc))
        relevant_allegation_2 = AllegationFactory(crid='2',
                                                  incident_date=datetime(
                                                      2002,
                                                      2,
                                                      22,
                                                      tzinfo=pytz.utc))
        relevant_allegation_3 = AllegationFactory(crid='3',
                                                  incident_date=datetime(
                                                      2002,
                                                      2,
                                                      23,
                                                      tzinfo=pytz.utc))
        not_relevant_allegation = AllegationFactory(crid='999')
        pinboard = PinboardFactory(
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set([
            pinned_investigator_1, pinned_investigator_2, pinned_investigator_3
        ])
        InvestigatorAllegationFactory(
            investigator__officer=pinned_investigator_1,
            allegation=relevant_allegation_1)
        InvestigatorAllegationFactory(
            investigator__officer=pinned_investigator_2,
            allegation=relevant_allegation_2)
        InvestigatorAllegationFactory(
            investigator__officer=pinned_investigator_3,
            allegation=relevant_allegation_3)
        InvestigatorAllegationFactory(
            investigator__officer=not_relevant_officer,
            allegation=not_relevant_allegation)

        relevant_complaints = list(pinboard.relevant_complaints)

        expect(relevant_complaints).to.have.length(3)
        expect(relevant_complaints[0].crid).to.eq('3')
        expect(relevant_complaints[1].crid).to.eq('2')
        expect(relevant_complaints[2].crid).to.eq('1')
Ejemplo n.º 18
0
    def test_query(self):
        allegation_officer1 = OfficerFactory(race='White', gender='F')
        allegation_officer2 = OfficerFactory(race='Hispanic', gender='M')
        trr_officer_1 = OfficerFactory(race='White', gender='M')
        trr_officer_2 = OfficerFactory(race='', gender='M')
        pinboard_officer1 = OfficerFactory(race='White', gender='M')
        pinboard_officer2 = OfficerFactory(race='Black', gender='')
        pinboard_officer3 = OfficerFactory(race='Asian/Pacific', gender='X')
        OfficerFactory(race='White', gender='')
        OfficerFactory(race='Black', gender='')

        pinboard_allegation = AllegationFactory()
        OfficerAllegationFactory(allegation=pinboard_allegation,
                                 officer=allegation_officer1)
        OfficerAllegationFactory(allegation=pinboard_allegation,
                                 officer=allegation_officer2)

        pinboard_trr1 = TRRFactory(officer=trr_officer_1)
        pinboard_trr2 = TRRFactory(officer=trr_officer_2)

        pinboard = PinboardFactory(trrs=(pinboard_trr1, pinboard_trr2),
                                   allegations=(pinboard_allegation, ),
                                   officers=(pinboard_officer1,
                                             pinboard_officer2,
                                             pinboard_officer3))
        query_results = dict(OfficersSummaryQuery(pinboard).query())
        expect(list(query_results['race'])).to.eq([{
            'race': 'Black',
            'percentage': 0.14
        }, {
            'race': 'White',
            'percentage': 0.43
        }, {
            'race': 'Hispanic',
            'percentage': 0.14
        }, {
            'race': 'Other',
            'percentage': 0.29
        }])
        expect(list(query_results['gender'])).to.eq([{
            'gender': 'M',
            'percentage': 0.57
        }, {
            'gender': 'F',
            'percentage': 0.14
        }, {
            'gender': 'Unknown',
            'percentage': 0.29
        }])
Ejemplo n.º 19
0
    def test_serialization(self):
        with freeze_time(datetime(2018, 4, 3, 12, 0, 10, tzinfo=pytz.utc)):
            pinboard = PinboardFactory(
                id='eeee1111',
                title='Pinboard 1',
            )

        expect(PinboardSerializer(pinboard).data).to.eq({
            'id':
            'eeee1111',
            'title':
            'Pinboard 1',
            'created_at':
            '2018-04-03',
        })
Ejemplo n.º 20
0
    def test_relevant_complaints_filter_out_pinned_allegations(self):
        pinned_officer_1 = OfficerFactory(id=1)
        pinned_officer_2 = OfficerFactory(id=2)
        pinned_allegation_1 = AllegationFactory(crid='1')
        pinned_allegation_2 = AllegationFactory(crid='2')
        pinboard = PinboardFactory(
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set([pinned_officer_1, pinned_officer_2])
        pinboard.allegations.set([pinned_allegation_1, pinned_allegation_2])
        OfficerAllegationFactory(officer=pinned_officer_1,
                                 allegation=pinned_allegation_1)
        OfficerAllegationFactory(officer=pinned_officer_2,
                                 allegation=pinned_allegation_2)
        AllegationFactory(crid='not relevant')

        expect(list(pinboard.relevant_complaints)).to.have.length(0)
Ejemplo n.º 21
0
    def test_example_pinboards(self):
        officer_1 = OfficerFactory(id=1)
        officer_2 = OfficerFactory(id=2)

        allegation_1 = AllegationFactory(crid='123abc')
        allegation_2 = AllegationFactory(crid='456def')

        trr_1 = TRRFactory(id=1, officer=OfficerFactory(id=3))
        trr_2 = TRRFactory(id=2, officer=OfficerFactory(id=4))

        pinboard_full = PinboardFactory(
            officers=(officer_1, officer_2),
            allegations=(allegation_1, allegation_2),
            trrs=(trr_1, trr_2),
        )

        pinboard_with_officers = PinboardFactory(officers=(officer_1,
                                                           officer_2), )

        pinboard_with_allegations = PinboardFactory(
            allegations=(allegation_1, allegation_2), )

        pinboard_with_trrs = PinboardFactory(trrs=(trr_1, trr_2), )

        pinboard_empty = PinboardFactory()

        e_pinboard_1 = PinboardFactory(
            title='Example pinboard 1',
            description='Example pinboard 1',
        )
        example_pinboard_1 = ExamplePinboardFactory(pinboard=e_pinboard_1)

        e_pinboard_2 = PinboardFactory(
            title='Example pinboard 1',
            description='Example pinboard 1',
        )
        example_pinboard_2 = ExamplePinboardFactory(pinboard=e_pinboard_2)

        expect(pinboard_empty.example_pinboards).to.have.length(2)
        expect(pinboard_empty.example_pinboards).to.contain(example_pinboard_1)
        expect(pinboard_empty.example_pinboards).to.contain(example_pinboard_2)

        expect(pinboard_with_officers.example_pinboards).to.be.none()
        expect(pinboard_with_allegations.example_pinboards).to.be.none()
        expect(pinboard_with_trrs.example_pinboards).to.be.none()
        expect(pinboard_full.example_pinboards).to.be.none()
Ejemplo n.º 22
0
    def test_relevant_complaints_via_police_witnesses(self):
        pinned_officer_1 = OfficerFactory(id=1)
        pinned_officer_2 = OfficerFactory(id=2)
        not_relevant_officer = OfficerFactory(id=999)
        relevant_allegation_11 = AllegationFactory(crid='11',
                                                   incident_date=datetime(
                                                       2002,
                                                       2,
                                                       21,
                                                       tzinfo=pytz.utc))
        relevant_allegation_12 = AllegationFactory(crid='12',
                                                   incident_date=datetime(
                                                       2002,
                                                       2,
                                                       22,
                                                       tzinfo=pytz.utc))
        relevant_allegation_21 = AllegationFactory(crid='21',
                                                   incident_date=datetime(
                                                       2002,
                                                       2,
                                                       23,
                                                       tzinfo=pytz.utc))
        not_relevant_allegation = AllegationFactory(crid='999')
        pinboard = PinboardFactory(
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set([pinned_officer_1, pinned_officer_2])
        PoliceWitnessFactory(allegation=relevant_allegation_11,
                             officer=pinned_officer_1)
        PoliceWitnessFactory(allegation=relevant_allegation_12,
                             officer=pinned_officer_1)
        PoliceWitnessFactory(allegation=relevant_allegation_21,
                             officer=pinned_officer_2)
        PoliceWitnessFactory(allegation=not_relevant_allegation,
                             officer=not_relevant_officer)

        relevant_complaints = list(pinboard.relevant_complaints)

        expect(relevant_complaints).to.have.length(3)
        expect(relevant_complaints[0].crid).to.eq('21')
        expect(relevant_complaints[1].crid).to.eq('12')
        expect(relevant_complaints[2].crid).to.eq('11')
Ejemplo n.º 23
0
    def test_serialization(self):
        pinned_officer = OfficerFactory(id=1)
        pinned_allegation = AllegationFactory(crid='1')
        with freeze_time(datetime(2018, 4, 3, 12, 0, 10, tzinfo=pytz.utc)):
            pinboard = PinboardFactory(
                id='eeee1111',
                title='Pinboard 1',
            )
        pinboard.officers.set([pinned_officer])
        pinboard.allegations.set([pinned_allegation])

        expect(ListPinboardDetailSerializer(pinboard).data).to.eq({
            'id':
            'eeee1111',
            'title':
            'Pinboard 1',
            'created_at':
            '2018-04-03',
            'officer_ids': [1],
            'crids': ['1'],
            'trr_ids': [],
        })
    def test_serialization_without_data(self):
        pinned_officer = OfficerFactory(id=1)
        pinned_allegation = AllegationFactory(crid='1')
        pinboard = PinboardFactory(
            id='66ef1560',
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set([pinned_officer])
        pinboard.allegations.set([pinned_allegation])

        expect(PinboardDetailSerializer(pinboard).data).to.eq({
            'id':
            '66ef1560',
            'title':
            'Test pinboard',
            'description':
            'Test description',
            'officer_ids': [1],
            'crids': ['1'],
            'trr_ids': [],
        })
Ejemplo n.º 25
0
    def test_serialization(self):
        with freeze_time(datetime(2018, 4, 3, 12, 0, 10, tzinfo=pytz.utc)):
            officer_1 = OfficerFactory(
                first_name='Jerome',
                last_name='Finnigan',
                allegation_count=0,
                complaint_percentile='0.0000',
                trr_percentile='0.0000',
                civilian_allegation_percentile='0.0000',
                internal_allegation_percentile='0.0000',
            )
            officer_2 = OfficerFactory(
                first_name='Joe',
                last_name='Parker',
                allegation_count=5,
                complaint_percentile='50.0000',
                trr_percentile='50.0000',
                civilian_allegation_percentile='50.0000',
                internal_allegation_percentile='50.0000',
            )
            officer_3 = OfficerFactory(
                first_name='John',
                last_name='Hurley',
                allegation_count=10,
                complaint_percentile='99.9999',
                trr_percentile='99.9999',
                civilian_allegation_percentile='99.9999',
                internal_allegation_percentile='99.9999',
            )
            allegation_1 = AllegationFactory(
                crid='111111',
                most_common_category=AllegationCategoryFactory(
                    category='Use Of Force'),
                incident_date=datetime(2001, 1, 1, tzinfo=pytz.utc),
            )
            allegation_2 = AllegationFactory(
                crid='222222',
                incident_date=datetime(2002, 2, 2, tzinfo=pytz.utc),
            )
            trr_1 = TRRFactory(id='111',
                               trr_datetime=datetime(2001,
                                                     1,
                                                     1,
                                                     tzinfo=pytz.utc))
            ActionResponseFactory(trr=trr_1, force_type='Use Of Force')
            trr_2 = TRRFactory(id='222',
                               trr_datetime=datetime(2002,
                                                     2,
                                                     2,
                                                     tzinfo=pytz.utc))
            pinboard = PinboardFactory(
                id='aaaa1111',
                title='Pinboard 1',
                description='Pinboard description 1',
                officers=[officer_1, officer_2, officer_3],
                allegations=[allegation_1, allegation_2],
                trrs=[trr_1, trr_2],
            )
            setattr(pinboard, 'child_pinboard_count', 2)

            expect(PinboardSerializer(pinboard).data).to.eq({
                'id':
                'aaaa1111',
                'title':
                'Pinboard 1',
                'description':
                'Pinboard description 1',
                'created_at':
                '2018-04-03T12:00:10Z',
                'officers_count':
                3,
                'allegations_count':
                2,
                'trrs_count':
                2,
                'child_pinboard_count':
                2,
                'officers': [
                    {
                        'id': officer_3.id,
                        'name': 'John Hurley',
                        'count': 10,
                        'percentile_allegation': '99.9999',
                        'percentile_trr': '99.9999',
                        'percentile_allegation_civilian': '99.9999',
                        'percentile_allegation_internal': '99.9999',
                    },
                    {
                        'id': officer_2.id,
                        'name': 'Joe Parker',
                        'count': 5,
                        'percentile_allegation': '50.0000',
                        'percentile_trr': '50.0000',
                        'percentile_allegation_civilian': '50.0000',
                        'percentile_allegation_internal': '50.0000',
                    },
                    {
                        'id': officer_1.id,
                        'name': 'Jerome Finnigan',
                        'count': 0,
                        'percentile_allegation': '0.0000',
                        'percentile_trr': '0.0000',
                        'percentile_allegation_civilian': '0.0000',
                        'percentile_allegation_internal': '0.0000',
                    },
                ],
                'allegations': [
                    {
                        'crid': '222222',
                        'category': 'Unknown',
                        'incident_date': '2002-02-02',
                    },
                    {
                        'crid': '111111',
                        'category': 'Use Of Force',
                        'incident_date': '2001-01-01',
                    },
                ],
                'trrs': [{
                    'id': 222,
                    'trr_datetime': '2002-02-02',
                    'category': 'Unknown',
                }, {
                    'id': 111,
                    'trr_datetime': '2001-01-01',
                    'category': 'Use Of Force',
                }],
            })
    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',
            incident_date=datetime(2002, 2, 21, tzinfo=pytz.utc),
            most_common_category=AllegationCategoryFactory(
                category='Operation/Personnel Violations'),
            point=Point([0.01, 0.02]),
        )
        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',
                    '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,
                    },
                })
        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': {
                    '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,
                    },
                }
            })
Ejemplo n.º 27
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
        }])
Ejemplo n.º 28
0
    def test_query(self):
        trr_officer_1 = OfficerFactory()
        trr_officer_2 = OfficerFactory()
        pinboard_officer = OfficerFactory()
        other_officer = OfficerFactory()

        pinboard_allegation = AllegationFactory()
        allegation1 = AllegationFactory()
        allegation2 = AllegationFactory()
        allegation3 = AllegationFactory()
        allegation4 = AllegationFactory()
        other_allegation = AllegationFactory()

        OfficerAllegationFactory(allegation=pinboard_allegation,
                                 officer=other_officer)
        OfficerAllegationFactory(allegation=allegation1, officer=trr_officer_1)
        OfficerAllegationFactory(allegation=allegation2, officer=trr_officer_2)
        OfficerAllegationFactory(allegation=allegation3, officer=trr_officer_2)
        OfficerAllegationFactory(allegation=allegation4,
                                 officer=pinboard_officer)

        ComplainantFactory(allegation=pinboard_allegation,
                           gender='M',
                           race='White')
        ComplainantFactory(allegation=pinboard_allegation,
                           gender='F',
                           race='White')
        ComplainantFactory(allegation=pinboard_allegation,
                           gender='F',
                           race='White')
        ComplainantFactory(allegation=pinboard_allegation,
                           gender='F',
                           race='Black')
        ComplainantFactory(allegation=allegation1, gender='X', race='Black')
        ComplainantFactory(allegation=allegation1, gender='F', race='Black')
        ComplainantFactory(allegation=allegation1, gender='X', race='')
        ComplainantFactory(allegation=allegation1,
                           gender='',
                           race='Asian/Pacific')
        ComplainantFactory(allegation=allegation3, gender='F', race='Hispanic')
        ComplainantFactory(allegation=allegation4, gender='M', race='White')
        ComplainantFactory(allegation=other_allegation, gender='M', race='')
        ComplainantFactory(allegation=other_allegation,
                           gender='F',
                           race='Black')

        pinboard_trr1 = TRRFactory(officer=trr_officer_1)
        pinboard_trr2 = TRRFactory(officer=trr_officer_2)

        pinboard = PinboardFactory(trrs=(pinboard_trr1, pinboard_trr2),
                                   allegations=(pinboard_allegation, ),
                                   officers=(pinboard_officer, ))
        query_results = dict(ComplainantsSummaryQuery(pinboard).query())
        expect(list(query_results['race'])).to.eq([{
            'race': 'Black',
            'percentage': 0.3
        }, {
            'race': 'White',
            'percentage': 0.4
        }, {
            'race': 'Hispanic',
            'percentage': 0.1
        }, {
            'race': 'Other',
            'percentage': 0.2
        }])
        expect(list(query_results['gender'])).to.eq([{
            'gender': 'M',
            'percentage': 0.2
        }, {
            'gender': 'F',
            'percentage': 0.5
        }, {
            'gender': 'Unknown',
            'percentage': 0.3
        }])
Ejemplo n.º 29
0
    def test_relevant_complaints_coaccusal_count_via_trr(self):
        officer_coaccusal_11 = OfficerFactory(id=11)
        officer_coaccusal_21 = OfficerFactory(id=21)
        OfficerFactory(id=99, first_name='Not Relevant', last_name='Officer')

        pinned_officer_1 = OfficerFactory(id=1)
        pinned_officer_2 = OfficerFactory(id=2)
        pinned_allegation_1 = AllegationFactory(crid='1')
        pinned_allegation_2 = AllegationFactory(crid='2')
        pinned_trr_1 = TRRFactory(officer__id=77)
        pinned_trr_2 = TRRFactory(officer=officer_coaccusal_11)
        pinboard = PinboardFactory(
            title='Test pinboard',
            description='Test description',
        )
        pinboard.officers.set([pinned_officer_1, pinned_officer_2])
        pinboard.allegations.set([pinned_allegation_1, pinned_allegation_2])
        pinboard.trrs.set([pinned_trr_1, pinned_trr_2])
        not_relevant_allegation = AllegationFactory(crid='999')

        allegation_11 = AllegationFactory(crid='11')
        allegation_12 = AllegationFactory(crid='12')
        allegation_13 = AllegationFactory(crid='13')
        allegation_14 = AllegationFactory(crid='14')
        OfficerAllegationFactory(allegation=allegation_11,
                                 officer=pinned_officer_1)
        OfficerAllegationFactory(allegation=allegation_12,
                                 officer=pinned_officer_1)
        OfficerAllegationFactory(allegation=allegation_13,
                                 officer=pinned_officer_1)
        OfficerAllegationFactory(allegation=allegation_14,
                                 officer=pinned_officer_1)
        OfficerAllegationFactory(allegation=allegation_11,
                                 officer=officer_coaccusal_11)
        OfficerAllegationFactory(allegation=allegation_12,
                                 officer=officer_coaccusal_11)
        OfficerAllegationFactory(allegation=allegation_13,
                                 officer=officer_coaccusal_11)
        OfficerAllegationFactory(allegation=allegation_14,
                                 officer=officer_coaccusal_11)
        OfficerAllegationFactory(allegation=not_relevant_allegation,
                                 officer=officer_coaccusal_11)

        allegation_21 = AllegationFactory(crid='21')
        allegation_22 = AllegationFactory(crid='22')
        allegation_23 = AllegationFactory(crid='23')
        OfficerAllegationFactory(allegation=allegation_21,
                                 officer=pinned_officer_2)
        OfficerAllegationFactory(allegation=allegation_22,
                                 officer=pinned_officer_2)
        OfficerAllegationFactory(allegation=allegation_23,
                                 officer=pinned_officer_2)
        OfficerAllegationFactory(allegation=allegation_21,
                                 officer=officer_coaccusal_21)
        OfficerAllegationFactory(allegation=allegation_22,
                                 officer=officer_coaccusal_21)
        OfficerAllegationFactory(allegation=allegation_23,
                                 officer=officer_coaccusal_21)
        OfficerAllegationFactory(allegation=not_relevant_allegation,
                                 officer=officer_coaccusal_21)

        allegation_coaccusal_12 = OfficerFactory(id=12)
        allegation_coaccusal_22 = OfficerFactory(id=22)
        OfficerAllegationFactory(allegation=pinned_allegation_1,
                                 officer=allegation_coaccusal_12)
        OfficerAllegationFactory(allegation=pinned_allegation_2,
                                 officer=allegation_coaccusal_12)
        OfficerAllegationFactory(allegation=not_relevant_allegation,
                                 officer=allegation_coaccusal_12)
        OfficerAllegationFactory(allegation=pinned_allegation_2,
                                 officer=allegation_coaccusal_22)
        OfficerAllegationFactory(allegation=not_relevant_allegation,
                                 officer=allegation_coaccusal_22)

        relevant_coaccusals = list(pinboard.relevant_coaccusals)

        expect(relevant_coaccusals).to.have.length(5)
        expect(relevant_coaccusals[0].id).to.eq(11)
        expect(relevant_coaccusals[0].coaccusal_count).to.eq(5)
        expect(relevant_coaccusals[1].id).to.eq(21)
        expect(relevant_coaccusals[1].coaccusal_count).to.eq(3)
        expect(relevant_coaccusals[2].id).to.eq(12)
        expect(relevant_coaccusals[2].coaccusal_count).to.eq(2)
        expect({
            relevant_coaccusal.id
            for relevant_coaccusal in relevant_coaccusals[3:5]
        }).to.eq({22, 77})
        expect(relevant_coaccusals[3].coaccusal_count).to.eq(1)
        expect(relevant_coaccusals[4].coaccusal_count).to.eq(1)
Ejemplo n.º 30
0
    def test_all_officers(self):
        officer_1 = OfficerFactory(id=8562,
                                   first_name='Jerome',
                                   last_name='Finnigan')
        officer_2 = OfficerFactory(id=8563,
                                   first_name='Edward',
                                   last_name='May')
        officer_3 = OfficerFactory(id=8564,
                                   first_name='Joe',
                                   last_name='Parker')
        officer_4 = OfficerFactory(id=8565,
                                   first_name='Jane',
                                   last_name='Marry')
        officer_5 = OfficerFactory(id=8566,
                                   first_name='John',
                                   last_name='Parker')
        officer_6 = OfficerFactory(id=8567,
                                   first_name='William',
                                   last_name='People')
        officer_7 = OfficerFactory(id=8568,
                                   first_name='Zin',
                                   last_name='Flagg')

        allegation_1 = AllegationFactory(crid='123',
                                         is_officer_complaint=False,
                                         incident_date=datetime(
                                             2005, 12, 31, tzinfo=pytz.utc))
        allegation_2 = AllegationFactory(crid='456',
                                         is_officer_complaint=True,
                                         incident_date=datetime(
                                             2006, 12, 31, tzinfo=pytz.utc))
        allegation_3 = AllegationFactory(crid='789',
                                         is_officer_complaint=False,
                                         incident_date=datetime(
                                             2007, 12, 31, tzinfo=pytz.utc))
        trr_1 = TRRFactory(id=1,
                           officer=officer_6,
                           trr_datetime=datetime(2008, 12, 31,
                                                 tzinfo=pytz.utc))
        trr_2 = TRRFactory(id=2,
                           officer=officer_7,
                           trr_datetime=datetime(2009, 12, 31,
                                                 tzinfo=pytz.utc))

        OfficerAllegationFactory(id=1,
                                 officer=officer_3,
                                 allegation=allegation_1)
        OfficerAllegationFactory(id=2,
                                 officer=officer_4,
                                 allegation=allegation_2)
        OfficerAllegationFactory(id=3,
                                 officer=officer_2,
                                 allegation=allegation_2)
        OfficerAllegationFactory(id=4,
                                 officer=officer_5,
                                 allegation=allegation_3)

        pinboard = PinboardFactory(description='abc', )

        pinboard.officers.set([officer_1, officer_2])
        pinboard.allegations.set([allegation_1, allegation_2])
        pinboard.trrs.set([trr_1, trr_2])

        expected_all_officers = [
            officer_2, officer_4, officer_1, officer_3, officer_6, officer_7
        ]

        expect(list(pinboard.all_officers)).to.eq(expected_all_officers)