当前位置: 首页>>代码示例>>Python>>正文


Python cleaners.Cleaners类代码示例

本文整理汇总了Python中comport.data.cleaners.Cleaners的典型用法代码示例。如果您正苦于以下问题:Python Cleaners类的具体用法?Python Cleaners怎么用?Python Cleaners使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cleaners类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_correct_complaint_cap

    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="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))
开发者ID:codeforamerica,项目名称:comport,代码行数:31,代码来源:test_extractor_api.py

示例2: test_post_assaults_data

    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="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']
开发者ID:codeforamerica,项目名称:comport,代码行数:33,代码来源:test_extractor_api.py

示例3: test_unknown_resident_weapon_returned

 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
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:test_cleaners.py

示例4: test_unknown_race_returned

 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
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:test_cleaners.py

示例5: test_unknown_gender_returned

 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
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:test_cleaners.py

示例6: test_known_genders_cleaned

 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]
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:test_cleaners.py

示例7: test_unknown_officer_force_type_returned

 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
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:test_cleaners.py

示例8: test_known_races_cleaned

 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]
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:test_cleaners.py

示例9: test_known_officer_force_types_cleaned

 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]
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:test_cleaners.py

示例10: upgrade

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)
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:43c4c512514_.py

示例11: test_known_resident_weapons_cleaned

 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]
开发者ID:codeforamerica,项目名称:comport,代码行数:7,代码来源:test_cleaners.py

示例12: test_capitalization

 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
开发者ID:codeforamerica,项目名称:comport,代码行数:10,代码来源:test_cleaners.py

示例13: test_captilization_handles_non_strings

 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
开发者ID:codeforamerica,项目名称:comport,代码行数:13,代码来源:test_cleaners.py

示例14: test_number_to_string

 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
开发者ID:codeforamerica,项目名称:comport,代码行数:14,代码来源:test_cleaners.py

示例15: test_post_mistyped_complaint_data

    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="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'])
开发者ID:carolynjoneslee,项目名称:comport,代码行数:50,代码来源:test_extractor_api.py


注:本文中的comport.data.cleaners.Cleaners类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。