Exemplo n.º 1
0
    def test_delete_status_code(self):
        """@Test Issue an HTTP DELETE request and check the returned status
        code.

        @Assert: HTTP 200, 202 or 204 is returned with an ``application/json``
        content-type.

        """
        try:
            system = System(uuid=System().create_json()['uuid'])
        except HTTPError as err:
            self.fail(err)
        logger.debug('system uuid: {0}'.format(system.uuid))
        response = client.delete(
            system.path(),
            auth=get_server_credentials(),
            verify=False,
        )
        self.assertIn(
            response.status_code,
            (httplib.NO_CONTENT, httplib.OK, httplib.ACCEPTED)
        )

        # According to RFC 2616, HTTP 204 responses "MUST NOT include a
        # message-body". If a message does not have a body, there is no need to
        # set the content-type of the message.
        if response.status_code is not httplib.NO_CONTENT:
            self.assertIn('application/json', response.headers['content-type'])
Exemplo n.º 2
0
    def test_delete_status_code(self, entity):
        """@Test Issue an HTTP DELETE request and check the returned status
        code.

        @Assert: HTTP 200, 202 or 204 is returned with an ``application/json``
        content-type.

        """
        if entity is entities.ConfigTemplate and bz_bug_is_open(1096333):
            self.skipTest('Cannot delete config templates.')
        try:
            attrs = entity().create()
        except factory.FactoryError as err:
            self.fail(err)
        path = entity(id=attrs['id']).path()
        response = client.delete(
            path,
            auth=get_server_credentials(),
            verify=False,
        )
        status_code = (httplib.NO_CONTENT, httplib.OK, httplib.ACCEPTED)
        self.assertIn(
            response.status_code,
            status_code,
            status_code_error(path, status_code, response),
        )

        # According to RFC 2616, HTTP 204 responses "MUST NOT include a
        # message-body". If a message does not have a body, there is no need to
        # set the content-type of the message.
        if response.status_code is not httplib.NO_CONTENT:
            self.assertIn('application/json', response.headers['content-type'])
Exemplo n.º 3
0
    def test_delete(self, entity):
        """@Test Create an entity, fetch it, DELETE it, and fetch it again.

        @Assert DELETE succeeds. HTTP 200, 202 or 204 is returned before
        deleting entity, and 404 is returned after deleting entity.

        """
        attrs = entity().create()
        path = entity(id=attrs['id']).path()
        response = client.delete(
            path,
            auth=get_server_credentials(),
            verify=False,
        )
        status_code = (httplib.NO_CONTENT, httplib.OK, httplib.ACCEPTED)
        self.assertIn(
            response.status_code,
            status_code,
            status_code_error(path, status_code, response),
        )
        response = client.get(
            path,
            auth=get_server_credentials(),
            verify=False,
        )
        status_code = httplib.NOT_FOUND
        self.assertEqual(
            status_code,
            response.status_code,
            status_code_error(path, status_code, response),
        )
Exemplo n.º 4
0
    def delete_raw(self, auth=None):
        """Delete the current entity.

        Send an HTTP DELETE request to :meth:`Entity.path`. Return the
        response. Do not check the response for any errors, such as an HTTP 4XX
        or 5XX status code.

        :param tuple auth: A ``(username, password)`` tuple used when accessing
            the API. If ``None``, the credentials provided by
            :func:`robottelo.common.helpers.get_server_credentials` are used.
        :return: A ``requests.response`` object.

        """
        if auth is None:
            auth = helpers.get_server_credentials()
        return client.delete(self.path(which='self'), auth=auth, verify=False)
Exemplo n.º 5
0
    def test_positive_delete_1(self, name):
        """@Test: Create a role and delete it

        @Feature: Role

        @Assert: Role deletion should succeed

        """
        try:
            role_attrs = entities.Role(name=name).create()
        except factory.FactoryError as err:
            self.fail(err)  # fail instead of error

        path = entities.Role(id=role_attrs['id']).path()

        # GET the role and verify it's name.
        response = client.get(
            path,
            auth=get_server_credentials(),
            verify=False,
        ).json()
        self.assertEqual(response['name'], name)

        # Delete the role, GET it, and assert that an HTTP 404 is returned.
        response = client.delete(
            path,
            auth=get_server_credentials(),
            verify=False,
        )
        # 404 should be returned for deleted role
        response = client.get(
            path,
            auth=get_server_credentials(),
            verify=False,
        )
        status_code = httplib.NOT_FOUND
        self.assertEqual(
            status_code,
            response.status_code,
            status_code_error(path, status_code, response),
        )
Exemplo n.º 6
0
    def delete(self, auth=None, synchronous=True):
        """Delete the current entity.

        Send an HTTP DELETE request to ``self.path(which='this')``.

        :param tuple auth: A ``(username, password)`` tuple used when accessing
            the API. If ``None``, the credentials provided by
            :func:`robottelo.common.helpers.get_server_credentials` are used.
        :param bool synchronous: What should happen if the server returns an
            HTTP 202 (accepted) status code? Wait for the task to complete if
            ``True``. Immediately return a task ID otherwise.
        :return: The ID of a :class:`robottelo.entities.ForemanTask` if an HTTP
            202 response was received. ``None`` otherwise.
        :raises: ``requests.exceptions.HTTPError`` if the response has an HTTP
            4XX or 5XX status code.
        :raises: ``ValueError`` If an HTTP 202 response is received and the
            response JSON can not be decoded.
        :raises robottelo.orm.TaskTimeout: If an HTTP 202 response is received,
            ``synchronous is True`` and the task times out.

        """
        # Delete this entity and check the status code of the response.
        if auth is None:
            auth = helpers.get_server_credentials()
        response = client.delete(
            self.path(which='this'),
            auth=auth,
            verify=False,
        )
        response.raise_for_status()

        # Return either a ForemanTask ID or None.
        if response.status_code is httplib.ACCEPTED:
            task_id = response.json()['id']
            if synchronous is True:
                _poll_task(task_id)
            return task_id
        return None