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


Python RBAC.edit_role方法代碼示例

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


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

示例1: test_edit_role_change_name_only

# 需要導入模塊: from zato.server.rbac_ import RBAC [as 別名]
# 或者: from zato.server.rbac_.RBAC import edit_role [as 別名]
    def test_edit_role_change_name_only(self):

        id, parent_id = rand_int(count=2)
        old_name, new_name = rand_string(2)

        rbac = RBAC()
        rbac.create_role(id, old_name, parent_id)
        rbac.edit_role(id, old_name, new_name, parent_id)

        self.assertEqual(rbac.role_id_to_name[id], new_name)
        self.assertEqual(rbac.role_name_to_id[new_name], id)
        self.assertIn(id, rbac.registry._roles)
        self.assertEquals(rbac.registry._roles[id], set([parent_id]))
開發者ID:Aayush-Kasurde,項目名稱:zato,代碼行數:15,代碼來源:test_rbac_.py

示例2: test_edit_role_parent_not_given

# 需要導入模塊: from zato.server.rbac_ import RBAC [as 別名]
# 或者: from zato.server.rbac_.RBAC import edit_role [as 別名]
    def test_edit_role_parent_not_given(self):

        id = rand_int()
        old_name, new_name = rand_string(2)

        rbac = RBAC()
        rbac.create_role(id, old_name, None)
        rbac.edit_role(id, old_name, new_name, None)

        self.assertEqual(rbac.role_id_to_name[id], new_name)
        self.assertEqual(rbac.role_name_to_id[new_name], id)
        self.assertIn(id, rbac.registry._roles)
        self.assertEquals(rbac.registry._roles[id], set())
開發者ID:Aayush-Kasurde,項目名稱:zato,代碼行數:15,代碼來源:test_rbac_.py

示例3: test_edit_role_change_parent_id_only

# 需要導入模塊: from zato.server.rbac_ import RBAC [as 別名]
# 或者: from zato.server.rbac_.RBAC import edit_role [as 別名]
    def test_edit_role_change_parent_id_only(self):

        id = rand_int()
        old_parent_id, new_parent_id = uuid4().int, uuid4().int # Using uuid4 to make sure they really are unique
        old_name = new_name = rand_string()

        rbac = RBAC()
        rbac.create_role(id, old_name, old_parent_id)
        rbac.edit_role(id, old_name, new_name, new_parent_id)

        self.assertEqual(rbac.role_id_to_name[id], new_name)
        self.assertEqual(rbac.role_name_to_id[new_name], id)
        self.assertIn(id, rbac.registry._roles)
        self.assertEquals(rbac.registry._roles[id], set([new_parent_id]))
開發者ID:Aayush-Kasurde,項目名稱:zato,代碼行數:16,代碼來源:test_rbac_.py

示例4: test_edit_role_parent_hierarchy

# 需要導入模塊: from zato.server.rbac_ import RBAC [as 別名]
# 或者: from zato.server.rbac_.RBAC import edit_role [as 別名]
    def test_edit_role_parent_hierarchy(self):

        id1, parent_id1 = 1, 11
        id2, id3, id4 = 2, 3, 4

        parent_id1_new, parent_id2_new, parent_id3_new = 111, 222, 333

        name1, name2, name3, name4 = 'name1', 'name2', 'name3', 'name4'
        name1_new, name3_new, name4_new = 'name1_new', 'name3_new', 'name4_new'

        rbac = RBAC()
        rbac.create_role(id1, name1, parent_id1)
        rbac.create_role(id2, name2, id1)
        rbac.create_role(id3, name3, id1)
        rbac.create_role(id4, name4, id2)

        # Changing only the name here
        rbac.edit_role(id1, name1, name1_new, parent_id1)
        self.assertEqual(rbac.role_id_to_name[id1], name1_new)
        self.assertIn(id1, rbac.registry._roles)
        self.assertEquals(rbac.registry._roles[id1], set([parent_id1]))
        self.assertEquals(sorted(get_family(rbac.registry._roles, id1)), [None, id1, parent_id1])

        # Changing the id1's parent ID here
        rbac.edit_role(id1, name1_new, name1_new, parent_id1_new)
        self.assertEqual(rbac.role_id_to_name[id1], name1_new)
        self.assertIn(id1, rbac.registry._roles)
        self.assertEquals(rbac.registry._roles[id1], set([parent_id1_new]))
        self.assertEquals(sorted(get_family(rbac.registry._roles, id1)), [None, id1, parent_id1_new])

        # Changing both name and parent ID of id3
        rbac.edit_role(id3, name3, name3_new, parent_id3_new)
        self.assertEqual(rbac.role_id_to_name[id3], name3_new)
        self.assertIn(id3, rbac.registry._roles)
        self.assertEquals(rbac.registry._roles[id3], set([parent_id3_new]))
        self.assertEquals(sorted(get_family(rbac.registry._roles, id3)), [None, id3, parent_id3_new])

        # id4 should have parent_id2_new as one of its predecessors as a result of the first edit
        # whereas the second one should update id4's name.
        rbac.edit_role(id2, name2, name2, parent_id2_new)
        rbac.edit_role(id4, name4, name4_new, id2)

        self.assertEquals(sorted(get_family(rbac.registry._roles, id4)), [None, id2, id4, parent_id2_new])
        self.assertEqual(rbac.role_id_to_name[id4], name4_new)
開發者ID:Aayush-Kasurde,項目名稱:zato,代碼行數:46,代碼來源:test_rbac_.py


注:本文中的zato.server.rbac_.RBAC.edit_role方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。