From 048e65eab3c3b1c659a4cb292f208f9a724021b1 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Thu, 3 Mar 2016 13:54:45 -0500 Subject: [PATCH] Add test to help detect incorrect role rebuilding --- awx/main/tests/functional/test_rbac_core.py | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/awx/main/tests/functional/test_rbac_core.py b/awx/main/tests/functional/test_rbac_core.py index 020023f9bd..deae21b3b8 100644 --- a/awx/main/tests/functional/test_rbac_core.py +++ b/awx/main/tests/functional/test_rbac_core.py @@ -138,3 +138,32 @@ def test_content_object(user): assert org.resource.content_object.id == org.id assert org.admin_role.content_object.id == org.id +@pytest.mark.django_db +def test_hierarchy_rebuilding(): + 'Tests some subdtle cases around role hierarchy rebuilding' + + X = Role.objects.create(name='X') + A = Role.objects.create(name='A') + B = Role.objects.create(name='B') + C = Role.objects.create(name='C') + D = Role.objects.create(name='D') + + A.children.add(B) + A.children.add(D) + B.children.add(C) + C.children.add(D) + + assert A.is_ancestor_of(D) + assert X.is_ancestor_of(D) is False + + X.children.add(A) + + assert X.is_ancestor_of(D) is True + + X.children.remove(A) + + # This can be the stickler, the rebuilder needs to ensure that D's role + # hierarchy is built after both A and C are updated. + assert X.is_ancestor_of(D) is False + +