def test_should_return_false_when_no_users(self):
     """
     Test is_user_in_group() should return false when there are no users.
     """
     groups = self._create_groups(3)
     self.assertFalse(p4.is_user_in_group('user1', groups[0]))
     self.assertFalse(p4.is_user_in_group('user1', groups[1]))
     self.assertFalse(p4.is_user_in_group('user1', groups[2]))
 def test_should_return_false_when_user_doesnt_exist(self):
     """
     Test is_user_in_group() should return false when the user doesn't exist.
     """
     groups = self._create_groups(3)
     groups[2].add_user('user2')
     groups[1].add_group(groups[2])
     groups[0].add_user('user1')
     groups[0].add_group(groups[1])
     self.assertFalse(p4.is_user_in_group('user3', groups[0]))
     self.assertFalse(p4.is_user_in_group('user3', groups[1]))
     self.assertFalse(p4.is_user_in_group('user3', groups[2]))
示例#3
0
    def test_empty_user_in_group(self):
        parent = Group("parent")
        child = Group("child")
        sub_child = Group("subchild")

        child.add_group(sub_child)
        parent.add_group(child)

        empty_user = ""

        self.assertFalse(is_user_in_group(empty_user, parent))
示例#4
0
    def test_is_false_user_in_group(self):
        parent = Group("parent")
        child = Group("child")
        sub_child = Group("subchild")

        child.add_group(sub_child)
        parent.add_group(child)

        false_user = "******"

        self.assertFalse(is_user_in_group(false_user, parent))
    def test_should_find_user_in_last_subgroup(self):
        """
        Test is_user_in_group() should find the user in last subgroup.

                Group 0
                   |
                Group 1
                   |
                Group 2
                   |
                 user1
        """
        groups = self._create_groups(3)
        groups[0].add_user('user1')
        groups[2].add_user('user1')
        groups[1].add_group(groups[2])
        groups[0].add_group(groups[1])

        self.assertTrue(p4.is_user_in_group('user1', groups[0]))
        self.assertTrue(p4.is_user_in_group('user1', groups[1]))
        self.assertTrue(p4.is_user_in_group('user1', groups[2]))
    def test_should_find_user_in_root(self):
        """
        Test is_user_in_group() should find the user in the root.

                Group 0
                   |
              ----------
             |          |
            user1    Group 1
                        |
                     Group 2
        """
        groups = self._create_groups(3)
        groups[0].add_user('user1')
        groups[1].add_group(groups[2])
        groups[0].add_group(groups[1])
        groups[0].add_group(groups[1])

        self.assertTrue(p4.is_user_in_group('user1', groups[0]))
        self.assertFalse(p4.is_user_in_group('user1', groups[1]))
        self.assertFalse(p4.is_user_in_group('user1', groups[2]))
示例#7
0
    def test_is_valid_user_in_subchild_group(self):
        parent = Group("parent")
        child = Group("child")
        sub_child = Group("subchild")

        sub_child_user = "******"
        sub_child.add_user(sub_child_user)

        child.add_group(sub_child)
        parent.add_group(child)

        self.assertTrue(is_user_in_group(sub_child_user, parent))
    def test_should_find_user_in_hierarchy(self):
        """
        Test is_user_in_group() should find the user in hierarchy.

                Group 0
                   |
           --------------------
          |        |           |
        user1   Group 1     Group 2
                   |           |
                 user2     --------
                          |        |
                        user3   Group 3
                                   |
                               --------
                              |        |
                            user4   Group 4
                                       |
                                   ---------
                                  |         |
                                user5     user6
        """
        groups = self._create_groups(5)
        groups[4].add_user('user5')
        groups[4].add_user('user6')
        groups[3].add_user('user4')
        groups[3].add_group(groups[4])
        groups[2].add_user('user3')
        groups[2].add_group(groups[3])
        groups[1].add_user('user2')
        groups[0].add_user('user1')
        groups[0].add_group(groups[1])
        groups[0].add_group(groups[2])

        self.assertTrue(p4.is_user_in_group('user1', groups[0]))
        self.assertFalse(p4.is_user_in_group('user1', groups[1]))
        self.assertFalse(p4.is_user_in_group('user1', groups[2]))
        self.assertFalse(p4.is_user_in_group('user1', groups[3]))
        self.assertFalse(p4.is_user_in_group('user1', groups[4]))

        self.assertTrue(p4.is_user_in_group('user2', groups[0]))
        self.assertTrue(p4.is_user_in_group('user2', groups[1]))
        self.assertFalse(p4.is_user_in_group('user2', groups[2]))
        self.assertFalse(p4.is_user_in_group('user2', groups[3]))
        self.assertFalse(p4.is_user_in_group('user2', groups[4]))

        self.assertTrue(p4.is_user_in_group('user3', groups[0]))
        self.assertFalse(p4.is_user_in_group('user3', groups[1]))
        self.assertTrue(p4.is_user_in_group('user3', groups[2]))
        self.assertFalse(p4.is_user_in_group('user3', groups[3]))
        self.assertFalse(p4.is_user_in_group('user3', groups[4]))

        self.assertTrue(p4.is_user_in_group('user4', groups[0]))
        self.assertFalse(p4.is_user_in_group('user4', groups[1]))
        self.assertTrue(p4.is_user_in_group('user4', groups[2]))
        self.assertTrue(p4.is_user_in_group('user4', groups[3]))
        self.assertFalse(p4.is_user_in_group('user4', groups[4]))

        self.assertTrue(p4.is_user_in_group('user5', groups[0]))
        self.assertFalse(p4.is_user_in_group('user5', groups[1]))
        self.assertTrue(p4.is_user_in_group('user5', groups[2]))
        self.assertTrue(p4.is_user_in_group('user5', groups[3]))
        self.assertTrue(p4.is_user_in_group('user5', groups[4]))

        self.assertTrue(p4.is_user_in_group('user6', groups[0]))
        self.assertFalse(p4.is_user_in_group('user6', groups[1]))
        self.assertTrue(p4.is_user_in_group('user6', groups[2]))
        self.assertTrue(p4.is_user_in_group('user6', groups[3]))
        self.assertTrue(p4.is_user_in_group('user6', groups[4]))