コード例 #1
0
    def test_null_last_order_by(self):
        OfficerAllegationFactory(start_date=datetime.datetime(2010, 11, 1))
        OfficerAllegationFactory(start_date=None)

        [
            o.start_date
            for o in OfficerAllegation.objects.all().order_by('-start_date')
        ].index(None).should.equal(1)
        [
            o.start_date
            for o in OfficerAllegation.objects.all().order_by('start_date')
        ].index(None).should.equal(0)

        OfficerAllegation.objects.all().delete()

        OfficerAllegationFactory(allegation=AllegationFactory(
            incident_date=datetime.datetime(2011, 10, 1)))
        OfficerAllegationFactory(allegation=AllegationFactory(
            incident_date=None))

        [
            o.allegation.incident_date
            for o in OfficerAllegation.objects.all().order_by(
                '-allegation__incident_date')
        ].index(None).should.equal(1)
        [
            o.allegation.incident_date
            for o in OfficerAllegation.objects.all().order_by(
                'allegation__incident_date')
        ].index(None).should.equal(0)
コード例 #2
0
    def test_categories_replacement_logic(self):
        category = self.allegation_category.category
        other_category = AllegationCategoryFactory()
        sub_category = AllegationCategoryFactory(category=category)
        OfficerAllegationFactory(cat=other_category)
        OfficerAllegationFactory(cat=sub_category)

        self.filter_complaint_type()
        self.link(category).click()
        self.until_ajax_complete()
        self.element_by_classname_and_text('filter-name',
                                           category).should.be.ok

        self.link(sub_category.allegation_name).click()
        self.until_ajax_complete()
        self.element_by_classname_and_text(
            'filter-name', sub_category.allegation_name).should.be.ok
        self.element_by_classname_and_text('filter-name',
                                           category).should.be.false

        self.link(other_category.category).click()
        self.until_ajax_complete()
        self.element_by_classname_and_text(
            'filter-name', other_category.category).should.be.ok
        self.element_by_classname_and_text(
            'filter-name', sub_category.allegation_name).should.be.false
コード例 #3
0
    def test_merge_officer_allegations(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        oa_list_1 = OfficerAllegationFactory.create_batch(2, officer=officer_1)
        oa_list_2 = OfficerAllegationFactory.create_batch(2, officer=officer_2)
        allegation = AllegationFactory()
        oa_1 = OfficerAllegationFactory(allegation=allegation,
                                        officer=officer_1,
                                        cat=None,
                                        recc_finding=None,
                                        recc_outcome=None,
                                        final_outcome=None,
                                        final_outcome_class=None,
                                        start_date=None,
                                        end_date=None,
                                        final_finding=None)
        oa_2 = OfficerAllegationFactory(allegation=allegation,
                                        officer=officer_2)

        merge_officer_allegation(officer_1, officer_2)
        oa_1.refresh_from_db()

        set(oa.pk
            for oa in officer_1.officerallegation_set.all()).should.equal(
                set(oa.pk for oa in oa_list_1 + oa_list_2 + [oa_1]))

        for field in [
                'cat', 'recc_finding', 'recc_outcome', 'final_finding',
                'final_outcome', 'final_outcome_class', 'start_date',
                'end_date'
        ]:
            getattr(oa_1, field).should.equal(getattr(oa_2, field))
コード例 #4
0
    def test_get_related_officer_in_police_witness_info(self):
        no_disp_code = '600'

        allegation1 = AllegationFactory()
        allegation2 = AllegationFactory()

        officer = OfficerFactory()
        OfficerAllegationFactory(
            allegation=allegation1, officer=officer,
            final_outcome=no_disp_code)
        OfficerAllegationFactory(
            allegation=allegation2, officer=officer)

        witness = OfficerFactory()
        PoliceWitnessFactory(
            crid=allegation1.crid,
            allegation=allegation1,
            officer=witness)
        OfficerAllegationFactory(
            allegation=allegation2, officer=witness,
            final_outcome=no_disp_code)

        result = self.client.get('/api/police-witness/', {
            'crid': allegation1.crid})
        data = json.loads(result.content.decode())

        officers = data['police_witness'][0]['officers']
        len(officers).should.equal(1)
        officers[0]['num_complaints'].should.equal(2)
        officers[0]['no_action_taken'].should.equal(2)
コード例 #5
0
    def test_officer_detail_when_successfully_call_the_api(self):
        officer = OfficerFactory()
        co_accused_officer = OfficerFactory()
        witness_officer = OfficerFactory()
        officer_allegation = OfficerAllegationFactory(officer=officer)
        PoliceWitnessFactory(crid=officer_allegation.allegation.crid, officer=witness_officer,
                             allegation=officer_allegation.allegation)
        OfficerAllegationFactory(allegation=officer_allegation.allegation, officer=co_accused_officer)

        response, data = self.call_related_officer_api({'pk': officer.pk})
        response.status_code.should.equal(HTTP_200_OK)

        detail = data['detail']
        complaints = data['complaints']

        detail['id'].should.be.equal(officer.id)
        detail['appt_date'].should.be.equal(officer.appt_date)
        detail['unit'].should.be.equal(officer.unit.unit_name)
        detail['gender'].should.be.equal(officer.gender)
        detail['rank'].should.be.equal(officer.rank)
        detail['race'].should.be.equal(officer.race)
        detail['officer_first'].should.be.equal(officer.officer_first)
        detail['officer_last'].should.be.equal(officer.officer_last)

        len(complaints).should.be(1)
        complaints[0]['crid'].should.be.equal(str(officer_allegation.allegation.crid))
        len(complaints[0]['officer_allegation_set']).should.be.equal(2)
        len(data['co_accused']).should.be.equal(1)
        data.should.contain('distribution')
コード例 #6
0
    def test_age_range(self):
        age_values = [20, 25, 31, 41, 51, 61]
        expect_officer_age = {
            '20-30': 2,
            '31-40': 1,
            '41-50': 1,
            '51-60': 1,
            '61+': 1,
        }
        expected_witness_age = {
            '<20': 1,
            '21-30': 1,
            '31-40': 1,
            '41-50': 1,
            '51+': 2
        }

        for val in age_values:
            allegation = AllegationFactory(incident_date=datetime(2000, 1, 1))
            OfficerAllegationFactory(officer=OfficerFactory(birth_year=2000 -
                                                            val),
                                     allegation=allegation)
            ComplainingWitnessFactory(age=val, allegation=allegation)

        allegation = AllegationFactory()
        OfficerAllegationFactory(officer=OfficerFactory(birth_year=None),
                                 allegation=allegation)
        ComplainingWitnessFactory(age=None, allegation=allegation)

        response, data = self.get_race_gender_info()

        response.status_code.should.equal(status.HTTP_200_OK)
        data['officers']['age'].should.equal(expect_officer_age)
        data['complaining_witness']['age'].should.equal(expected_witness_age)
コード例 #7
0
    def setUp(self):
        self.rank = 'SGT'
        self.star = '823'
        self.unit = '001'
        self.gender = 'M'
        self.crid_1 = '1234'
        self.crid_2 = '2345'
        self.crid_3 = '3456'

        police_unit = PoliceUnitFactory(unit_name=self.unit)
        self.officer = OfficerFactory(rank=self.rank,
                                      star=self.star,
                                      unit=police_unit,
                                      gender=self.gender)
        self.involved_officer = OfficerFactory()
        self.witness_officer = OfficerFactory()

        allegation_1 = AllegationFactory(crid=self.crid_1)
        OfficerAllegationFactory(officer=self.officer, allegation=allegation_1)
        allegation_2 = AllegationFactory(crid=self.crid_2)
        OfficerAllegationFactory(officer=self.officer, allegation=allegation_2)
        OfficerAllegationFactory(
            officer=self.officer,
            allegation=AllegationFactory(crid=self.crid_3))
        OfficerAllegationFactory(officer=self.involved_officer,
                                 allegation=allegation_1)
        PoliceWitnessFactory(officer=self.witness_officer,
                             crid=self.crid_2,
                             allegation=allegation_2)

        self.setting = self.get_admin_settings()
コード例 #8
0
    def test_less_data_information_officer(self):
        # no data, race is keep here to make summary section not to be hidden
        officer = OfficerFactory(gender='',
                                 rank=None,
                                 appt_date=None,
                                 unit=None,
                                 race='Hispanic')
        OfficerAllegationFactory(officer=officer)

        self.visit_officer_page(officer.id)
        self.until(lambda: self.find('.officer-summary-section'))

        officer_summary = self.find('.officer-summary-section').text
        officer_summary.shouldnt.contain('Rank')
        officer_summary.shouldnt.contain('Unit')
        officer_summary.shouldnt.contain('Joined Date')
        officer_summary.shouldnt.contain('Sex')

        # Invalid units and no race data
        other_officer_unit = PoliceUnitFactory(unit_name='999')
        other_officer = OfficerFactory(gender='M',
                                       rank=None,
                                       appt_date=None,
                                       unit=other_officer_unit,
                                       race='')
        OfficerAllegationFactory(officer=other_officer)

        self.visit_officer_page(other_officer.id)
        self.until(lambda: self.find('.officer-summary-section'))

        officer_summary = self.find('.officer-summary-section').text
        officer_summary.shouldnt.contain('Unit')
        officer_summary.shouldnt.contain('Unit')
コード例 #9
0
    def test_filter_by_has_address(self):
        data = self.fetch_officer_allegations(has_address='true')
        len(data).should.equal(0)

        allegation1 = AllegationFactory(add1=123)
        OfficerAllegationFactory(allegation=allegation1)
        allegation2 = AllegationFactory(add2='456')
        OfficerAllegationFactory(allegation=allegation2)
        allegation3 = AllegationFactory(add1=789, add2='abc')
        OfficerAllegationFactory(allegation=allegation3)
        result_count = 3

        data = self.fetch_officer_allegations(has_address='true')
        len(data).should.equal(result_count)
        any([
            data[i]['allegation']['id'] == allegation1.id
            for i in range(result_count)
        ]).should.be.true
        any([
            data[i]['allegation']['id'] == allegation2.id
            for i in range(result_count)
        ]).should.be.true
        any([
            data[i]['allegation']['id'] == allegation3.id
            for i in range(result_count)
        ]).should.be.true
コード例 #10
0
    def test_update_officer_allegation_session(self):
        ids_to_update = [(OfficerAllegationFactory().id,
                          OfficerAllegationFactory().id) for i in range(2)]
        session_1 = SessionFactory(
            query={'filters': {
                'id': [{
                    'value': ids_to_update[0][0]
                }]
            }})
        SessionFactory(
            query={'filters': {
                'def': [{
                    'value': ids_to_update[0][0]
                }]
            }})
        session_2 = SessionFactory(query={
            'activeComplaints': [ids_to_update[1][0], ids_to_update[1][0]]
        })
        SessionFactory(query={'abc': ids_to_update[1][0]})

        update_officer_allegation_session(ids_to_update)

        session_1.refresh_from_db()
        session_1.query['filters']['id'][0]['value'].should.equal(
            ids_to_update[0][1])

        session_2.refresh_from_db()
        session_2.query['activeComplaints'].should.equal([ids_to_update[1][1]])
コード例 #11
0
    def test_filter_by_one_graph_does_not_change_others(self):
        officer_1 = OfficerFactory(race='black', gender='M')
        officer_2 = OfficerFactory(race='white', gender='F')
        officer_allegation_1 = OfficerAllegationFactory(officer=officer_1)
        officer_allegation_2 = OfficerAllegationFactory(officer=officer_2)
        ComplainingWitnessFactory(race='black',
                                  crid=officer_allegation_1.allegation.crid,
                                  gender='M',
                                  allegation=officer_allegation_1.allegation)
        ComplainingWitnessFactory(race='white',
                                  crid=officer_allegation_2.allegation.crid,
                                  gender='F',
                                  allegation=officer_allegation_2.allegation)

        response, data = self.get_race_gender_info(officer__gender='F')

        data['officers']['gender']['M'].should.equal(1)
        data['officers']['gender']['F'].should.equal(1)

        data['officers']['race'].shouldnt.contain('black')
        data['officers']['race']['white'].should.equal(1)

        data['complaining_witness']['gender'].shouldnt.contain('M')
        data['complaining_witness']['gender']['F'].should.equal(1)

        data['complaining_witness']['race'].shouldnt.contain('black')
        data['complaining_witness']['race']['white'].should.equal(1)
コード例 #12
0
 def setUp(self):
     base = datetime.now()
     self.dates = [(base + timedelta(days=x)).date() for x in range(0, 2)]
     OfficerAllegationFactory(allegation=AllegationFactory(
         incident_date_only=self.dates[1]))
     allegation = AllegationFactory(incident_date_only=None)
     OfficerAllegationFactory(allegation=allegation,
                              start_date=self.dates[0])
コード例 #13
0
 def test_create_officer_allegation_with_officer_age(self):
     officer = OfficerFactory(birth_year=1984)
     allegation = AllegationFactory(
         incident_date=datetime.datetime(2010, 1, 1))
     officer_allegation = OfficerAllegationFactory(officer=officer,
                                                   allegation=allegation)
     officer_allegation.officer_age.should.equal(26)
     OfficerAllegationFactory(allegation=AllegationFactory(
         incident_date=None)).officer_age.should.be.none
コード例 #14
0
    def test_allegation_category_on_duty(self):
        expected_allegations = [
            OfficerAllegationFactory(cat=AllegationCategoryFactory(
                on_duty=True))]
        OfficerAllegationFactory()

        query_string = 'cat__on_duty=true'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #15
0
    def test_has_location(self):
        expected_allegations = [
            OfficerAllegationFactory(
                allegation=AllegationFactory(location='4 Privet Drive'))]
        OfficerAllegationFactory()

        query_string = 'has_location=true'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #16
0
    def test_has_identified(self):
        expected_allegations = [
            OfficerAllegationFactory()]
        OfficerAllegationFactory(
            officer=None)

        query_string = 'has_identified=true'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #17
0
    def test_incident_date_time_of_day(self):
        self.clean_db()
        oa1 = OfficerAllegationFactory(allegation=AllegationFactory(
            incident_date=datetime.datetime(2007, 12, 16, 7, 30, 30)
        ))
        OfficerAllegationFactory(allegation=AllegationFactory(
            incident_date=datetime.datetime(2007, 12, 16, 16, 30, 30)
        ))

        self.check_built_query('incident_date_time_of_day=morning', [oa1.id])
コード例 #18
0
    def test_adhoc_queries(self):
        expected_allegations = [
            OfficerAllegationFactory(
                allegation=AllegationFactory(crid='1'), final_outcome='ZZ')]
        OfficerAllegationFactory(allegation=AllegationFactory(crid='1'))

        query_string = 'final_outcome=ZZ&allegation__crid=1'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #19
0
    def test_outcome_30_more_days(self):
        expected_allegations = [
            OfficerAllegationFactory(final_outcome=code)
            for code in ["045", "060", "090", "180", "200"]]
        OfficerAllegationFactory(final_outcome='ZZ')

        query_string = 'outcome_text=30 more days'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #20
0
    def test_outcome_no_discipline(self):
        expected_allegations = [
            OfficerAllegationFactory(final_finding='SU', final_outcome=code)
            for code in NO_DISCIPLINE_CODES + (None,)]
        OfficerAllegationFactory(final_finding='SU', final_outcome='ZZ')

        query_string = 'outcome_text=no discipline'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #21
0
    def test_unsustained_final_finding(self):
        expected_allegations = [
            OfficerAllegationFactory(final_finding=code)
            for code in ['DS', 'EX', 'NA', 'NC', 'NS', 'UN', 'ZZ']]
        OfficerAllegationFactory(final_finding='SU')

        query_string = 'final_finding_text=unsustained'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #22
0
    def test_has_summary(self):
        expected_allegations = [
            OfficerAllegationFactory(
                allegation=AllegationFactory(summary='Some summary'))]
        OfficerAllegationFactory()

        query_string = 'has_summary=true'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #23
0
    def test_has_document(self):
        document = DocumentFactory(documentcloud_id=1)

        expected_allegations = [OfficerAllegationFactory(allegation=document.allegation)]
        OfficerAllegationFactory()

        query_string = 'has_document=true'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #24
0
    def test_has_investigator(self):
        expected_allegations = [
            OfficerAllegationFactory()]
        OfficerAllegationFactory(
            allegation=AllegationFactory(investigator=None))

        query_string = 'has_investigator=true'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #25
0
    def test_has_address(self):
        expected_allegations = [
            OfficerAllegationFactory(allegation=AllegationFactory(add1=100)),
            OfficerAllegationFactory(allegation=AllegationFactory(add2='100'))]
        OfficerAllegationFactory()

        query_string = 'has_address=true'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #26
0
    def test_officer_discipline_count(self):
        expected_allegations = [
            OfficerAllegationFactory(
                officer=OfficerFactory(discipline_count=11))]
        OfficerAllegationFactory(officer=OfficerFactory(discipline_count=10))
        OfficerAllegationFactory(officer=OfficerFactory(discipline_count=9))

        query_string = 'officer__discipline_count__gt=10'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #27
0
    def test_complainant_age_filter(self):
        allegation_1 = AllegationFactory()
        allegation_2 = AllegationFactory()
        ComplainingWitnessFactory(age=36, allegation=allegation_1)
        ComplainingWitnessFactory(age=23, allegation=allegation_2)
        oa_1 = OfficerAllegationFactory(allegation=allegation_1)
        oa_2 = OfficerAllegationFactory(allegation=allegation_2)

        self.check_built_query('complainant_age=30-40', [oa_1.id])
        self.check_built_query('complainant_age=<30', [oa_2.id])
        self.check_built_query('complainant_age=>35', [oa_1.id])
コード例 #28
0
    def test_has_map(self):
        expected_allegations = [
            OfficerAllegationFactory()]
        allegation = OfficerAllegationFactory().allegation
        allegation.point = None
        allegation.save()

        query_string = 'has_map=true'
        expected_ids = [o.id for o in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #29
0
    def _test_investigator_agency_iad(self):
        expected_allegations = [
            OfficerAllegationFactory(allegation=AllegationFactory(
                investigator=InvestigatorFactory(agency='IAD')))]
        OfficerAllegationFactory(allegation=AllegationFactory(
            investigator=InvestigatorFactory(agency='IPRA')))

        query_string = 'allegation__investigator__agency=IAD'
        expected_ids = [allegation.id for allegation in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #30
0
 def setUp(self):
     Allegation.objects.all().delete()
     today = datetime.datetime.now().strftime(DATE_ONLY_FORMAT)
     self.foia = AllegationFactory(
         incident_date=generate_random_date(FOIA_START_DATE, today))
     OfficerAllegationFactory(allegation=self.foia)
     self.pre_foia = AllegationFactory(incident_date=generate_random_date(
         START_UNIX_TIME_DATE, FOIA_START_DATE))
     OfficerAllegationFactory(allegation=self.pre_foia,
                              start_date=generate_random_date(
                                  START_UNIX_TIME_DATE, FOIA_START_DATE))