コード例 #1
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_unknown_resident_weapon_returned(self):
     ''' Cleaning an unknown weapon returns the same value passed.
     '''
     cleaner = Cleaners()
     weapon = "Suspect - Lewd Nebulosity "
     cleaned = cleaner.resident_weapon_used(weapon)
     assert cleaned == weapon
コード例 #2
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_unknown_gender_returned(self):
     ''' Cleaning an unknown gender returns the same value passed.
     '''
     cleaner = Cleaners()
     gender = "Golf"
     cleaned = cleaner.sex(gender)
     assert cleaned == gender
コード例 #3
0
    def test_correct_complaint_cap (self, testapp):
        ''' New complaint data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="IM Police Department", short_name="IMPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="******")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of complaint descriptions from the JSON test client
        test_client = JSONTestClient()
        complaint_count = 1
        complaint_data = test_client.get_prebaked_complaints(last=complaint_count)
        complaint_data[0]["allegation"] = "Rude, demeaning, or affronting language"

        # post the json to the complaint URL
        response = testapp.post_json("/data/complaints", params={'month': 0, 'year': 0, 'data': complaint_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == complaint_count

        # check the complaint incident in the database against the data that was sent
        cleaner = Cleaners()
        sent_complaint = cleaner.capitalize_incident(complaint_data[0])
        check_complaint = CitizenComplaintIMPD.query.filter_by(opaque_id=sent_complaint['opaqueId']).first()
        assert check_complaint.allegation == "Rude, Demeaning, or Affronting Language"
        with open("scratch.txt", "w") as text_file:
            text_file.write("Complaint Data: {} ".format(check_complaint.allegation))
コード例 #4
0
    def test_post_assaults_data(self, testapp):
        ''' New assaults data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="IM Police Department", short_name="IMPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="******")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of assault descriptions from the JSON test client
        test_client = JSONTestClient()
        assault_count = 1
        assault_data = test_client.get_prebaked_assaults(last=assault_count)
        # post the json to the assault URL
        response = testapp.post_json("/data/assaults", params={'month': 0, 'year': 0, 'data': assault_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == assault_count

        # check the assault incident in the database against the data that was sent
        cleaner = Cleaners()
        sent_assault = cleaner.capitalize_incident(assault_data[0])
        check_assault = AssaultOnOfficerIMPD.query.filter_by(opaque_id=sent_assault['opaqueId']).first()
        assert check_assault.service_type == sent_assault['serviceType']
        assert check_assault.force_type == sent_assault['forceType']
        assert check_assault.assignment == sent_assault['assignment']
        assert check_assault.arrest_made == sent_assault['arrestMade']
        assert check_assault.officer_injured == sent_assault['officerInjured']
        assert check_assault.officer_killed == sent_assault['officerKilled']
        assert check_assault.report_filed == sent_assault['reportFiled']
コード例 #5
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_known_genders_cleaned(self):
     ''' Cleaning known genders returns the expected value.
     '''
     cleaner = Cleaners()
     for gender in GENDER_LOOKUP:
         check_gender = cleaner.sex(gender)
         assert check_gender == GENDER_LOOKUP[gender]
コード例 #6
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_known_races_cleaned(self):
     ''' Cleaning known races returns the expected value.
     '''
     cleaner = Cleaners()
     for race in RACE_LOOKUP:
         check_race = cleaner.race(race)
         assert check_race == RACE_LOOKUP[race]
コード例 #7
0
 def test_unknown_officer_force_type_returned(self):
     """ Cleaning an unknown weapon returns the same value passed.
     """
     cleaner = Cleaners()
     force_type = "Bugbear Squeeze"
     cleaned = cleaner.officer_force_type(force_type)
     assert cleaned == force_type
コード例 #8
0
ファイル: 43c4c512514_.py プロジェクト: vcgato29/comport
def upgrade():
    complaints = CitizenComplaintIMPD.query.all()
    cleaner = Cleaners()
    for complaint in complaints:
        new_allegation = cleaner.capitalize(complaint.allegation)
        if complaint.allegation != new_allegation:
            complaint.update(allegation=new_allegation)
コード例 #9
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_known_officer_force_types_cleaned(self):
     ''' Cleaning known weapons returns the expected value.
     '''
     cleaner = Cleaners()
     for force_type in OFFICER_FORCE_TYPE_LOOKUP:
         check_force_type = cleaner.officer_force_type(force_type)
         assert check_force_type == OFFICER_FORCE_TYPE_LOOKUP[force_type]
コード例 #10
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_unknown_officer_force_type_returned(self):
     ''' Cleaning an unknown weapon returns the same value passed.
     '''
     cleaner = Cleaners()
     force_type = "Bugbear Squeeze"
     cleaned = cleaner.officer_force_type(force_type)
     assert cleaned == force_type
コード例 #11
0
 def test_known_genders_cleaned(self):
     """ Cleaning known genders returns the expected value.
     """
     cleaner = Cleaners()
     for gender in GENDER_LOOKUP:
         check_gender = cleaner.sex(gender)
         assert check_gender == GENDER_LOOKUP[gender]
コード例 #12
0
 def test_known_races_cleaned(self):
     """ Cleaning known races returns the expected value.
     """
     cleaner = Cleaners()
     for race in RACE_LOOKUP:
         check_race = cleaner.race(race)
         assert check_race == RACE_LOOKUP[race]
コード例 #13
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_unknown_race_returned(self):
     ''' Cleaning an unknown race returns the same value passed.
     '''
     cleaner = Cleaners()
     race = "Comet"
     cleaned = cleaner.race(race)
     assert cleaned == race
コード例 #14
0
 def test_known_officer_force_types_cleaned(self):
     """ Cleaning known weapons returns the expected value.
     """
     cleaner = Cleaners()
     for force_type in OFFICER_FORCE_TYPE_LOOKUP:
         check_force_type = cleaner.officer_force_type(force_type)
         assert check_force_type == OFFICER_FORCE_TYPE_LOOKUP[force_type]
コード例 #15
0
 def test_unknown_race_returned(self):
     """ Cleaning an unknown race returns the same value passed.
     """
     cleaner = Cleaners()
     race = "Comet"
     cleaned = cleaner.race(race)
     assert cleaned == race
コード例 #16
0
 def test_known_resident_weapons_cleaned(self):
     """ Cleaning known weapons returns the expected value.
     """
     cleaner = Cleaners()
     for weapon in RESIDENT_WEAPONS_LOOKUP:
         check_weapon = cleaner.resident_weapon_used(weapon)
         assert check_weapon == RESIDENT_WEAPONS_LOOKUP[weapon]
コード例 #17
0
 def test_unknown_resident_weapon_returned(self):
     """ Cleaning an unknown weapon returns the same value passed.
     """
     cleaner = Cleaners()
     weapon = "Suspect - Lewd Nebulosity "
     cleaned = cleaner.resident_weapon_used(weapon)
     assert cleaned == weapon
コード例 #18
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_known_resident_weapons_cleaned(self):
     ''' Cleaning known weapons returns the expected value.
     '''
     cleaner = Cleaners()
     for weapon in RESIDENT_WEAPONS_LOOKUP:
         check_weapon = cleaner.resident_weapon_used(weapon)
         assert check_weapon == RESIDENT_WEAPONS_LOOKUP[weapon]
コード例 #19
0
 def test_unknown_gender_returned(self):
     """ Cleaning an unknown gender returns the same value passed.
     """
     cleaner = Cleaners()
     gender = "Golf"
     cleaned = cleaner.sex(gender)
     assert cleaned == gender
コード例 #20
0
 def test_capitalization(self):
     ''' A phrase is title-cased with expected exceptions.
     '''
     cleaner = Cleaners()
     in_sentence = "I thought I would sail about a little and see the watery part of the world"
     titlecased_sentence = titlecase(in_sentence)
     send = " ".join(i.lower() + " " + j.lower() for i, j in zip(in_sentence.split(" "), CAPITALIZE_LIST))
     check = " ".join(i + " " + j for i, j in zip(titlecased_sentence.split(" "), CAPITALIZE_LIST))
     result = cleaner.capitalize(send)
     assert check == result
コード例 #21
0
 def test_capitalization(self):
     """ A phrase is title-cased with expected exceptions.
     """
     cleaner = Cleaners()
     in_sentence = "I thought I would sail about a little and see the watery part of the world"
     titlecased_sentence = titlecase(in_sentence)
     send = " ".join(i.lower() + " " + j.lower() for i, j in zip(in_sentence.split(" "), CAPITALIZE_LIST))
     check = " ".join(i + " " + j for i, j in zip(titlecased_sentence.split(" "), CAPITALIZE_LIST))
     result = cleaner.capitalize(send)
     assert check == result
コード例 #22
0
 def test_captilization_handles_non_strings(self):
     """ Non-strings passed to capitalize aren't altered.
     """
     cleaner = Cleaners()
     send_int = 23
     send_float = 32.01
     send_list = ["I", "thought", "I", "would", "sail"]
     result_int = cleaner.capitalize(send_int)
     result_float = cleaner.capitalize(send_float)
     result_list = cleaner.capitalize(send_list)
     assert send_int == result_int
     assert send_float == result_float
     assert send_list == result_list
コード例 #23
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_captilization_handles_non_strings(self):
     ''' Non-strings passed to capitalize aren't altered.
     '''
     cleaner = Cleaners()
     send_int = 23
     send_float = 32.01
     send_list = ["I", "thought", "I", "would", "sail"]
     result_int = cleaner.capitalize(send_int)
     result_float = cleaner.capitalize(send_float)
     result_list = cleaner.capitalize(send_list)
     assert send_int == result_int
     assert send_float == result_float
     assert send_list == result_list
コード例 #24
0
    def test_post_mistyped_complaint_data(self, testapp):
        ''' New complaint data from the extractor with wrongly typed data is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="******")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of complaint descriptions from the JSON test client
        test_client = JSONTestClient()
        complaint_count = 1
        complaint_data = test_client.get_prebaked_complaints(last=complaint_count)

        # The app expects number values to be transmitted as strings. Let's change them to integers.
        complaint_data[0]['residentAge'] = 28
        complaint_data[0]['officerAge'] = 46
        complaint_data[0]['officerYearsOfService'] = 17

        # post the json to the complaint URL
        response = testapp.post_json("/data/complaints", params={'month': 0, 'year': 0, 'data': complaint_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == complaint_count

        # check the complaint incident in the database against the data that was sent
        cleaner = Cleaners()
        sent_complaint = cleaner.capitalize_incident(complaint_data[0])
        check_complaint = CitizenComplaint.query.filter_by(opaque_id=sent_complaint['opaqueId']).first()
        assert check_complaint.occured_date.strftime('%Y-%m-%d %-H:%-M:%S') == sent_complaint['occuredDate']
        assert check_complaint.division == sent_complaint['division']
        assert check_complaint.precinct == sent_complaint['precinct']
        assert check_complaint.shift == sent_complaint['shift']
        assert check_complaint.beat == sent_complaint['beat']
        assert check_complaint.disposition == sent_complaint['disposition']
        assert check_complaint.service_type == sent_complaint['serviceType']
        assert check_complaint.source == sent_complaint['source']
        assert check_complaint.allegation_type == sent_complaint['allegationType']
        assert check_complaint.allegation == sent_complaint['allegation']
        assert check_complaint.resident_race == cleaner.race(sent_complaint['residentRace'])
        assert check_complaint.resident_sex == cleaner.sex(sent_complaint['residentSex'])
        assert check_complaint.resident_age == cleaner.number_to_string(sent_complaint['residentAge'])
        assert check_complaint.officer_identifier == sent_complaint['officerIdentifier']
        assert check_complaint.officer_race == cleaner.race(sent_complaint['officerRace'])
        assert check_complaint.officer_sex == cleaner.sex(sent_complaint['officerSex'])
        assert check_complaint.officer_age == cleaner.number_to_string(sent_complaint['officerAge'])
        assert check_complaint.officer_years_of_service == cleaner.number_to_string(sent_complaint['officerYearsOfService'])
コード例 #25
0
 def test_number_to_string(self):
     """ Numbers are turned into strings.
     """
     cleaner = Cleaners()
     in_int = 85
     in_float = 82.12
     in_string = "big frame, small spirit!"
     in_list = ["hands", "by", "the", "halyards"]
     in_none = None
     assert cleaner.number_to_string(in_int) == str(in_int)
     assert cleaner.number_to_string(in_float) == str(in_float)
     assert cleaner.number_to_string(in_string) == in_string
     assert cleaner.number_to_string(in_list) == in_list
     assert cleaner.number_to_string(in_none) is None
コード例 #26
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_capitalization_inside_parentheses(self):
     ''' Words are left titlecased even if they're inside parentheses
     '''
     cleaner = Cleaners()
     in_sentence = "I thought I would sail about a little and see the watery part of the world"
     titlecased_sentence = titlecase(in_sentence)
     send = " ".join(
         i.lower() + " (" + j.lower() + ")"
         for i, j in zip(in_sentence.split(" "), CAPITALIZE_LIST))
     check = " ".join(
         i + " (" + j + ")"
         for i, j in zip(titlecased_sentence.split(" "), CAPITALIZE_LIST))
     result = cleaner.capitalize(send)
     assert check == result
コード例 #27
0
    def test_incident_capitalization(self):
        """ Incident descriptions are title-cased with expected exceptions.
        """
        cleaner = Cleaners()
        in_sentence = "Northwest and east district"
        send = {}
        send["division"] = in_sentence
        send["precinct"] = in_sentence
        for key in CAPITALIZE_IGNORE_KEYS_LIST:
            send[key] = in_sentence

        result = cleaner.capitalize_incident(send)

        # values of keys not in the list should be titlecased
        titlecased_sentence = "Northwest and East District"
        assert result["division"] == titlecased_sentence
        assert result["precinct"] == titlecased_sentence
        # values of keys in the list should not be titlecased
        for key in CAPITALIZE_IGNORE_KEYS_LIST:
            assert result[key] == in_sentence
コード例 #28
0
    def test_incident_capitalization(self):
        ''' Incident descriptions are title-cased with expected exceptions.
        '''
        cleaner = Cleaners()
        in_sentence = "It is a way I have of driving off the spleen and regulating the circulation"
        titlecased_sentence = titlecase(in_sentence)
        send = {}
        send["damp"] = in_sentence
        send["drizzly"] = in_sentence
        for key in CAPITALIZE_IGNORE_KEYS_LIST:
            send[key] = in_sentence

        result = cleaner.capitalize_incident(send)

        # values of keys not in the list should be titlecased
        assert result["damp"] == titlecased_sentence
        assert result["drizzly"] == titlecased_sentence
        # values of keys in the list should not be titlecased
        for key in CAPITALIZE_IGNORE_KEYS_LIST:
            assert result[key] == in_sentence
コード例 #29
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
    def test_incident_capitalization(self):
        ''' Incident descriptions are title-cased with expected exceptions.
        '''
        cleaner = Cleaners()
        in_sentence = "Northwest and east district"
        send = {}
        send["division"] = in_sentence
        send["precinct"] = in_sentence
        for key in CAPITALIZE_IGNORE_KEYS_LIST:
            send[key] = in_sentence

        result = cleaner.capitalize_incident(send)

        # values of keys not in the list should be titlecased
        titlecased_sentence = "Northwest and East District"
        assert result["division"] == titlecased_sentence
        assert result["precinct"] == titlecased_sentence
        # values of keys in the list should not be titlecased
        for key in CAPITALIZE_IGNORE_KEYS_LIST:
            assert result[key] == in_sentence
コード例 #30
0
 def test_string_to_integer(self):
     ''' Strings are turned into integers.
     '''
     cleaner = Cleaners()
     in_string_success_int = '85'
     in_string_success_float = '33.34'
     in_int = 85
     in_float = 82.12
     in_string_fail = 'whaleman'
     in_list = ["hands", "by", "the", "halyards"]
     in_none = None
     assert cleaner.string_to_integer(in_string_success_int) == int(in_string_success_int)
     assert cleaner.string_to_integer(in_string_success_float) == int(float(in_string_success_float))
     assert cleaner.string_to_integer(in_int) == in_int
     assert cleaner.string_to_integer(in_float) == int(in_float)
     assert cleaner.string_to_integer(in_string_fail) is None
     assert cleaner.string_to_integer(in_list) is None
     assert cleaner.string_to_integer(in_none) is None
コード例 #31
0
ファイル: test_cleaners.py プロジェクト: vcgato29/comport
 def test_number_to_string(self):
     ''' Numbers are turned into strings.
     '''
     cleaner = Cleaners()
     in_int = 85
     in_float = 82.12
     in_string = "big frame, small spirit!"
     in_list = ["hands", "by", "the", "halyards"]
     in_none = None
     assert cleaner.number_to_string(in_int) == str(in_int)
     assert cleaner.number_to_string(in_float) == str(in_float)
     assert cleaner.number_to_string(in_string) == in_string
     assert cleaner.number_to_string(in_list) == in_list
     assert cleaner.number_to_string(in_none) is None
コード例 #32
0
 def test_string_to_integer(self):
     """ Strings are turned into integers.
     """
     cleaner = Cleaners()
     in_string_success_int = "85"
     in_string_success_float = "33.34"
     in_int = 85
     in_float = 82.12
     in_string_fail = "whaleman"
     in_list = ["hands", "by", "the", "halyards"]
     in_none = None
     assert cleaner.string_to_integer(in_string_success_int) == int(in_string_success_int)
     assert cleaner.string_to_integer(in_string_success_float) == int(float(in_string_success_float))
     assert cleaner.string_to_integer(in_int) == in_int
     assert cleaner.string_to_integer(in_float) == int(in_float)
     assert cleaner.string_to_integer(in_string_fail) is None
     assert cleaner.string_to_integer(in_list) is None
     assert cleaner.string_to_integer(in_none) is None
コード例 #33
0
    def test_update_complaint_data(self, testapp):
        ''' Updated complaint data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="IM Police Department", short_name="IMPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="******")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of complaint descriptions from the JSON test client
        test_client = JSONTestClient()
        complaint_data = test_client.get_prebaked_complaints(last=1)
        # post the json to the complaint URL
        response = testapp.post_json("/data/complaints", params={'month': 0, 'year': 0, 'data': complaint_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == 1

        # Get the second pre-baked complaint
        updated_complaint_data = test_client.get_prebaked_complaints(first=1, last=2)
        # Swap in the opaque ID from the first complaint
        updated_complaint_data[0]["opaqueId"] = complaint_data[0]["opaqueId"]
        # The complaint won't be a match unless these fields are the same
        updated_complaint_data[0]["allegationType"] = complaint_data[0]["allegationType"]
        updated_complaint_data[0]["allegation"] = complaint_data[0]["allegation"]
        updated_complaint_data[0]["officerIdentifier"] = complaint_data[0]["officerIdentifier"]
        updated_complaint_data[0]["residentRace"] = complaint_data[0]["residentRace"]
        updated_complaint_data[0]["residentSex"] = complaint_data[0]["residentSex"]
        updated_complaint_data[0]["residentAge"] = complaint_data[0]["residentAge"]
        # post the json to the complaint URL
        response = testapp.post_json("/data/complaints", params={'month': 0, 'year': 0, 'data': updated_complaint_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 1
        assert response.json_body['added'] == 0

        # There's only one complaint in the database.
        all_complaints = CitizenComplaintIMPD.query.all()
        assert len(all_complaints) == 1

        # check the complaint incident in the database against the updated data that was sent
        cleaner = Cleaners()
        sent_complaint = cleaner.capitalize_incident(updated_complaint_data[0])
        check_complaint = CitizenComplaintIMPD.query.filter_by(opaque_id=sent_complaint['opaqueId']).first()
        assert check_complaint.occured_date.strftime('%Y-%m-%d %-H:%-M:%S') == sent_complaint['occuredDate']
        assert check_complaint.division == sent_complaint['division']
        assert check_complaint.precinct == sent_complaint['precinct']
        assert check_complaint.shift == sent_complaint['shift']
        assert check_complaint.beat == sent_complaint['beat']
        assert check_complaint.disposition == sent_complaint['disposition']
        assert check_complaint.service_type == sent_complaint['serviceType']
        assert check_complaint.source == sent_complaint['source']
        assert check_complaint.allegation_type == sent_complaint['allegationType']
        assert check_complaint.allegation == sent_complaint['allegation']
        assert check_complaint.resident_race == cleaner.race(sent_complaint['residentRace'])
        assert check_complaint.resident_sex == cleaner.sex(sent_complaint['residentSex'])
        assert check_complaint.resident_age == cleaner.number_to_string(sent_complaint['residentAge'])
        assert check_complaint.officer_identifier == sent_complaint['officerIdentifier']
        assert check_complaint.officer_race == cleaner.race(sent_complaint['officerRace'])
        assert check_complaint.officer_sex == cleaner.sex(sent_complaint['officerSex'])
        assert check_complaint.officer_age == cleaner.number_to_string(sent_complaint['officerAge'])
        assert check_complaint.officer_years_of_service == cleaner.number_to_string(sent_complaint['officerYearsOfService'])
コード例 #34
0
    def test_post_mistyped_uof_data(self, testapp):
        ''' New UOF data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="IM Police Department", short_name="IMPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="******")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of UOF descriptions from the JSON test client
        test_client = JSONTestClient()
        uof_count = 1
        uof_data = test_client.get_prebaked_uof(last=uof_count)

        # The app expects number values to be transmitted as strings. Let's change them to integers.
        uof_data[0]['residentAge'] = 28
        uof_data[0]['officerAge'] = 46
        uof_data[0]['officerYearsOfService'] = 17

        # post the json to the UOF URL
        response = testapp.post_json("/data/UOF", params={'month': 0, 'year': 0, 'data': uof_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == uof_count

        # check the uof incident in the database against the data that was sent
        cleaner = Cleaners()
        sent_uof = uof_data[0]
        check_uof = UseOfForceIncidentIMPD.query.filter_by(opaque_id=sent_uof['opaqueId']).first()
        assert check_uof.occured_date.strftime('%Y-%m-%d %-H:%-M:%S') == sent_uof['occuredDate']
        assert check_uof.division == cleaner.capitalize(sent_uof['division'])
        assert check_uof.precinct == cleaner.capitalize(sent_uof['precinct'])
        assert check_uof.shift == cleaner.capitalize(sent_uof['shift'])
        assert check_uof.beat == cleaner.capitalize(sent_uof['beat'])
        assert check_uof.disposition == sent_uof['disposition']
        assert check_uof.officer_force_type == cleaner.officer_force_type(sent_uof['officerForceType'])
        assert check_uof.use_of_force_reason == sent_uof['useOfForceReason']
        assert check_uof.service_type == sent_uof['serviceType']
        assert check_uof.arrest_made == sent_uof['arrestMade']
        assert check_uof.arrest_charges == sent_uof['arrestCharges']
        assert check_uof.resident_weapon_used == sent_uof['residentWeaponUsed']
        assert check_uof.resident_injured == sent_uof['residentInjured']
        assert check_uof.resident_hospitalized == sent_uof['residentHospitalized']
        assert check_uof.officer_injured == sent_uof['officerInjured']
        assert check_uof.officer_hospitalized == sent_uof['officerHospitalized']
        assert check_uof.resident_race == cleaner.race(sent_uof['residentRace'])
        assert check_uof.resident_sex == cleaner.sex(sent_uof['residentSex'])
        assert check_uof.resident_age == cleaner.number_to_string(sent_uof['residentAge'])
        assert check_uof.resident_condition == sent_uof['residentCondition']
        assert check_uof.officer_identifier == sent_uof['officerIdentifier']
        assert check_uof.officer_race == cleaner.race(sent_uof['officerRace'])
        assert check_uof.officer_sex == cleaner.sex(sent_uof['officerSex'])
        assert check_uof.officer_age == cleaner.number_to_string(sent_uof['officerAge'])
        assert check_uof.officer_years_of_service == cleaner.number_to_string(sent_uof['officerYearsOfService'])
        assert check_uof.officer_condition == sent_uof['officerCondition']
コード例 #35
0
ファイル: test_cleaners.py プロジェクト: mehmadi/comport
 def test_unknown_race_returned(self):
     ''' Cleaning an unknown race returns the same value passed.
     '''
     race = "Comet"
     cleaned = Cleaners.race(race)
     assert cleaned == race
コード例 #36
0
ファイル: test_cleaners.py プロジェクト: mehmadi/comport
 def test_known_races_cleaned(self):
     ''' Cleaning known races returns the expected value.
     '''
     for race in RACE_LOOKUP:
         check_race = Cleaners.race(race)
         assert check_race == RACE_LOOKUP[race]
コード例 #37
0
ファイル: test_cleaners.py プロジェクト: mehmadi/comport
 def test_unknown_gender_returned(self):
     ''' Cleaning an unknown gender returns the same value passed.
     '''
     gender = "Golf"
     cleaned = Cleaners.sex(gender)
     assert cleaned == gender
コード例 #38
0
    def test_update_uof_data(self, testapp):
        ''' Updated UOF data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="******")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of UOF descriptions from the JSON test client
        test_client = JSONTestClient()
        uof_data = test_client.get_prebaked_uof(last=1)
        # post the json to the UOF URL
        response = testapp.post_json("/data/UOF", params={'month': 0, 'year': 0, 'data': uof_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == 1

        # Get the second pre-baked uof incident
        updated_uof_data = test_client.get_prebaked_uof(first=1, last=2)
        # Swap in the opaque ID from the first uof incident
        updated_uof_data[0]["opaqueId"] = uof_data[0]["opaqueId"]
        # The uof incident won't be a match unless these fields are the same
        updated_uof_data[0]["officerIdentifier"] = uof_data[0]["officerIdentifier"]
        updated_uof_data[0]["officerForceType"] = uof_data[0]["officerForceType"]
        # post the json to the uof URL
        response = testapp.post_json("/data/UOF", params={'month': 0, 'year': 0, 'data': updated_uof_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 1
        assert response.json_body['added'] == 0

        # There's only one complaint in the database.
        all_uof = UseOfForceIncident.query.all()
        assert len(all_uof) == 1

        # check the uof incident in the database against the updated data that was sent
        cleaner = Cleaners()
        sent_uof = updated_uof_data[0]
        check_uof = UseOfForceIncident.query.filter_by(opaque_id=sent_uof['opaqueId']).first()
        assert check_uof.occured_date.strftime('%Y-%m-%d %-H:%-M:%S') == sent_uof['occuredDate']
        assert check_uof.division == cleaner.capitalize(sent_uof['division'])
        assert check_uof.precinct == cleaner.capitalize(sent_uof['precinct'])
        assert check_uof.shift == cleaner.capitalize(sent_uof['shift'])
        assert check_uof.beat == cleaner.capitalize(sent_uof['beat'])
        assert check_uof.disposition == sent_uof['disposition']
        assert check_uof.officer_force_type == cleaner.officer_force_type(sent_uof['officerForceType'])
        assert check_uof.use_of_force_reason == sent_uof['useOfForceReason']
        assert check_uof.service_type == sent_uof['serviceType']
        assert check_uof.arrest_made == sent_uof['arrestMade']
        assert check_uof.arrest_charges == sent_uof['arrestCharges']
        assert check_uof.resident_weapon_used == sent_uof['residentWeaponUsed']
        assert check_uof.resident_injured == sent_uof['residentInjured']
        assert check_uof.resident_hospitalized == sent_uof['residentHospitalized']
        assert check_uof.officer_injured == sent_uof['officerInjured']
        assert check_uof.officer_hospitalized == sent_uof['officerHospitalized']
        assert check_uof.resident_race == cleaner.race(sent_uof['residentRace'])
        assert check_uof.resident_sex == cleaner.sex(sent_uof['residentSex'])
        assert check_uof.resident_age == cleaner.number_to_string(sent_uof['residentAge'])
        assert check_uof.resident_condition == sent_uof['residentCondition']
        assert check_uof.officer_identifier == sent_uof['officerIdentifier']
        assert check_uof.officer_race == cleaner.race(sent_uof['officerRace'])
        assert check_uof.officer_sex == cleaner.sex(sent_uof['officerSex'])
        assert check_uof.officer_age == cleaner.number_to_string(sent_uof['officerAge'])
        assert check_uof.officer_years_of_service == cleaner.number_to_string(sent_uof['officerYearsOfService'])
        assert check_uof.officer_condition == sent_uof['officerCondition']
コード例 #39
0
    def test_update_ois_data(self, testapp):
        ''' Updated OIS data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="******")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of OIS descriptions from the JSON test client
        test_client = JSONTestClient()
        ois_data = test_client.get_prebaked_ois(last=1)
        # post the json to the OIS URL
        response = testapp.post_json("/data/OIS", params={'month': 0, 'year': 0, 'data': ois_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == 1

        # Get the second pre-baked ois incident
        updated_ois_data = test_client.get_prebaked_ois(first=1, last=2)
        # Swap in the opaque ID from the first ois incident
        updated_ois_data[0]["opaqueId"] = ois_data[0]["opaqueId"]
        # The ois incident won't be a match unless this field is the same
        updated_ois_data[0]["officerIdentifier"] = ois_data[0]["officerIdentifier"]
        # post the json to the ois URL
        response = testapp.post_json("/data/OIS", params={'month': 0, 'year': 0, 'data': updated_ois_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 1
        assert response.json_body['added'] == 0

        # There's only one complaint in the database.
        all_ois = OfficerInvolvedShooting.query.all()
        assert len(all_ois) == 1

        # check the ois incident in the database against the updated data that was sent
        cleaner = Cleaners()
        sent_ois = updated_ois_data[0]
        check_ois = OfficerInvolvedShooting.query.filter_by(opaque_id=sent_ois['opaqueId']).first()
        assert check_ois.occured_date.strftime('%Y-%m-%d %-H:%-M:%S') == sent_ois['occuredDate']
        assert check_ois.division == cleaner.capitalize(sent_ois['division'])
        assert check_ois.precinct == cleaner.capitalize(sent_ois['precinct'])
        assert check_ois.shift == cleaner.capitalize(sent_ois['shift'])
        assert check_ois.beat == cleaner.capitalize(sent_ois['beat'])
        assert check_ois.disposition == sent_ois['disposition']
        assert check_ois.resident_race == cleaner.race(sent_ois['residentRace'])
        assert check_ois.resident_sex == cleaner.sex(sent_ois['residentSex'])
        assert check_ois.resident_age == cleaner.number_to_string(sent_ois['residentAge'])
        assert check_ois.resident_weapon_used == cleaner.resident_weapon_used(sent_ois['residentWeaponUsed'])
        assert check_ois.resident_condition == sent_ois['residentCondition']
        assert check_ois.officer_identifier == sent_ois['officerIdentifier']
        assert check_ois.officer_weapon_used == sent_ois['officerForceType']
        assert check_ois.officer_race == cleaner.race(sent_ois['officerRace'])
        assert check_ois.officer_sex == cleaner.sex(sent_ois['officerSex'])
        assert check_ois.officer_age == cleaner.number_to_string(sent_ois['officerAge'])
        assert check_ois.officer_years_of_service == cleaner.string_to_integer(sent_ois['officerYearsOfService'])
        assert check_ois.officer_condition == sent_ois['officerCondition']
コード例 #40
0
    def test_post_mistyped_ois_data(self, testapp):
        ''' New OIS data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="******")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of OIS descriptions from the JSON test client
        test_client = JSONTestClient()
        ois_count = 1
        ois_data = test_client.get_prebaked_ois(last=ois_count)

        # The app expects number values to be transmitted as strings. Let's change them to integers.
        ois_data[0]['residentAge'] = 28
        ois_data[0]['officerAge'] = 46
        # And it expects this number value to be transmitted as a number, so let's make it a string.
        ois_data[0]['officerYearsOfService'] = "17"

        # post the json to the OIS URL
        response = testapp.post_json("/data/OIS", params={'month': 0, 'year': 0, 'data': ois_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == ois_count

        # check the ois incident in the database against the data that was sent
        cleaner = Cleaners()
        sent_ois = ois_data[0]
        check_ois = OfficerInvolvedShooting.query.filter_by(opaque_id=sent_ois['opaqueId']).first()
        assert check_ois.occured_date.strftime('%Y-%m-%d %-H:%-M:%S') == sent_ois['occuredDate']
        assert check_ois.division == cleaner.capitalize(sent_ois['division'])
        assert check_ois.precinct == cleaner.capitalize(sent_ois['precinct'])
        assert check_ois.shift == cleaner.capitalize(sent_ois['shift'])
        assert check_ois.beat == cleaner.capitalize(sent_ois['beat'])
        assert check_ois.disposition == sent_ois['disposition']
        assert check_ois.resident_race == cleaner.race(sent_ois['residentRace'])
        assert check_ois.resident_sex == cleaner.sex(sent_ois['residentSex'])
        assert check_ois.resident_age == cleaner.number_to_string(sent_ois['residentAge'])
        assert check_ois.resident_weapon_used == cleaner.resident_weapon_used(sent_ois['residentWeaponUsed'])
        assert check_ois.resident_condition == sent_ois['residentCondition']
        assert check_ois.officer_identifier == sent_ois['officerIdentifier']
        assert check_ois.officer_weapon_used == sent_ois['officerForceType']
        assert check_ois.officer_race == cleaner.race(sent_ois['officerRace'])
        assert check_ois.officer_sex == cleaner.sex(sent_ois['officerSex'])
        assert check_ois.officer_age == cleaner.number_to_string(sent_ois['officerAge'])
        assert check_ois.officer_years_of_service == cleaner.string_to_integer(sent_ois['officerYearsOfService'])
        assert check_ois.officer_condition == sent_ois['officerCondition']