本文整理匯總了Python中comport.data.cleaners.Cleaners.resident_weapon_used方法的典型用法代碼示例。如果您正苦於以下問題:Python Cleaners.resident_weapon_used方法的具體用法?Python Cleaners.resident_weapon_used怎麽用?Python Cleaners.resident_weapon_used使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類comport.data.cleaners.Cleaners
的用法示例。
在下文中一共展示了Cleaners.resident_weapon_used方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_known_resident_weapons_cleaned
# 需要導入模塊: from comport.data.cleaners import Cleaners [as 別名]
# 或者: from comport.data.cleaners.Cleaners import resident_weapon_used [as 別名]
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]
示例2: test_unknown_resident_weapon_returned
# 需要導入模塊: from comport.data.cleaners import Cleaners [as 別名]
# 或者: from comport.data.cleaners.Cleaners import resident_weapon_used [as 別名]
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
示例3: test_post_mistyped_ois_data
# 需要導入模塊: from comport.data.cleaners import Cleaners [as 別名]
# 或者: from comport.data.cleaners.Cleaners import resident_weapon_used [as 別名]
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="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']
示例4: test_update_ois_data
# 需要導入模塊: from comport.data.cleaners import Cleaners [as 別名]
# 或者: from comport.data.cleaners.Cleaners import resident_weapon_used [as 別名]
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="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']