예제 #1
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))
예제 #2
0
    def test_lookup_by_allegation_crid_with_one_officerallegation_but_same_category(self):
        allegation = AllegationFactory(crid='12345')
        category = AllegationCategoryFactory(pk=456123, category='category name')
        OfficerAllegationFactory.create_batch(2, allegation=allegation, cat=category)
        expected_url = '/complaint/12345/category-name/J84Lyq78'

        response = self.client.get('/lookup/{query}'.format(query=allegation.crid))

        response.status_code.should.equals(HTTP_301_MOVED_PERMANENTLY)
        response.url.should.contain(expected_url)
    def test_redirect_allegation_crid_sesstion_multiple_officer_allegation_but_one_category(self):
        crid = '12345'
        expected_url = '/complaint/12345/no-category/r9ME4Vao'
        allegation = AllegationFactory(crid=crid)
        OfficerAllegationFactory.create_batch(2, allegation=allegation, cat=None)

        filters = {
            'allegation__crid': [{'value': allegation.crid, 'category': 'allegation__crid'}]
        }

        urls = self.redirect_allegation_id_only_session(filters)
        urls.should.be.equal([expected_url])
    def test_query_for_repeaters(self):
        normal = OfficerFactory()
        repeater = OfficerFactory()
        OfficerAllegationFactory(officer=normal)
        OfficerAllegationFactory.create_batch(10, officer=repeater)

        management.call_command('calculate_allegations_count')

        response = self.client.get(
            '/api/officer-allegations/officers/?officer__allegations_count__gt=9')
        data = json.loads(response.content.decode())
        any([officer['id'] == repeater.id for officer in data['officers']])\
            .should.be.true
    def test_query_for_repeaters(self):
        normal = OfficerFactory()
        repeater = OfficerFactory()
        OfficerAllegationFactory(officer=normal)
        OfficerAllegationFactory.create_batch(10, officer=repeater)

        management.call_command('calculate_allegations_count')

        response = self.client.get(
            '/api/officer-allegations/officers/?officer__allegations_count__gt=9'
        )
        data = json.loads(response.content.decode())
        any([officer['id'] == repeater.id for officer in data['officers']])\
            .should.be.true
예제 #6
0
    def test_lookup_by_allegation_crid_with_one_officerallegation_but_same_category(
            self):
        allegation = AllegationFactory(crid='12345')
        category = AllegationCategoryFactory(pk=456123,
                                             category='category name')
        OfficerAllegationFactory.create_batch(2,
                                              allegation=allegation,
                                              cat=category)
        expected_url = '/complaint/12345/category-name/J84Lyq78'

        response = self.client.get(
            '/lookup/{query}'.format(query=allegation.crid))

        response.status_code.should.equals(HTTP_301_MOVED_PERMANENTLY)
        response.url.should.contain(expected_url)
    def test_query_for_discipline_count(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        OfficerAllegationFactory(officer=officer_1)
        OfficerAllegationFactory.create_batch(
            10, officer=officer_2, final_outcome_class='disciplined')

        management.call_command('calculate_allegations_count')

        response = self.client.get(
            '/api/officer-allegations/officers/?officer__discipline_count__gt=9')
        data = json.loads(response.content.decode())
        returned_officer = data['officers'][0]
        officer_2.id.should.equal(returned_officer['id'])

        len(data['officers']).should.equal(1)
    def test_query_for_discipline_count(self):
        officer_1 = OfficerFactory()
        officer_2 = OfficerFactory()
        OfficerAllegationFactory(officer=officer_1)
        OfficerAllegationFactory.create_batch(
            10, officer=officer_2, final_outcome_class='disciplined')

        management.call_command('calculate_allegations_count')

        response = self.client.get(
            '/api/officer-allegations/officers/?officer__discipline_count__gt=9'
        )
        data = json.loads(response.content.decode())
        returned_officer = data['officers'][0]
        officer_2.id.should.equal(returned_officer['id'])

        len(data['officers']).should.equal(1)
예제 #9
0
    def test_get_allegations_with_good_information(self):
        crid = 'crid1'
        other_crid = 'crid2'
        officer = OfficerFactory()
        other_officer = OfficerFactory()

        allegation = AllegationFactory(crid=crid)
        OfficerAllegationFactory.create_batch(
            2, allegation=allegation, officer=officer)

        allegation = AllegationFactory(crid=other_crid)
        OfficerAllegationFactory.create_batch(
            1, allegation=allegation, officer=other_officer)

        result = self.call_get_allegations(officer_id=officer.id)
        len(result).should.equal(2)
        result[0].crid.should.equal(str(crid))
예제 #10
0
    def test_redirect_allegation_crid_sesstion_multiple_officer_allegation_but_one_category(
            self):
        crid = '12345'
        expected_url = '/complaint/12345/no-category/r9ME4Vao'
        allegation = AllegationFactory(crid=crid)
        OfficerAllegationFactory.create_batch(2,
                                              allegation=allegation,
                                              cat=None)

        filters = {
            'allegation__crid': [{
                'value': allegation.crid,
                'category': 'allegation__crid'
            }]
        }

        urls = self.redirect_allegation_id_only_session(filters)
        urls.should.be.equal([expected_url])
예제 #11
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))
예제 #12
0
    def test_latlng(self):
        expected_allegations = OfficerAllegationFactory.create_batch(2)
        for i in range(len(expected_allegations)):
            allegation = expected_allegations[i].allegation
            allegation.point = Point(0 + i/1000, 0 + 1/1000)
            allegation.save()
        allegation = OfficerAllegationFactory().allegation
        allegation.point = Point(650, 650)
        allegation.save()

        query_string = 'latlng=0,0&radius=500'
        expected_ids = [o.id for o in expected_allegations]

        self.check_built_query(query_string, expected_ids)
예제 #13
0
 def setUp(self):
     self.officer = OfficerFactory()
     OfficerAllegationFactory.create_batch(2, officer=self.officer)
예제 #14
0
 def test_fetch_officer_allegation(self):
     OfficerAllegationFactory.create_batch(10)
     data = self.fetch_officer_allegations()
     isinstance(data, list).should.be.true
     len(data).should.equal(10)
예제 #15
0
 def setUp(self):
     self.officer = OfficerFactory()
     OfficerAllegationFactory.create_batch(2, officer=self.officer)
예제 #16
0
 def setUp(self):
     self.officer_allegations = OfficerAllegationFactory.create_batch(3)
 def setUp(self):
     self.officer_allegations = OfficerAllegationFactory.create_batch(3)