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


Python VoterManager.delete_voter方法代码示例

本文整理汇总了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']))
开发者ID:JesseAldridge,项目名称:WeVoteServer,代码行数:75,代码来源:test_views_voter_count.py


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