本文整理匯總了Python中voter.models.VoterManager.delete_voter方法的典型用法代碼示例。如果您正苦於以下問題:Python VoterManager.delete_voter方法的具體用法?Python VoterManager.delete_voter怎麽用?Python VoterManager.delete_voter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類voter.models.VoterManager
的用法示例。
在下文中一共展示了VoterManager.delete_voter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_count_with_no_cookie
# 需要導入模塊: from voter.models import VoterManager [as 別名]
# 或者: from voter.models.VoterManager import delete_voter [as 別名]
def test_count_with_no_cookie(self):
"""
This API should work even if person isn't signed in
:return:
"""
#######################################
# Check to see if there are 0 voters
response = self.client.get(self.voter_count_url)
json_data = json.loads(response.content.decode())
# Python3 solution? Problem is refused connection
# req = Request(self.voter_count_url)
# response = urlopen(req)
# json_data = response.read()
self.assertEqual('success' in json_data, True, "'success' expected in the json response, and not found")
self.assertEqual('voter_count' in json_data, True,
"'voter_count' expected in the voterCount json response")
self.assertEqual(
json_data['voter_count'], 0,
"success: {success} (voter_count '0' expected), voter_count: {voter_count}".format(
success=json_data['success'], voter_count=json_data['voter_count']))
#######################################
# Add 3 voters so we can check count again
voter_manager = VoterManager()
email1 = "[email protected]"
voter_manager.create_voter(
email=email1,
password="password123",
)
email2 = "[email protected]"
voter_manager.create_voter(
email=email2,
password="password123",
)
email3 = "[email protected]"
voter_manager.create_voter(
email=email3,
password="password123",
)
#######################################
# Check to see if there are 3 voters
response2 = self.client.get(self.voter_count_url)
json_data2 = json.loads(response2.content.decode())
self.assertEqual('success' in json_data2, True, "'success' expected in the json response, and not found")
self.assertEqual('voter_count' in json_data2, True,
"'voter_count' expected in the voterCount json response")
self.assertEqual(
json_data2['voter_count'], 3,
"success: {success} (voter_count '3' expected), voter_count: {voter_count}".format(
success=json_data2['success'], voter_count=json_data2['voter_count']))
#######################################
# Remove data for 3 voters
voter_manager.delete_voter(email1)
voter_manager.delete_voter(email2)
voter_manager.delete_voter(email3)
#######################################
# Check to see if there are 0 voters
response3 = self.client.get(self.voter_count_url)
json_data3 = json.loads(response3.content.decode())
self.assertEqual('success' in json_data, True, "'success' expected in the json response, and not found")
self.assertEqual('voter_count' in json_data3, True,
"'voter_count' expected in the voterCount json response")
self.assertEqual(
json_data3['voter_count'], 0,
"success: {success} (voter_count '0' expected - 2nd pass), voter_count: {voter_count}".format(
success=json_data3['success'], voter_count=json_data3['voter_count']))