コード例 #1
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)
コード例 #2
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)
コード例 #3
0
 def test_filter_by_both_complaint_gender(self):
     allegation = self.officer_allegations[0].allegation
     ComplainingWitnessFactory.create_batch(3, crid=allegation.crid)
     data = self.fetch_officer_allegations(complainant_gender=['M', 'F'])
     for row in data:
         genders = [x['gender'] for x in row['complaining_witness']]
         genders.should.be.ok
コード例 #4
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])
コード例 #5
0
    def test_race_gender_api_that_complaint_doesnt_contain_in_allegations(
            self):
        OfficerFactory(race='black', gender='M')
        OfficerFactory(race='white', gender='F')
        ComplainingWitnessFactory(race='black', gender='M')
        ComplainingWitnessFactory(race='white', gender='F')

        response, data = self.get_race_gender_info()

        response.status_code.should.equal(status.HTTP_200_OK)
        for x in ['officers', 'complaining_witness']:
            data[x]['gender'].shouldnt.contain('M')
            data[x]['gender'].shouldnt.contain('F')
            data[x]['race'].shouldnt.contain('black')
            data[x]['race'].shouldnt.contain('white')
コード例 #6
0
    def test_complaining_witness_sheet(self, mock_workbook):
        allegation = AllegationFactory()
        witness = ComplainingWitnessFactory(allegation=allegation,
                                            crid=allegation.crid)
        officer_allegation = OfficerAllegationFactory(allegation=allegation)
        allegation_download = AllegationsDownload(DownloadFactory().id)
        allegation_download.officer_allegations = [officer_allegation]
        allegation_download.update_crids()
        allegation_download.write_headers = MagicMock()

        with patch('allegation.services.download_allegations.os'):
            allegation_download.init_workbook()
            mock_worksheet = MagicMock()
            allegation_download.workbook.add_worksheet = MagicMock(
                return_value=mock_worksheet)

            allegation_download.write_complaint_witnesses()
            (sheet, columns), _ = allegation_download.write_headers.call_args
            sheet.should.equal(mock_worksheet)
            columns.should.equal(['CRID', 'Gender', 'Race', 'Age'])

            mock_worksheet.write.assert_any_call(1, 0, str(allegation.crid))
            mock_worksheet.write.assert_any_call(1, 1, witness.gender)
            mock_worksheet.write.assert_any_call(1, 2, witness.race)
            mock_worksheet.write.assert_any_call(1, 3, witness.age)
コード例 #7
0
ファイル: test_fix_race.py プロジェクト: pdflu/CPDB
 def setUp(self):
     Officer.objects.all().delete()
     ComplainingWitness.objects.all().delete()
     self.good_races = [x[1] for x in RACES]  # pardon the variable name
     self.bad_races = [x[0] for x in RACES]  # again, see ^
     for race in RACES:
         ComplainingWitnessFactory(race=race[0])
         OfficerFactory(race=race[0])
コード例 #8
0
 def test_filter_by_complaint_race(self):
     allegation = self.officer_allegations[0].allegation
     witnesses = ComplainingWitnessFactory.create_batch(
         3, crid=allegation.crid)
     race = witnesses[0].race
     data = self.fetch_officer_allegations(complainant_race=race)
     for row in data:
         races = [x['race'] for x in row['complaining_witness']]
         races.should.contain(race)
コード例 #9
0
    def test_complaint_gender(self):
        allegation = AllegationFactory()
        ComplainingWitnessFactory(
            crid=allegation.crid, allegation=allegation, gender='M')
        expected_allegations = [
            OfficerAllegationFactory(allegation=allegation)]

        allegation_2 = AllegationFactory()
        ComplainingWitnessFactory(
            crid=allegation_2.crid, allegation=allegation_2, gender='F')
        OfficerAllegationFactory(allegation=allegation_2)

        OfficerAllegationFactory()

        query_string = 'complainant_gender=M'
        expected_ids = [x.id for x in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #10
0
 def populate_witness_data(self):
     allegations = [AllegationFactory() for i in range(5)]
     witness_stats = [
         {'race': 'White', 'gender': 'M', 'age': 15},
         {'race': 'Black', 'gender': 'F', 'age': 21},
         {'race': 'Black', 'gender': 'M', 'age': 32},
         {'race': 'White', 'gender': 'F', 'age': 43},
         {'race': 'Hispanic', 'gender': 'X', 'age': 53},
     ]
     [ComplainingWitnessFactory(allegation=allegations[ind], **stat)
      for ind, stat in enumerate(witness_stats)]
     [OfficerAllegationFactory(allegation=allegation) for allegation in allegations]
コード例 #11
0
    def test_complaint_race(self):
        allegation = AllegationFactory()
        ComplainingWitnessFactory(
            crid=allegation.crid, allegation=allegation, race='Black')
        allegation_2 = AllegationFactory()
        ComplainingWitnessFactory(
            crid=allegation_2.crid, allegation=allegation_2, race='Asian')
        expected_allegations = [
            OfficerAllegationFactory(allegation=allegation),
            OfficerAllegationFactory(allegation=allegation_2)]

        allegation_3 = AllegationFactory()
        ComplainingWitnessFactory(
            crid=allegation_3.crid, allegation=allegation_3, race='White')
        OfficerAllegationFactory(allegation=allegation_3)

        OfficerAllegationFactory()

        query_string = 'complainant_race=Black&complainant_race=Asian'
        expected_ids = [x.id for x in expected_allegations]

        self.check_built_query(query_string, expected_ids)
コード例 #12
0
    def test_race_gender_api_with_filter(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(
            allegation__crid=officer_allegation_2.allegation.crid)

        response.status_code.should.equal(status.HTTP_200_OK)
        for x in ['officers', 'complaining_witness']:
            data[x]['gender'].should.contain('F')
            data[x]['gender'].shouldnt.contain('M')
            data[x]['race'].shouldnt.contain('black')
            data[x]['race'].should.contain('white')
コード例 #13
0
    def setUp(self):
        super(DownloadAllegationTestCase, self).setUp()
        allegation = AllegationFactory()
        OfficerAllegationFactory(allegation=allegation)
        PoliceWitnessFactory(crid=allegation.crid)
        ComplainingWitnessFactory(crid=allegation.crid)
        self.get_admin_settings()

        self.visit_home()
        self.browser.execute_script("window.redirect = function () {};"
                                    )  # disable excel redirect on testing

        self.click_first_officer()
        self.until(lambda: self.download_link.is_displayed())
コード例 #14
0
    def test_complaining_witness_not_repeated(self):
        OfficerAllegation.objects.all().delete()
        allegation = AllegationFactory()
        complaining_witness = ComplainingWitnessFactory(allegation=allegation)

        OfficerAllegationFactory(allegation=allegation)
        OfficerAllegationFactory(allegation=allegation)
        OfficerAllegationFactory(allegation=allegation)

        data = self.fetch_officer_allegations(allegation_id=allegation.pk)

        len(data).should.equal(3)
        len(data[0]['complaining_witness']).should.equal(1)
        for c in data:
            c['complaining_witness'][0]['cwit_id'].should.equal(
                complaining_witness.pk)
コード例 #15
0
    def test_allegation_with_full_information(self):
        view_document_text = 'View'

        officer_gender = 'X'
        officer_gender_display = 'X'

        complaint_witness_gender = 'F'
        complaint_witness_race = 'Black'
        complaint_witness_age = 40
        complaint_witness_text = 'Female, Black, Age 40'
        address1 = 4748
        address2 = 'N Kimball Ave'
        addresss = '{add1} {add2}'.format(add1=address1, add2=address2)
        category = AllegationCategoryFactory()
        officer = OfficerFactory(gender=officer_gender)
        current_rank = 'SERGEANT OF POLICE'
        investigator = InvestigatorFactory(current_rank=current_rank)
        allegation = AllegationFactory(
            investigator=investigator, add1=address1, add2=address2,
            city='Chicago, IL', location='15')
        DocumentFactory(documentcloud_id=123, allegation=allegation)
        OfficerAllegationFactory(cat=category, officer=officer, allegation=allegation)

        ComplainingWitnessFactory(
            crid=allegation.crid, gender=complaint_witness_gender,
            allegation=allegation,
            race=complaint_witness_race, age=complaint_witness_age)

        self.visit_complaint_page(allegation.crid, category.id)
        self.until(lambda: self.find('.crid-number'))
        self.until(lambda: self.find('.allegation-category').text.should.be.equal(category.category))
        self.find('.allegation-name').text.should.be.equal(category.allegation_name)

        self.should_see_text(officer.display_name, '.against-section')
        self.should_see_text(officer_gender_display, '.against-section')
        self.should_see_text(complaint_witness_text, '.complaining-witness-list')
        self.should_see_text(investigator.name, '.investigator .name')
        self.should_see_text(investigator.current_rank, '.investigator .rank')
        self.should_see_text(allegation.beat.name, '.location-detail')

        self.should_see_text(view_document_text, '.document-card')

        location_detail = self.find('.location-detail').text
        location_detail.should.contain(addresss)
        location_detail.should.contain(allegation.city)
        location_detail.should.contain(allegation.location)
コード例 #16
0
    def test_successfully_call_the_api(self):
        officer = OfficerFactory()
        officer_allegation = OfficerAllegationFactory(officer=officer)
        allegation = officer_allegation.allegation
        complaining_witness = ComplainingWitnessFactory(allegation=allegation)

        response, data = self.call_allegation_api({'crid': allegation.crid})
        response.status_code.should.equal(HTTP_200_OK)

        data['allegation']['crid'].should.be.equal(str(allegation.crid))
        data['allegation']['point']['x'].should.be.equal(allegation.point.x)
        data['allegation']['point']['y'].should.be.equal(allegation.point.y)

        len(data['allegation']['officer_allegation_set']).should.be.equal(1)
        data['allegation']['officer_allegation_set'][0]['officer'][
            'id'].should.be.equal(officer.pk)

        len(data['complaining_witnesses']).should.be.equal(1)
        data['complaining_witnesses'][0]['race'].should.be.equal(
            complaining_witness.race)
        data['complaining_witnesses'][0]['gender'].should.be.equal(
            complaining_witness.gender)
        data['complaining_witnesses'][0]['age'].should.be.equal(
            complaining_witness.age)