def test_handle(self):
        allegation = AllegationFactory(crid='001')

        call_command('import_cr_summary',
                     file_path='data/tests/data_sample/cr_summary.csv')

        allegation.refresh_from_db()
        expect(allegation.summary).be.eq('Summary Text 01 is here')
Exemple #2
0
    def test_lastmod(self):
        allegation = AllegationFactory(crid='123')
        with freeze_time(datetime(2018, 4, 4, 12, 0, 1, tzinfo=pytz.utc)):
            allegation.coaccused_count = 2
            allegation.save()

        allegation.refresh_from_db()

        expect(AllegationSitemap().lastmod(allegation)).to.eq(datetime(2018, 4, 4, 12, 0, 1, tzinfo=pytz.utc))
Exemple #3
0
    def test_first_end_date(self):
        allegation = AllegationFactory()
        first_end_date = date(2003, 3, 20)
        OfficerAllegationFactory(allegation=allegation, end_date=None)
        OfficerAllegationFactory(allegation=allegation,
                                 end_date=first_end_date)
        allegation_cache_manager.cache_data()
        allegation.refresh_from_db()

        expect(allegation.first_end_date).to.eq(first_end_date)
Exemple #4
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)
Exemple #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)
    def test_extract_datum(self):
        allegation = AllegationFactory(
            crid='123456',
            incident_date=datetime(2017, 7, 27, tzinfo=pytz.utc),
            summary='abc',
            add1='3000',
            add2='Michigan Ave',
            city='Chicago IL'
        )
        officer = OfficerFactory(
            id=10,
            first_name='Luke',
            last_name='Skywalker',
            allegation_count=4,
            complaint_percentile='99.70',
            trr_percentile='99.88',
            civilian_allegation_percentile='77.66',
            internal_allegation_percentile='66.55'
        )
        officer2 = OfficerFactory(
            id=11,
            first_name='John', last_name='Doe',
            allegation_count=2,
            complaint_percentile='70.33',
            trr_percentile='66.88',
            civilian_allegation_percentile='33.66',
            internal_allegation_percentile='22.55'
        )
        OfficerAllegationFactory(allegation=allegation, officer=officer)

        category1 = AllegationCategoryFactory(
            category='Operation/Personnel Violations',
            allegation_name='Secondary/Special Employment'
        )
        category2 = AllegationCategoryFactory(category='Use of Force', allegation_name='sub category')
        OfficerAllegationFactory(allegation=allegation, allegation_category=category2, officer=officer2)
        OfficerAllegationFactory.create_batch(2, allegation=allegation, allegation_category=category1, officer=None)
        OfficerAllegationFactory.create_batch(3, allegation=allegation, allegation_category=None, officer=None)

        VictimFactory(allegation=allegation, gender='F', race='Black', age=25)
        VictimFactory(allegation=allegation, gender='', race='Black', age=25)
        VictimFactory(allegation=allegation, gender='F', race='Black', age=None)

        AttachmentFileFactory(id=1, allegation=allegation, text_content='')
        AttachmentFileFactory(
            id=2, allegation=allegation, show=False,
            text_content="CHICAGO POLICE DEPARTMENT RD I HT334604"
        )
        AttachmentFileFactory(id=3, allegation=allegation, text_content='CHICAGO POLICE DEPARTMENT RD I HT334604')

        setattr(allegation, 'investigator_names', ['Jerome Finnigan'])
        allegation_cache_manager.cache_data()
        allegation.refresh_from_db()

        datum = CrIndexer().extract_datum(allegation)
        datum['victims'] = sorted(
            datum['victims'],
            key=lambda victim: (victim['gender'], victim['race'], victim.get('age', 0))
        )

        expect(datum).to.eq({
            'crid': '123456',
            'category': 'Operation/Personnel Violations',
            'sub_category': 'Secondary/Special Employment',
            'incident_date': '2017-07-27',
            'address': '3000 Michigan Ave, Chicago IL',
            'summary': 'abc',
            'to': '/complaint/123456/',
            'investigator_names': ['Jerome Finnigan'],
            'victims': [
                {'gender': '', 'race': 'Black', 'age': 25},
                {'gender': 'Female', 'race': 'Black'},
                {'gender': 'Female', 'race': 'Black', 'age': 25},
            ],
            'coaccused': [
                {
                    'id': 10, 'full_name': 'Luke Skywalker', 'allegation_count': 4,
                    'percentile_allegation': '99.7000',
                    'percentile_allegation_civilian': '77.6600',
                    'percentile_allegation_internal': '66.5500',
                    'percentile_trr': '99.8800',
                },
                {
                    'id': 11, 'full_name': 'John Doe', 'allegation_count': 2,
                    'percentile_allegation': '70.3300',
                    'percentile_allegation_civilian': '33.6600',
                    'percentile_allegation_internal': '22.5500',
                    'percentile_trr': '66.8800',
                }
            ],
            'attachment_files': [
                {'id': 3, 'text_content': 'CHICAGO POLICE DEPARTMENT RD I HT334604'}
            ]
        })