test_provider_image_service.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import uuid
  2. from test.helpers import ProviderTestBase
  3. import test.helpers
  4. class ProviderImageServiceTestCase(ProviderTestBase):
  5. def __init__(self, methodName, provider):
  6. super(ProviderImageServiceTestCase, self).__init__(
  7. methodName=methodName, provider=provider)
  8. def setUp(self):
  9. self.instance = test.helpers.get_test_instance(self.provider)
  10. def tearDown(self):
  11. self.instance.terminate()
  12. def test_create_and_list_image(self):
  13. """
  14. Create a new image and check whether that image can be listed.
  15. This covers waiting till the image is ready, checking that the image name is the expected one and
  16. whether list_images is functional.
  17. """
  18. name = "CBUnitTestListImg-{0}".format(uuid.uuid4())
  19. test_image = self.instance.create_image(name)
  20. try:
  21. test_image.wait_till_ready()
  22. images = self.provider.images.list_images()
  23. images = [image for image in images if image.name == name]
  24. self.assertTrue(
  25. len(images) == 1,
  26. "List images does not return the expected image %s" %
  27. name)
  28. finally:
  29. test_image.delete()