Exemplo n.º 1
0
class ImageOperationsSmoke(ImagesFixture):
    @classmethod
    def setUpClass(cls):
        super(ImageOperationsSmoke, cls).setUpClass()

        # Count set to number of images required for this module
        created_images = cls.images.behaviors.create_images_via_task(
            image_properties={'name': rand_name('image_operations_smoke')},
            count=4)

        cls.image = created_images.pop()
        cls.alt_image = created_images.pop()
        cls.activated_image = created_images.pop()

        cls.deactivated_image = created_images.pop()
        cls.images_admin.client.deactivate_image(cls.deactivated_image.id_)

    @classmethod
    def tearDownClass(cls):
        cls.images.behaviors.resources.release()
        super(ImageOperationsSmoke, cls).tearDownClass()

    def test_register_image(self):
        """
        @summary: Register an image

        1) Register an image
        2) Verify that the response code is 201
        3) Add the image to the resource pool for deletion
        """

        resp = self.images.client.register_image(
            name=rand_name('image_operations_smoke'))
        self.assertEqual(
            resp.status_code, 201,
            Messages.STATUS_CODE_MSG.format(201, resp.status_code))
        image = resp.entity

        self.resources.add(image.id_, self.images.client.delete_image)

    @data_driven_test(ImagesDatasetListGenerator.ListImagesSmoke())
    def ddtest_list_images(self, params):
        """
        @summary: List a subset of images passing in valid query parameters

        @param params: Parameter being passed to the list images request
        @type params: Dictionary

        1) List subset of images passing in a query parameter
        2) Verify the response status code is 200
        """

        resp = self.images.client.list_images(params)
        self.assertEqual(
            resp.status_code, 200,
            Messages.STATUS_CODE_MSG.format(200, resp.status_code))

    @data_driven_test(ImagesDatasetListGenerator.ListImagesInvalidParameters())
    def ddtest_invalid_list_images(self, prop):
        """
        @summary: Attempt to list a subset of images passing in invalid query
        parameters

        @param params: Parameter being passed to the list images request
        @type params: Dictionary

        1) Attempt to list a subset of images passing in an invalid query
        parameter
        2) If the invalid query parameter is created_at or updated_at, verify
        the response status code is 400
        3) If the invalid query parameter is not created_at or updated_at,
        verify the response status code is 200
        """

        unacceptable_props = ['created_at', 'updated_at']

        # Most invalid parameters should be ignored, should return 200 response
        resp = self.images.client.list_images(prop)
        # Prop will always only have a single key
        try:
            if prop.keys()[0] in unacceptable_props:
                self.assertEqual(
                    resp.status_code, 400,
                    Messages.STATUS_CODE_MSG.format(400, resp.status_code))
            else:
                self.assertEqual(
                    resp.status_code, 200,
                    Messages.STATUS_CODE_MSG.format(200, resp.status_code))
        except IndexError, error:
            self.fail(msg='No image property passed in. '
                      'Error: {0}'.format(error))
Exemplo n.º 2
0
class ImageOperationsSmoke(ImagesFixture):

    @classmethod
    def setUpClass(cls):
        super(ImageOperationsSmoke, cls).setUpClass()

        # Count set to number of images required for this module
        created_images = cls.images.behaviors.create_images_via_task(
            image_properties={'name': rand_name('image_operations_smoke')},
            count=2)

        cls.image = created_images.pop()
        cls.alt_image = created_images.pop()

    @classmethod
    def tearDownClass(cls):
        cls.images.behaviors.resources.release()
        super(ImageOperationsSmoke, cls).tearDownClass()

    @data_driven_test(ImagesDatasetListGenerator.ListImagesSmoke())
    def ddtest_list_images(self, params):
        """
        @summary: List a subset of images passing in valid query parameters

        @param params: Parameter being passed to the list images request
        @type params: Dictionary

        1) List subset of images passing in a query parameter
        2) Verify the response status code is 200
        """

        resp = self.images.client.list_images(params)
        self.assertEqual(
            resp.status_code, 200,
            Messages.STATUS_CODE_MSG.format(200, resp.status_code))

    @data_driven_test(
        ImagesDatasetListGenerator.ListImagesInvalidParameters())
    def ddtest_invalid_list_images(self, params):
        """
        @summary: Attempt to list a subset of images passing in invalid query
        parameters

        @param params: Parameter being passed to the list images request
        @type params: Dictionary

        1) Attempt to list a subset of images passing in an invalid query
        parameter
        2) Verify the response status code is 200
        """

        # Invalid parameters should be ignored, the response code should be 200
        resp = self.images.client.list_images(params)
        self.assertEqual(
            resp.status_code, 200,
            Messages.STATUS_CODE_MSG.format(200, resp.status_code))

    def test_get_image_details(self):
        """
        @summary: Get the details of an image

        1) Get the details of an image passing in an image id
        2) Verify the response status code is 200
        """

        resp = self.images.client.get_image_details(self.image.id_)
        self.assertEqual(
            resp.status_code, 200,
            Messages.STATUS_CODE_MSG.format(200, resp.status_code))

    def test_update_image(self):
        """
        @summary: Update an image

        1) Update an image replacing a single property
        2) Verify that the response code is 200
        """

        updated_name = rand_name('image_operations_smoke_updated')

        resp = self.images.client.update_image(
            self.image.id_, replace={'name': updated_name})
        self.assertEqual(
            resp.status_code, 200,
            Messages.STATUS_CODE_MSG.format(200, resp.status_code))

    def test_delete_image(self):
        """
        @summary: Delete an image

        1) Delete an image
        2) Verify that the response code is 204
        """

        resp = self.images.client.delete_image(self.alt_image.id_)
        self.assertEqual(
            resp.status_code, 204,
            Messages.STATUS_CODE_MSG.format(204, resp.status_code))