コード例 #1
0
    def test_trr_timeline(self, trr_new_timeline_serializer_mock):
        officer = OfficerFactory(id=123, appointed_date=date(2001, 2, 3))

        trr_1 = TRRFactory(officer=officer, trr_datetime=datetime(2002, 1, 4, tzinfo=pytz.utc))
        trr_2 = TRRFactory(officer=officer, trr_datetime=datetime(2003, 1, 5, tzinfo=pytz.utc))

        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)._trr_timeline).to.eq([{'id': 1}, {'id': 2}])

        trr_timeline_queryset_arg = trr_new_timeline_serializer_mock.call_args[0][0]
        trr_1_arg, trr_2_arg = sorted(trr_timeline_queryset_arg, key=attrgetter('id'))

        expect(trr_1_arg.id).to.eq(trr_1.id)
        expect(trr_1_arg.unit_name).to.eq('001')
        expect(trr_1_arg.unit_description).to.eq('District 001')
        expect(trr_1_arg.rank_name).to.eq('Police Officer')

        expect(trr_2_arg.id).to.eq(trr_2.id)
        expect(trr_2_arg.unit_name).to.eq('002')
        expect(trr_2_arg.unit_description).to.eq('District 002')
        expect(trr_2_arg.rank_name).to.eq('Senior Police Officer')
コード例 #2
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()
コード例 #3
0
    def test_serialization(self):
        with freeze_time(datetime(2018, 4, 3, 12, 0, 10, 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))

            expect(TRRSerializer(trr_1).data).to.eq({
                'id': 111,
                'trr_datetime': '2001-01-01',
                'category': 'Use Of Force',
            })

            expect(TRRSerializer(trr_2).data).to.eq({
                'id': 222,
                'trr_datetime': '2002-02-02',
                'category': 'Unknown',
            })
コード例 #4
0
    def test_retrieve_single_search_date_officers_result(self):
        officer_1 = OfficerFactory(id=1,
                                   first_name='Jerome',
                                   last_name='Finnigan')
        officer_2 = OfficerFactory(id=2, first_name='Edward', last_name='May')
        officer_3 = OfficerFactory(id=3)
        officer_4 = OfficerFactory(id=4)

        allegation_1 = AllegationFactory(
            incident_date=datetime(2004, 10, 10, tzinfo=pytz.utc))
        allegation_2 = AllegationFactory(
            incident_date=datetime(2009, 10, 6, tzinfo=pytz.utc))
        OfficerAllegationFactory(officer=officer_1, allegation=allegation_1)
        OfficerAllegationFactory(officer=officer_3, allegation=allegation_2)

        TRRFactory(trr_datetime=datetime(2004, 10, 10, tzinfo=pytz.utc),
                   officer=officer_2)
        TRRFactory(trr_datetime=datetime(2010, 5, 7, tzinfo=pytz.utc),
                   officer=officer_4)

        self.rebuild_index()
        self.refresh_index()

        url = reverse('api:suggestion-single')
        response = self.client.get(url, {
            'term': '10-10-2004',
            'contentType': 'DATE > OFFICERS'
        })
        results = response.data['results']
        expect({record['id'] for record in results}).to.eq({'1', '2'})
コード例 #5
0
    def test_compute_trr_metric(self):
        officer = OfficerFactory(id=1, appointed_date=date(2010, 3, 14))

        TRRFactory(officer=officer,
                   trr_datetime=datetime(2014, 12, 31, tzinfo=pytz.utc))
        TRRFactory(officer=officer,
                   trr_datetime=datetime(2015, 1, 1, tzinfo=pytz.utc))
        TRRFactory(officer=officer,
                   trr_datetime=datetime(2016, 1, 1, tzinfo=pytz.utc))
        TRRFactory(officer=officer,
                   trr_datetime=datetime(2016, 2, 1, tzinfo=pytz.utc))
        TRRFactory(officer=officer,
                   trr_datetime=datetime(2017, 2, 1, tzinfo=pytz.utc))

        officers = officer_percentile._compute_metric(2016,
                                                      PERCENTILE_TRR_GROUP)
        expect(officers).to.have.length(1)
        validate_object(
            officers[0], {
                'officer_id': 1,
                'year': 2016,
                'start_date': date(2015, 1, 1),
                'end_date': date(2016, 7, 1),
                'service_year': 1.4986,
                'num_trr': 3,
                'metric_trr': 2.0019
            })
コード例 #6
0
ファイル: test_views.py プロジェクト: invinst/CPDBv2_backend
    def test_sitemap_trr_view(self):
        TRRFactory(id=123)
        TRRFactory(id=789)
        TRRFactory(id=456)

        response = self.client.get('/sitemap-trr.xml')

        expect(response.status_code).to.eq(status.HTTP_200_OK)
        expect(response.content.decode('utf8')).to.eq(
            '<?xml version="1.0" encoding="UTF-8"?>\n'
            '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'
            '<url>'
            '<loc>https://example.com/trr/123/</loc>'
            '<lastmod>2019-03-18</lastmod>'
            '<changefreq>daily</changefreq>'
            '<priority>0.5</priority>'
            '</url>'
            '<url>'
            '<loc>https://example.com/trr/456/</loc>'
            '<lastmod>2019-03-18</lastmod>'
            '<changefreq>daily</changefreq>'
            '<priority>0.5</priority>'
            '</url>'
            '<url>'
            '<loc>https://example.com/trr/789/</loc>'
            '<lastmod>2019-03-18</lastmod>'
            '<changefreq>daily</changefreq>'
            '<priority>0.5</priority>'
            '</url>\n'
            '</urlset>\n'
        )
コード例 #7
0
    def test_search(self):
        officer_1 = OfficerFactory(id=1,
                                   first_name='Jerome',
                                   last_name='Finnigan')
        officer_2 = OfficerFactory(id=2, first_name='Edward', last_name='May')
        officer_3 = OfficerFactory(id=3)
        officer_4 = OfficerFactory(id=4)

        allegation_1 = AllegationFactory(
            incident_date=datetime(2004, 10, 10, tzinfo=pytz.utc))
        allegation_2 = AllegationFactory(
            incident_date=datetime(2009, 10, 6, tzinfo=pytz.utc))
        OfficerAllegationFactory(officer=officer_1, allegation=allegation_1)
        OfficerAllegationFactory(officer=officer_3, allegation=allegation_2)

        TRRFactory(trr_datetime=datetime(2004, 10, 10, tzinfo=pytz.utc),
                   officer=officer_2)
        TRRFactory(trr_datetime=datetime(2010, 5, 7, tzinfo=pytz.utc),
                   officer=officer_4)

        self.rebuild_index()
        self.refresh_index()

        response = DateOfficerWorker().search('', dates=['2004-10-10'])
        expect({record.id for record in response.hits}).to.eq({1, 2})
コード例 #8
0
 def test_force_category(self):
     expect(TRRFactory(taser=False,
                       firearm_used=False).force_category).to.eq('Other')
     expect(TRRFactory(taser=True,
                       firearm_used=False).force_category).to.eq('Taser')
     expect(TRRFactory(taser=False,
                       firearm_used=True).force_category).to.eq('Firearm')
コード例 #9
0
    def test_get_point(self):
        trr = TRRFactory(point=None)
        result = TRRDocSerializer(trr).data
        expect(result['point']).to.eq(None)

        trr = TRRFactory(point=Point(1.0, 1.0))
        result = TRRDocSerializer(trr).data
        expect(result['point']).to.eq({'lng': 1.0, 'lat': 1.0})
コード例 #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])
コード例 #11
0
    def test_get_address_missing_data(self):
        trr_no_street = TRRFactory(block='34XX')
        trr_no_block = TRRFactory(block=None, street='Douglas Blvd')
        trr_no_address = TRRFactory()

        expect(TRRDocSerializer(trr_no_street).data['address']).to.eq('34XX')
        expect(TRRDocSerializer(trr_no_block).data['address']).to.eq(
            'Douglas Blvd')
        expect(TRRDocSerializer(trr_no_address).data['address']).to.eq('')
コード例 #12
0
    def test_trr_count(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        TRRFactory.create_batch(2, officer=officer_1)
        officer_cache_manager.build_cached_columns()
        officer_1.refresh_from_db()
        officer_2.refresh_from_db()

        expect(officer_1.trr_count).to.eq(2)
        expect(officer_2.trr_count).to.eq(0)
コード例 #13
0
ファイル: test_views.py プロジェクト: UC-ITSC/CPDBv2_backend
    def test_search_date_trr_result(self):
        officer = OfficerFactory(
            id=123456,
            rank='Sergeant of Police',
            first_name='Jesse',
            last_name='Pinkman',
            complaint_percentile=4.4,
            civilian_allegation_percentile=1.1,
            internal_allegation_percentile=2.2,
            trr_percentile=3.3,
            allegation_count=1,
            resignation_date=date(2015, 4, 14)
        )
        TRRFactory(
            id='123',
            trr_datetime=datetime(2007, 12, 27, tzinfo=pytz.utc),
        )
        TRRFactory(
            id='456',
            trr_datetime=datetime(2008, 12, 27, tzinfo=pytz.utc),
            block='3000',
            street='Michigan Ave',
            taser=False,
            firearm_used=True,
            officer=officer
        )

        self.rebuild_index()
        self.refresh_index()

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

        results = response.data['DATE > TRR']
        expect(results).to.have.length(1)
        expect(results[0]['id']).to.eq('456')
        expect(results[0]).to.eq({
            'id': '456',
            'trr_datetime': '2008-12-27',
            'to': '/trr/456/',
            'category': 'Firearm',
            'address': '3000 Michigan Ave',
            'officer': {
                'id': 123456,
                'full_name': 'Jesse Pinkman',
                'percentile_allegation': '4.4000',
                'percentile_trr': '3.3000',
                'percentile_allegation_civilian': '1.1000',
                'percentile_allegation_internal': '2.2000',
                'allegation_count': 1
            }
        })
コード例 #14
0
    def test_items(self):
        trr_1 = TRRFactory(id=123)
        trr_2 = TRRFactory(id=789)
        trr_3 = TRRFactory(id=456)

        items = list(TRRSitemap().items())

        expect(items).to.have.length(3)
        expect(items[0]).to.eq(trr_1)
        expect(items[1]).to.eq(trr_3)
        expect(items[2]).to.eq(trr_2)
コード例 #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
        }])
コード例 #16
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
        }])
コード例 #17
0
    def test_search_trr_result(self):
        TRRFactory(id='123456').save()
        TRRFactory(id='456789').save()

        self.rebuild_index()
        self.refresh_index()

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

        results = response.data['TRR']
        expect(results).to.have.length(1)

        expect(results[0]['id']).to.eq('123456')
コード例 #18
0
    def test_force_types(self):
        trr = TRRFactory()
        ActionResponseFactory(trr=trr,
                              force_type='Physical Force - Stunning',
                              action_sub_category='4')
        ActionResponseFactory(trr=trr,
                              force_type='Taser',
                              action_sub_category='5.1')
        ActionResponseFactory(trr=trr,
                              force_type='Other',
                              action_sub_category=None,
                              person='Subject Action')
        ActionResponseFactory(trr=trr,
                              force_type='Impact Weapon',
                              action_sub_category='5.2')
        ActionResponseFactory(trr=trr,
                              force_type='Taser Display',
                              action_sub_category='3')
        ActionResponseFactory(trr=trr,
                              force_type='Taser Display',
                              action_sub_category='3')

        expect(list(trr.force_types)).to.eq([
            'Impact Weapon', 'Taser', 'Physical Force - Stunning',
            'Taser Display'
        ])
コード例 #19
0
    def test_serialization(self):
        trr = TRRFactory(id=1)

        expect(TRRSerializer(trr).data).to.eq({
            'id': 1,
            'type': 'TRR',
        })
コード例 #20
0
    def test_update_trr_attachment_request_to_foia_with_valid_airtable_id(
            self, airtable_mock):
        airtable_mock.update.return_value = {'id': 'airtable_id'}

        officer = OfficerFactory(id=1, first_name='Marry', last_name='Jane')
        trr = TRRFactory(id='123456', officer=officer)
        attachment_request = TRRAttachmentRequestFactory(
            trr=trr, email='*****@*****.**', airtable_id='airtable_id')

        expected_airtable_data = {
            'Explanation':
            'Officer: Marry Jane(ID 1)',
            'Project': ['CPDP'],
            'Agency': [],
            'Requested For':
            'TRR 123456',
            'Requestor': [{
                'id': 'usrGiZFcyZ6wHTYWd',
                'email': '*****@*****.**',
                'name': 'Rajiv Sinclair'
            }],
            'Date requested by user':
            attachment_request.created_at.strftime('%Y-%m-%d'),
            'Requester Email':
            '*****@*****.**'
        }

        TRRRequestAirTableUploader.upload(update_all_records=True)
        attachment_request.refresh_from_db()

        airtable_mock.update.assert_called_with('airtable_id',
                                                expected_airtable_data)
        expect(attachment_request.airtable_id).to.be.eq('airtable_id')
コード例 #21
0
    def test_data(self):
        officer_1 = OfficerFactory(id=1)
        officer_2 = OfficerFactory(id=2)
        officer_3 = OfficerFactory(id=3)
        officer_4 = OfficerFactory(id=4)
        officer_5 = OfficerFactory(id=5)
        officers = [officer_1, officer_2, officer_3, officer_4]

        trr_1 = TRRFactory(id=1, officer=officer_3)
        trr_2 = TRRFactory(id=2, officer=officer_4)
        trr_3 = TRRFactory(id=3, officer=officer_4)
        TRRFactory(id=4, officer=officer_5)

        expected_data = [trr_1.id, trr_2.id, trr_3.id]
        results = [item.id for item in list(GeographyTrrsDataQuery([trr_3.id], officers).data())]
        expect(results).to.eq(expected_data)
コード例 #22
0
 def test_unique_trr_and_email(self):
     trr = TRRFactory()
     email = '*****@*****.**'
     TRRAttachmentRequestFactory(email=email, trr=trr)
     with transaction.atomic():
         expect(lambda: TRRAttachmentRequestFactory(email=email, trr=trr)).to.throw(IntegrityError)
     expect(len(TRRAttachmentRequest.objects.all())).to.eq(1)
コード例 #23
0
 def test_request_document_without_email(self):
     TRRFactory(pk=321)
     response = self.client.post(reverse('api-v2:trr-request-document', kwargs={'pk': 321}))
     expect(response.status_code).to.eq(status.HTTP_400_BAD_REQUEST)
     expect(response.data).to.eq({
         'message': 'Please enter a valid email'
     })
コード例 #24
0
 def test_extract_datum_without_officer(self):
     trr = TRRFactory(taser=False,
                      firearm_used=False,
                      trr_datetime=datetime(2001, 1, 1, tzinfo=pytz.utc),
                      subject_age=37,
                      officer_assigned_beat='Beat 1',
                      officer_in_uniform=True,
                      officer_on_duty=False,
                      subject_gender='M',
                      officer=None)
     expect(TRRIndexer().extract_datum(trr)).to.eq({
         'id': trr.id,
         'officer_assigned_beat': 'Beat 1',
         'officer_in_uniform': True,
         'officer_on_duty': False,
         'officer': None,
         'subject_race': 'White',
         'subject_gender': 'Male',
         'subject_age': 37,
         'force_category': 'Other',
         'force_types': [],
         'date_of_incident': '2001-01-01',
         'location_type': None,
         'address': '',
         'beat': None,
         'point': None,
     })
コード例 #25
0
    def test_serialization(self):
        officer = OfficerFactory(id=123)
        trr = TRRFactory(
            id=456,
            officer=officer,
            trr_datetime=datetime(2002, 2, 3, tzinfo=pytz.utc),
            point=Point([0.01, 0.02]),
            taser=True,
            firearm_used=False
        )

        setattr(trr, 'unit_name', 'Unit 001')
        setattr(trr, 'unit_description', 'District 001')
        setattr(trr, 'rank_name', 'Police Officer')

        expect(TRRNewTimelineMobileSerializer(trr).data).to.eq({
            'unit_name': 'Unit 001',
            'unit_description': 'District 001',
            'rank': 'Police Officer',
            'priority_sort': 50,
            'kind': 'FORCE',
            'trr_id': 456,
            'date_sort': date(2002, 2, 3),
            'date': '2002-02-03',
            'taser': True,
            'firearm_used': False,
            'point': {
                'lon': 0.01,
                'lat': 0.02
            }
        })
コード例 #26
0
ファイル: test_views.py プロジェクト: UC-ITSC/CPDBv2_backend
    def test_retrieve_recent_search_items(self):
        OfficerFactory(
            id=8562,
            first_name='Jerome',
            last_name='Finnigan',
            current_badge='123456',
            allegation_count=20,
            sustained_count=5,
            birth_year=1980,
            race='White',
            gender='M',
            rank='Police Officer'
        )
        allegation_category = AllegationCategoryFactory(category='Use of Force')
        AllegationFactory(
            crid='C12345',
            incident_date=datetime(2007, 1, 1, tzinfo=pytz.utc),
            most_common_category=allegation_category,
        )
        trr = TRRFactory(id=123, trr_datetime=datetime(2007, 1, 1, tzinfo=pytz.utc))
        ActionResponseFactory(trr=trr, force_type='Physical Force - Stunning', action_sub_category='4')
        ActionResponseFactory(trr=trr, force_type='Taser', action_sub_category='5.1')
        ActionResponseFactory(trr=trr, force_type='Impact Weapon', action_sub_category='5.2')
        ActionResponseFactory(trr=trr, force_type='Taser Display', action_sub_category='3')

        url = reverse('api:suggestion-recent-search-items')
        response = self.client.get(url, {
            'officer_ids[]': 8562,
            'crids[]': 'C12345',
            'trr_ids[]': 123,
        })

        expect(response.status_code).to.eq(status.HTTP_200_OK)
        expect(response.data).to.eq([
            {
                'id': 8562,
                'name': 'Jerome Finnigan',
                'race': 'White',
                'gender': 'Male',
                'rank': 'Police Officer',
                'allegation_count': 20,
                'sustained_count': 5,
                'birth_year': 1980,
                'type': 'OFFICER',
            },
            {
                'id': 'C12345',
                'crid': 'C12345',
                'category': 'Use of Force',
                'incident_date': '2007-01-01',
                'type': 'CR',
            },
            {
                'id': 123,
                'trr_datetime': '2007-01-01',
                'force_type': 'Impact Weapon',
                'type': 'TRR',
            }
        ])
コード例 #27
0
    def test_get_point(self):
        trr = TRRFactory(id=456, point=None)

        setattr(trr, 'unit_name', 'Unit 001')
        setattr(trr, 'unit_description', 'District 001')
        setattr(trr, 'rank_name', 'Police Officer')

        expect(TRRNewTimelineSerializer(trr).data).to.exclude('point')
コード例 #28
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()
コード例 #29
0
    def test_lastmod(self):
        trr = TRRFactory(id=123, beat=1)
        with freeze_time(datetime(2018, 4, 4, 12, 0, 1, tzinfo=pytz.utc)):
            trr.beat = 2
            trr.save()

        trr.refresh_from_db()

        expect(TRRSitemap().lastmod(trr)).to.eq(datetime(2018, 4, 4, 12, 0, 1, tzinfo=pytz.utc))
コード例 #30
0
 def test_request_document(self):
     EmailTemplateFactory(type=TRR_ATTACHMENT_REQUEST)
     TRRFactory(pk=112233)
     response = self.client.post(
         reverse('api-v2:trr-request-document', kwargs={'pk': 112233}),
         {'email': '*****@*****.**'}
     )
     expect(response.status_code).to.eq(status.HTTP_200_OK)
     expect(response.data).to.eq({
         'message': 'Thanks for subscribing',
         'trr_id': 112233
     })