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


Python Dependency.update_user方法代码示例

本文整理汇总了Python中common.utilities.inversion_of_control.Dependency.update_user方法的典型用法代码示例。如果您正苦于以下问题:Python Dependency.update_user方法的具体用法?Python Dependency.update_user怎么用?Python Dependency.update_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common.utilities.inversion_of_control.Dependency的用法示例。


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

示例1: TestCoreUserAccess

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import update_user [as 别名]
class TestCoreUserAccess(MoxTestBase):

    counter = 0

    @classmethod
    def setUpClass(cls):
        cls.counter = 0

    @classmethod
    def get_counter(cls):
        counter = cls.counter
        cls.counter += 1
        return counter

    def setUp(self):
        # call super
        super(TestCoreUserAccess, self).setUp()

        # register mox and common core dependencies
        register_core_mock_dependencies()
        register_common_mox_dependencies(self.mox)

        # get some needed things
        self.user_access = Dependency("CoreUserProvider").value

        role_dict = self.__get_role_dict()
        role_dict["name"] = "admin"
        self.user_access.create_role(role_dict)

    def tearDown(self):

        self.user_access = None
        dependencies.clear()
    
    def test_user_basic_crud(self):

        # create stub
        m = Mox()
        m.StubOutWithMock(utils, "encrypt_password")
        m.StubOutWithMock(utils, "verify_password")
        m.StubOutWithMock(base64, "b64encode")
        m.StubOutWithMock(os, "urandom")

        # start recording
        utils.encrypt_password("test")
        utils.verify_password("test", None).AndReturn(True)
        utils.verify_password("asdfasdf", None).AndReturn(False)
        # mock the urandom return for the salt, and make sure that gets base-64 encoded into something different
        os.urandom(128).AndReturn("she sells sea shells by the sea shore")
        base64.b64encode("she sells sea shells by the sea shore").AndReturn("Salt-n-Pepa")
        m.ReplayAll()

        user_dict = self.__get_user_dict()
        user = self.user_access.create_user(user_dict)

        self.assertIn("id", user)
        self.assertEqual(user_dict["email"], user["email"])
        self.assertEqual(user_dict["is_generalist"], user["is_generalist"])
        self.assertEqual(user_dict["active"], user["active"])
        self.assertEqual(len(user["roles"]), 1)

        self.assertTrue(self.user_access.verify_user_password(user["id"], user_dict["password"]))
        self.assertFalse(self.user_access.verify_user_password(user["id"], "asdfasdf"))

        self.assertEqual("Salt-n-Pepa", user["salt"])

        user2 = self.user_access.update_user(user["id"], {"email": "[email protected]"})

        self.assertEqual(user2["email"], "[email protected]")
        self.assertEqual(user2["id"], user["id"])

        user3 = self.user_access.get_user(user2["id"])

        self.assertEqual(user2, user3)

        result = self.user_access.delete_user(user3["id"])
        self.assertEqual(result, True)

        no_user = self.user_access.get_user(user2["id"])
        self.assertEqual(no_user, None)

    def test_user_update_password(self):

        # create stub
        m = Mox()
        m.StubOutWithMock(utils, "encrypt_password")
        m.StubOutWithMock(utils, "verify_password")
        m.StubOutWithMock(base64, "b64encode")
        m.StubOutWithMock(os, "urandom")

        # start recording
        utils.encrypt_password("test")
        utils.verify_password("test", None).AndReturn(True)
        utils.verify_password("asdfasdf", None).AndReturn(False)
        # mock the urandom return for the salt, and make sure that gets base-64 encoded into something different
        os.urandom(128).AndReturn("she sells sea shells by the sea shore")
        base64.b64encode("she sells sea shells by the sea shore").AndReturn("Salt-n-Pepa")

        #go into replay mode
        m.ReplayAll()
#.........这里部分代码省略.........
开发者ID:erezrubinstein,项目名称:aa,代码行数:103,代码来源:test_core_user_access.py


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