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


Python Dependency.create_user方法代碼示例

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


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

示例1: TestCoreUserAccess

# 需要導入模塊: from common.utilities.inversion_of_control import Dependency [as 別名]
# 或者: from common.utilities.inversion_of_control.Dependency import create_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.create_user方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。