當前位置: 首頁>>代碼示例>>Python>>正文


Python Cleaners.capitalize_incident方法代碼示例

本文整理匯總了Python中comport.data.cleaners.Cleaners.capitalize_incident方法的典型用法代碼示例。如果您正苦於以下問題:Python Cleaners.capitalize_incident方法的具體用法?Python Cleaners.capitalize_incident怎麽用?Python Cleaners.capitalize_incident使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在comport.data.cleaners.Cleaners的用法示例。


在下文中一共展示了Cleaners.capitalize_incident方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_correct_complaint_cap

# 需要導入模塊: from comport.data.cleaners import Cleaners [as 別名]
# 或者: from comport.data.cleaners.Cleaners import capitalize_incident [as 別名]
    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,代碼行數:33,代碼來源:test_extractor_api.py

示例2: test_post_assaults_data

# 需要導入模塊: from comport.data.cleaners import Cleaners [as 別名]
# 或者: from comport.data.cleaners.Cleaners import capitalize_incident [as 別名]
    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,代碼行數:35,代碼來源:test_extractor_api.py

示例3: test_post_mistyped_complaint_data

# 需要導入模塊: from comport.data.cleaners import Cleaners [as 別名]
# 或者: from comport.data.cleaners.Cleaners import capitalize_incident [as 別名]
    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,代碼行數:52,代碼來源:test_extractor_api.py

示例4: test_incident_capitalization

# 需要導入模塊: from comport.data.cleaners import Cleaners [as 別名]
# 或者: from comport.data.cleaners.Cleaners import capitalize_incident [as 別名]
    def test_incident_capitalization(self):
        ''' Incident descriptions are title-cased with expected exceptions.
        '''
        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 = Cleaners.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
開發者ID:mehmadi,項目名稱:comport,代碼行數:21,代碼來源:test_cleaners.py

示例5: test_incident_capitalization

# 需要導入模塊: from comport.data.cleaners import Cleaners [as 別名]
# 或者: from comport.data.cleaners.Cleaners import capitalize_incident [as 別名]
    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
開發者ID:codeforamerica,項目名稱:comport,代碼行數:22,代碼來源:test_cleaners.py

示例6: test_update_complaint_data

# 需要導入模塊: from comport.data.cleaners import Cleaners [as 別名]
# 或者: from comport.data.cleaners.Cleaners import capitalize_incident [as 別名]
    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="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_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 = CitizenComplaint.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 = 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,代碼行數:68,代碼來源:test_extractor_api.py


注:本文中的comport.data.cleaners.Cleaners.capitalize_incident方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。