Ejemplo n.º 1
0
    def test_positive_update_1(self, name_generator):
        """@Test: Update a role with and give a name of ``name_generator()``.

        @Feature: Role

        @Assert: The role is updated with the given name.

        """
        if decorators.bz_bug_is_open(1112657) and (
                name_generator is gen_cjk or name_generator is gen_latin1
                or name_generator is gen_utf8):
            self.skipTest('Bugzilla bug 1112657 is open.')
        try:
            role_id = entities.Role().create()['id']
        except HTTPError as err:
            self.fail(err)  # fail instead of error

        role = entities.Role(id=role_id)
        name = name_generator()
        response = client.put(
            role.path(),
            {u'name': name},
            auth=get_server_credentials(),
            verify=False,
        )
        response.raise_for_status()
        self.assertEqual(role.read_json()['name'], name)
Ejemplo n.º 2
0
    def give_user_permission(self, perm_name):
        """Give ``self.user`` the ``perm_name`` permission.

        This method creates a role and filter to accomplish the above goal.
        When complete, the relevant relationhips look like this:

            user → role ← filter → permission

        :param str perm_name: The name of a permission. For example:
            'create_architectures'.
        :raises: ``AssertionError`` if more than one permission is found when
            searching for the permission with name ``perm_name``.
        :raises: ``requests.exceptions.HTTPError`` if an error occurs when
            updating ``self.user``'s roles.
        :rtype: None

        """
        role_id = entities.Role().create()['id']
        permission_ids = [
            permission['id']
            for permission
            in entities.Permission(name=perm_name).search()
        ]
        self.assertEqual(len(permission_ids), 1)
        entities.Filter(permission=permission_ids, role=role_id).create()
        # NOTE: An extra hash is used due to an API bug.
        client.put(
            self.user.path(),
            {u'user': {u'role_ids': [role_id]}},
            auth=get_server_credentials(),
            verify=False,
        ).raise_for_status()
Ejemplo n.º 3
0
    def test_update_role(self):
        """@Test: Update role for a user

        @Feature: User - Update

        @Assert: User role is updated

        """

        strategy, value = common_locators["entity_deselect"]
        name = gen_string("alpha", 6)
        role_name = entities.Role().create()['name']
        with Session(self.browser) as session:
            make_user(session, username=name)
            self.user.search(name, search_key).click()
            self.user.wait_until_element(
                tab_locators["users.tab_roles"]).click()
            element1 = self.user.wait_until_element(
                (strategy, value % role_name))
            self.assertIsNone(element1)
            self.user.update(search_key, name, new_roles=[role_name])
            self.user.search(name, search_key).click()
            self.user.wait_until_element(
                tab_locators["users.tab_roles"]).click()
            element2 = self.user.wait_until_element(
                (strategy, value % role_name))
            self.assertIsNotNone(element2)
Ejemplo n.º 4
0
    def test_positive_create_user_10(self):
        """@Test: Create User with multiple roles

        @Feature: User - Positive Create

        @Steps:
        1. Create User with multiple roles assigned to it

        @Assert: User is created

        """
        strategy, value = common_locators["entity_deselect"]
        name = gen_string("alpha", 6)
        role1 = gen_string("alpha", 6)
        role2 = gen_string("alpha", 6)
        for role in [role1, role2]:
            entities.Role(name=role).create()
        with Session(self.browser) as session:
            make_user(session, username=name, roles=[role1, role2], edit=True)
            self.user.search(name, search_key).click()
            self.user.wait_for_ajax()
            self.user.wait_until_element(
                tab_locators["users.tab_roles"]).click()
            for role in [role1, role2]:
                element = self.user.wait_until_element(
                    (strategy, value % role))
                self.assertIsNotNone(element)
Ejemplo n.º 5
0
    def test_positive_create_1(self, name_generator):
        """@Test: Create a role with name ``name_generator()``.

        @Feature: Role

        @Assert: An entity can be created without receiving any errors, the
        entity can be fetched, and the fetched entity has the specified name.

        """
        if decorators.bz_bug_is_open(1112657) and (
                name_generator is gen_cjk or name_generator is gen_latin1
                or name_generator is gen_utf8):
            self.skipTest('Bugzilla bug 1112657 is open.')
        name = name_generator()
        try:
            role_id = entities.Role(name=name).create()['id']
        except HTTPError as err:
            self.fail(err)  # fail instead of error

        # GET the role and verify it's name.
        self.assertEqual(entities.Role(id=role_id).read_json()['name'], name)
Ejemplo n.º 6
0
    def test_implicitly_delete_filter(self):
        """@Test: Create a filter and delete the role it points at.

        @Assert: The filter cannot be fetched.

        @Feature: Filter

        """
        role = entities.Role(id=entities.Role().create()['id'])
        ct_perms = entities.Permission(resource_type='ConfigTemplate').search()
        filter_ = entities.Filter(id=entities.Filter(
            permission=[permission['id'] for permission in ct_perms],
            role=role.id,
        ).create()['id'])

        # A filter depends on a role. Deleting a role implicitly deletes the
        # filter pointing at it.
        role.delete()
        with self.assertRaises(HTTPError):
            role.read_json()
        with self.assertRaises(HTTPError):
            filter_.read_json()
Ejemplo n.º 7
0
    def test_positive_delete_1(self, name_generator):
        """@Test: Delete a role with name ``name_generator()``.

        @Feature: Role

        @Assert: The role cannot be fetched after it is deleted.

        """
        if decorators.bz_bug_is_open(1112657) and (
                name_generator is gen_cjk or name_generator is gen_latin1
                or name_generator is gen_utf8):
            self.skipTest('Bugzilla bug 1112657 is open.')
        name = name_generator()
        try:
            role_id = entities.Role(name=name).create()['id']
        except HTTPError as err:
            self.fail(err)  # fail instead of error

        # DELETE the role and verify that it cannot be fetched
        role = entities.Role(id=role_id)
        role.delete()
        with self.assertRaises(HTTPError):
            role.read_json()
Ejemplo n.º 8
0
    def test_positive_create_user_9(self):
        """@Test: Create User with one role

        @Feature: User - Positive Create

        @Steps:
        1. Create User with one role assigned to it

        @Assert: User is created

        """
        strategy, value = common_locators["entity_deselect"]
        name = gen_string("alpha", 6)
        role_name = entities.Role().create()['name']
        with Session(self.browser) as session:
            make_user(session, username=name, roles=[role_name], edit=True)
            self.user.search(name, search_key).click()
            self.user.wait_until_element(
                tab_locators["users.tab_roles"]).click()
            element = self.user.wait_until_element(
                (strategy, value % role_name))
            self.assertIsNotNone(element)