Ejemplo n.º 1
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.º 2
0
    def test_complainant_race_aggregation(self):
        officer = OfficerFactory()

        allegation1 = AllegationFactory()
        allegation2 = AllegationFactory()
        allegation3 = AllegationFactory()
        OfficerAllegationFactory(officer=officer,
                                 allegation=allegation1,
                                 start_date=date(2010, 1, 1),
                                 final_finding='SU')
        OfficerAllegationFactory(officer=officer,
                                 allegation=allegation2,
                                 start_date=date(2011, 1, 1),
                                 final_finding='NS')
        OfficerAllegationFactory(officer=officer,
                                 allegation=allegation3,
                                 start_date=None,
                                 final_finding='NS')
        ComplainantFactory(allegation=allegation1, race='White')
        ComplainantFactory(allegation=allegation2, race='')
        ComplainantFactory(allegation=allegation3, race='White')

        expect(officer.complainant_race_aggregation).to.eq([{
            'name':
            'White',
            'count':
            2,
            'sustained_count':
            1,
            'items': [{
                'year': 2010,
                'count': 1,
                'sustained_count': 1,
                'name': 'White'
            }]
        }, {
            'name':
            'Unknown',
            'count':
            1,
            'sustained_count':
            0,
            'items': [{
                'year': 2011,
                'count': 1,
                'sustained_count': 0,
                'name': 'Unknown'
            }]
        }])
Ejemplo n.º 3
0
    def test_search_investigator_cr_results(self):
        allegation_1 = AllegationFactory(crid='123456', incident_date=datetime(2002, 2, 3, tzinfo=pytz.utc))
        allegation_2 = AllegationFactory(crid='654321', incident_date=datetime(2005, 2, 3, tzinfo=pytz.utc))
        officer = OfficerFactory(id=123, first_name='Edward', last_name='May')
        investigator_1 = InvestigatorFactory(first_name='Jerome', last_name='Finnigan')
        investigator_2 = InvestigatorFactory(officer=officer)
        InvestigatorAllegationFactory(investigator=investigator_1, allegation=allegation_1)
        InvestigatorAllegationFactory(investigator=investigator_2, allegation=allegation_1)
        InvestigatorAllegationFactory(investigator=investigator_1, allegation=allegation_2)

        self.rebuild_index()
        self.refresh_index()

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

        results = response.data['INVESTIGATOR > CR']
        expect(results).to.have.length(2)

        expected_results = {
            '123456': {
                'id': '123456',
                'crid': '123456',
                'to': '/complaint/123456/',
                'incident_date': '2002-02-03',
                'category': 'Unknown',
                'sub_category': 'Unknown',
                'address': '',
                'victims': [],
                'coaccused': []
            },
            '654321': {
                'id': '654321',
                'crid': '654321',
                'to': '/complaint/654321/',
                'incident_date': '2005-02-03',
                'category': 'Unknown',
                'sub_category': 'Unknown',
                'address': '',
                'victims': [],
                'coaccused': []
            }
        }

        for cr_data in results:
            expect(cr_data).to.eq(expected_results[cr_data['id']])
Ejemplo n.º 4
0
    def test_complainant_races(self):
        allegation = AllegationFactory()
        ComplainantFactory(race='White', allegation=allegation)
        expect(allegation.complainant_races).to.eq(['White'])

        ComplainantFactory(race='White/Hispinic', allegation=allegation)
        expect(allegation.complainant_races).to.eq(['White', 'White/Hispinic'])
Ejemplo n.º 5
0
    def test_most_common_category(self):
        allegation = AllegationFactory()
        category1, category2 = AllegationCategoryFactory.create_batch(2)

        OfficerAllegationFactory(allegation=allegation,
                                 allegation_category=category2)
        OfficerAllegationFactory.create_batch(2,
                                              allegation=allegation,
                                              allegation_category=category1)
        OfficerAllegationFactory.create_batch(3,
                                              allegation=allegation,
                                              allegation_category=None)
        allegation_cache_manager.cache_data()
        allegation.refresh_from_db()

        expect(allegation.most_common_category).to.eq(category1)
Ejemplo n.º 6
0
    def test_extract_datum_most_common_category(self):
        allegation = AllegationFactory()
        cat1 = AllegationCategoryFactory(
            category='Use Of Forces',
            allegation_name='Sub Force'
        )
        cat2 = AllegationCategoryFactory(
            category='Traffic',
            allegation_name='Sub traffic'
        )
        OfficerAllegationFactory.create_batch(
            2,
            allegation=allegation,
            allegation_category=cat1
        )

        OfficerAllegationFactory(
            allegation=allegation,
            allegation_category=cat2
        )

        rows = self.extract_data()
        expect(rows).to.have.length(1)
        expect(rows[0]['most_common_category']).to.eq({
            'category': 'Use Of Forces',
            'allegation_name': 'Sub Force'
        })
    def test_next_document_id_is_none_if_all_documents_have_tags(self):
        allegation = AllegationFactory(crid='456')
        with freeze_time('2017-08-04'):
            AttachmentFileFactory(
                allegation=allegation,
                file_type='document',
                tags=['tag123'],
            )

        with freeze_time('2017-09-04'):
            AttachmentFileFactory(
                allegation=allegation,
                file_type='document',
                tags=['tag124'],
            )

        with freeze_time('2017-10-05'):
            attachment = AttachmentFileFactory(
                allegation=allegation,
                file_type='document',
                tags=['tag125'],
            )

        with freeze_time('2017-08-05'):
            AttachmentFileFactory(
                allegation=allegation,
                file_type='audio',
            )

        next_document_id = AuthenticatedAttachmentFileSerializer(
            attachment).data['next_document_id']
        expect(next_document_id).to.eq(None)
    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.º 10
0
    def test_complainant_genders(self):
        allegation = AllegationFactory()
        ComplainantFactory(gender='F', allegation=allegation)
        expect(allegation.complainant_genders).to.eq(['Female'])

        ComplainantFactory(gender='U', allegation=allegation)
        expect(allegation.complainant_genders).to.eq(['Female', 'Unknown'])
Ejemplo n.º 11
0
 def test_request_document_with_invalid_email(self):
     AllegationFactory(crid='321')
     response = self.client.post(
         reverse('api-v2:cr-request-document', kwargs={'pk': 321}),
         {'email': 'invalid@email'})
     expect(response.status_code).to.eq(status.HTTP_400_BAD_REQUEST)
     expect(response.data).to.eq({'message': 'Please enter a valid email'})
Ejemplo n.º 12
0
    def test_extract_info_complaint_record_complainant_null_age(self):
        allegation = AllegationFactory()
        ComplainantFactory(allegation=allegation, age=None)
        OfficerAllegationFactory(final_finding='UN',
                                 start_date=date(2000, 1, 2),
                                 allegation=allegation)

        rows = self.extract_data()

        expect(rows).to.have.length(1)
        expect(rows[0]['complaint_records']['facets'][2]).to.eq({
            'name':
            'complainant age',
            'entries': [{
                'name':
                'Unknown',
                'count':
                1,
                'sustained_count':
                0,
                'items': [{
                    'year': 2000,
                    'name': 'Unknown',
                    'count': 1,
                    'sustained_count': 0
                }]
            }]
        })
Ejemplo n.º 13
0
    def test_search_date_cr_result(self):
        AllegationFactory(crid='123', incident_date=datetime(2007, 12, 27, tzinfo=pytz.utc)).save()
        AllegationFactory(crid='456', incident_date=datetime(2008, 12, 27, tzinfo=pytz.utc)).save()

        self.rebuild_index()
        self.refresh_index()

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

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

        expect(results[0]['crid']).to.eq('456')
    def test_victims(self):
        allegation = AllegationFactory()
        victim1 = VictimFactory(allegation=allegation)
        victim2 = VictimFactory(allegation=allegation)

        officer_allegation = OfficerAllegationFactory(allegation=allegation)
        expect(list(officer_allegation.victims)).to.eq([victim1, victim2])
Ejemplo n.º 15
0
    def test_logging_when_sending_cr_attachment_available_email_raise_error(
            self, mock_send_email, mock_logger):
        mock_send_email.side_effect = SMTPException('Sending failed')

        EmailTemplateFactory(
            subject='To {name}',
            body='This message is related to crid {pk} with url {url}',
            from_email='*****@*****.**',
            type=CR_ATTACHMENT_AVAILABLE)

        allegation_123 = AllegationFactory(crid='123')
        AttachmentRequestFactory(allegation=allegation_123,
                                 email='*****@*****.**',
                                 noti_email_sent=False)

        AttachmentFileFactory(allegation=allegation_123)
        new_attachments = AttachmentFile.objects.all()

        send_cr_attachment_available_email(new_attachments)

        expect(AttachmentRequest.objects.filter(
            noti_email_sent=True).count()).to.eq(0)
        expect(
            AttachmentRequest.objects.filter(
                noti_email_sent=False).count()).to.eq(1)

        expect(mock_logger.info).to.be.called_with(
            'Cannot send notification email for crid 123 to [email protected]'
        )
Ejemplo n.º 16
0
    def test_upload_summary_reports_copa_documents(self, DocumentCloudMock):
        logger = logging.getLogger('crawler.crawl_copa_data')
        DocumentCloudMock().documents.upload.return_value = PropertyMock(
            id='5396984-crid-123-cr-tactical-response-report',
            title='CRID 123 CR Tactical Response Report',
            canonical_url=
            'https://www.documentcloud.org/documents/5396984-tactical-response-report.html',
            normal_image_url=
            'https://www.documentcloud.org/documents/tactical-response-report-p1-normal.gif',
            created_at=datetime(2017, 8, 4, 14, 30, 00, tzinfo=pytz.utc),
            updated_at=datetime(2017, 8, 5, 14, 30, 00, tzinfo=pytz.utc),
            resources=None)

        allegation = AllegationFactory(crid='123')
        AttachmentFileFactory(
            external_id='123-OCIR-Redacted.pdf',
            allegation=allegation,
            source_type=AttachmentSourceType.SUMMARY_REPORTS_COPA,
            file_type=MEDIA_TYPE_DOCUMENT,
            title='COPA Summary Report',
            original_url=
            'https://www.chicagocopa.org/wp-content/uploads/2017/10/Log-1086285-TRR-Redacted.pdf',
            upload_fail_attempts=1,
        )

        CopaSummaryReportsAttachmentImporter(logger).upload_to_documentcloud()

        AttachmentFile.objects.get(pending_documentcloud_id='5396984')
        expect(DocumentCloudMock().documents.upload).to.be.called_with(
            'https://www.chicagocopa.org/wp-content/uploads/2017/10/Log-1086285-TRR-Redacted.pdf',
            title='CRID 123 CR COPA Summary Report',
            description=AttachmentSourceType.
            SUMMARY_REPORTS_COPA_DOCUMENTCLOUD,
            access='public',
            force_ocr=True)
Ejemplo n.º 17
0
    def test_get_involvements(self, police_witness_serializer_mock, investigator_allegation_serializer_mock):
        allegation = AllegationFactory()
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        PoliceWitnessFactory(officer=officer_1, allegation=allegation)
        PoliceWitnessFactory(officer=officer_2, allegation=allegation)
        OfficerBadgeNumberFactory(officer=officer_1, star='456789')
        investigator_1 = InvestigatorFactory(officer=officer_1)
        investigator_2 = InvestigatorFactory(officer=officer_2)
        investigator_3 = InvestigatorFactory()
        investigator_allegation_1 = InvestigatorAllegationFactory(allegation=allegation, investigator=investigator_1)
        investigator_allegation_2 = InvestigatorAllegationFactory(allegation=allegation, investigator=investigator_2)
        investigator_allegation_3 = InvestigatorAllegationFactory(allegation=allegation, investigator=investigator_3)
        investigator_allegations = [investigator_allegation_1, investigator_allegation_2, investigator_allegation_3]
        expected_has_badge_numbers = {
            investigator_allegation_1.id: True,
            investigator_allegation_2.id: False,
            investigator_allegation_3.id: False,
        }

        result = CRSerializer(allegation).data
        investigator_allegations_arg = investigator_allegation_serializer_mock.call_args[0][0]
        police_witnesses_arg = police_witness_serializer_mock.call_args[0][0]
        expect(set(investigator_allegations_arg)).to.eq(set(investigator_allegations))
        for obj in investigator_allegations_arg:
            expect(obj.has_badge_number).to.eq(expected_has_badge_numbers[obj.id])
        expect(set(police_witnesses_arg)).to.eq(set([officer_1, officer_2]))
        expect(result['involvements']).to.eq(
            [{'officer_id': 1}, {'officer_id': 2}, {'officer_id': 4}, {'officer_id': 3}]
        )
Ejemplo n.º 18
0
    def test_create_success(self):
        allegation = AllegationFactory(crid=123456)
        attachment_file = AttachmentFileFactory(
            id=123,
            allegation=allegation,
            title='CR document 10',
            tag='CR',
            url='https://cr-document.com/10',
            file_type=MEDIA_TYPE_DOCUMENT,
            preview_image_url='http://preview.com/url3',
        )

        expect(AttachmentTracking.objects.count()).to.eq(0)

        response = self.client.post(reverse(
            'api-v2:attachment-tracking-list'),
            {'accessed_from_page': 'CR', 'app': 'frontend', 'attachment_id': 123}
        )

        expect(response.status_code).to.eq(status.HTTP_200_OK)
        expect(AttachmentTracking.objects.count()).to.eq(1)
        attachment_tracking = AttachmentTracking.objects.first()
        expect(attachment_tracking.created_at).to.eq(datetime(2018, 4, 4, 12, 0, 1, tzinfo=pytz.utc))
        expect(attachment_tracking.attachment_file).to.eq(attachment_file)
        expect(attachment_tracking.accessed_from_page).to.eq('CR')
        expect(attachment_tracking.app).to.eq('frontend')
Ejemplo n.º 19
0
    def test_search_cr_result(self):
        AllegationFactory(crid='123').save()
        AllegationFactory(crid='456').save()

        self.rebuild_index()
        self.refresh_index()

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

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

        expect(results[0]['crid']).to.eq('123')
Ejemplo n.º 20
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')
Ejemplo n.º 21
0
    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',
            }
        ])
 def make_officer_allegation(self, count, area, incident_date, **kwargs):
     for _ in range(count):
         allegation = AllegationFactory(incident_date=incident_date)
         area.allegation_set.add(allegation)
         OfficerAllegationFactory(
             allegation=allegation,
             **kwargs
         )
Ejemplo n.º 23
0
    def test_get_coaccused(self, coaccused_serializer_mock):
        allegation = AllegationFactory()
        officer_allegations = OfficerAllegationFactory.create_batch(2, allegation=allegation)

        result = CRSerializer(allegation).data
        officer_allegations_arg = coaccused_serializer_mock.call_args[0][0]
        expect(set(officer_allegations_arg)).to.eq(set(officer_allegations))
        expect(result['coaccused']).to.eq([{'id': 1}, {'id': 2}])
Ejemplo n.º 24
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.º 25
0
    def test_unique_allegation_and_email(self):
        allegation = AllegationFactory()
        email = '*****@*****.**'
        AttachmentRequestFactory(email=email, allegation=allegation)

        expect(lambda: AttachmentRequestFactory(
            email=email, allegation=allegation)).to.throw(ValidationError)
        expect(len(AttachmentRequest.objects.all())).to.eq(1)
Ejemplo n.º 26
0
    def test_coaccused_count(self):
        allegation_1 = AllegationFactory()
        allegation_2 = AllegationFactory()
        OfficerAllegationFactory.create_batch(6, allegation=allegation_1)
        allegation_cache_manager.cache_data()
        allegation_1.refresh_from_db()
        allegation_2.refresh_from_db()

        expect(allegation_1.coaccused_count).to.eq(6)
        expect(allegation_2.coaccused_count).to.eq(0)
Ejemplo n.º 27
0
    def test_create_zip_file_already_exist(self, aws_mock):
        aws_mock.s3.get_object.return_value = {}

        allegation = AllegationFactory(crid='1')
        allegation_456 = AllegationFactory(crid='456')

        AttachmentFileFactory(
            allegation=allegation,
            source_type='DOCUMENTCLOUD',
            external_id='ABC',
            title='allegation 1 attachment'
        )
        AttachmentFileFactory(allegation=allegation, source_type='COPA')
        AttachmentFileFactory(allegation=allegation_456, source_type='DOCUMENTCLOUD')
        AttachmentFileFactory(allegation=allegation_456, source_type='PORTAL_COPA_DOCUMENTCLOUD')

        officer = OfficerFactory(id=1, first_name='Jerome', last_name='Finnigan')
        OfficerAllegationFactory(officer=officer, allegation=allegation)

        allegation_2 = AllegationFactory(crid='2')
        allegation_789 = AllegationFactory(crid='789')
        AttachmentFileFactory(
            allegation=allegation_2,
            source_type='DOCUMENTCLOUD',
            external_id='XYZ',
            title='allegation 2 attachment'
        )
        AttachmentFileFactory(allegation=allegation_2, source_type='COPA')
        AttachmentFileFactory(allegation=allegation_789, source_type='DOCUMENTCLOUD')
        AttachmentFileFactory(allegation=allegation_789, source_type='PORTAL_COPA_DOCUMENTCLOUD')

        investigator = InvestigatorFactory(officer=officer)
        InvestigatorAllegationFactory(allegation=allegation_2, investigator=investigator)

        self.client.get(reverse('api-v2:officers-create-zip-file', kwargs={'pk': 1}))

        aws_mock.s3.get_object.assert_any_call(
            Bucket='officer_content_bucket',
            Key='zip_with_docs/Jerome_Finnigan_with_docs.zip'
        )
        aws_mock.s3.get_object.assert_any_call(
            Bucket='officer_content_bucket',
            Key='zip/Jerome_Finnigan.zip'
        )
        expect(aws_mock.lambda_client.invoke_async.called).to.be.false()
    def test_update_coaccusal_count_when_create(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()

        allegation_1 = AllegationFactory()
        allegation_2 = AllegationFactory()
        OfficerAllegationFactory(allegation=allegation_1, officer=officer_1)
        OfficerAllegationFactory(allegation=allegation_1, officer=officer_2)
        OfficerAllegationFactory(allegation=allegation_2, officer=officer_1)
        OfficerAllegationFactory(allegation=allegation_2, officer=officer_2)
        OfficerAllegationFactory(officer=officer_1)
        OfficerAllegationFactory(officer=officer_2)

        pair_card = ActivityPairCard.objects.create(officer1=officer_1,
                                                    officer2=officer_2)

        pair_card.refresh_from_db()
        expect(pair_card.coaccusal_count).to.eq(2)
Ejemplo n.º 29
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.º 30
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)