Exemple #1
0
    def setup_class(cls):
        cls.raw_image_str = open(
            os.path.join(os.path.dirname(__file__), 'data/image.json')).read()
        cls.raw_images_str = open(
            os.path.join(os.path.dirname(__file__),
                         'data/images.json')).read()

        cls.raw_images_schema_str = open(
            os.path.join(os.path.dirname(__file__),
                         'data/images_schema.json')).read()
        cls.raw_image_schema_str = open(
            os.path.join(os.path.dirname(__file__),
                         'data/image_schema.json')).read()

        if IS_MOCK:
            HTTPretty.enable()
            cls.mock_api()

        cls.image_obj = Image._json_to_obj(cls.raw_image_str)
        cls.images_obj = Image._json_to_obj(cls.raw_images_str)

        cls.images_client = ImagesClient(
            base_url='http://localhost/v2',
            auth_token='36a04b4e71484ab9aacb1d0ac95733fc',
            serialize_format='json',
            deserialize_format='json')
Exemple #2
0
    def setup_class(cls):
        cls.raw_image_str = open(os.path.join(
            os.path.dirname(__file__), '../data/image.json')).read()
        cls.raw_images_str = open(os.path.join(
            os.path.dirname(__file__), '../data/images.json')).read()

        cls.image_obj = Image(
            id_='21c697d1-2cc5-4a45-ba50-61fab15ab9b7',
            name='cirros-0.3.1-x86_64-uec-ramdisk',
            visibility=ImageVisibility.PUBLIC,
            status=ImageStatus.ACTIVE,
            protected=False,
            tags=[],
            checksum='69c33642f44ca552ba4bb8b66ad97e85',
            size=3714968,
            created_at=datetime.strptime('2013-05-22T14:24:36Z',
                                         '%Y-%m-%dT%H:%M:%SZ'),
            updated_at=datetime.strptime('2013-05-22T14:24:36Z',
                                         '%Y-%m-%dT%H:%M:%SZ'),
            file_='/v2/images/21c697d1-2cc5-4a45-ba50-61fab15ab9b7/file',
            self_='/v2/images/21c697d1-2cc5-4a45-ba50-61fab15ab9b7',
            schema='/v2/schemas/image',
            container_format=ImageContainerFormat.ARI,
            disk_format=ImageDiskFormat.ARI,
            min_disk=0,
            min_ram=0
        )
Exemple #3
0
    def setup_class(cls):
        cls.raw_image_str = open(
            os.path.join(os.path.dirname(__file__),
                         '../data/image.json')).read()
        cls.raw_images_str = open(
            os.path.join(os.path.dirname(__file__),
                         '../data/images.json')).read()

        # Required due to datetime parser in image client
        date_time = dateutil.parser.parse(unicode('2013-05-22T14:24:36Z'))

        cls.image_obj = Image(
            checksum='69c33642f44ca552ba4bb8b66ad97e85',
            container_format=ImageContainerFormat.ARI,
            created_at=date_time,
            disk_format=ImageDiskFormat.ARI,
            file_='/v2/images/21c697d1-2cc5-4a45-ba50-61fab15ab9b7/file',
            id_='21c697d1-2cc5-4a45-ba50-61fab15ab9b7',
            min_disk=0,
            min_ram=0,
            name='cirros-0.3.1-x86_64-uec-ramdisk',
            protected=False,
            schema='/v2/schemas/image',
            self_='/v2/images/21c697d1-2cc5-4a45-ba50-61fab15ab9b7',
            size=3714968,
            status=ImageStatus.ACTIVE,
            tags=[],
            updated_at=date_time,
            visibility=ImageVisibility.PUBLIC,
            additional_properties={unicode('additional_properties'): {}})

        cls.obj_dict = json.loads(cls.raw_image_str)
Exemple #4
0
    def test_serialization_to_json(self):
        # Required due to datetime parser in image client
        setattr(self.image_obj, 'created_at', '2013-05-22T14:24:36Z')
        setattr(self.image_obj, 'updated_at', '2013-05-22T14:24:36Z')
        serialized_obj = self.image_obj._obj_to_json()
        # we do this to overcome the property ordering:
        deserialized_obj = Image._json_to_obj(serialized_obj)

        assert set(self.image_obj.__dict__) == set(deserialized_obj.__dict__)
Exemple #5
0
    def test_serialization_to_json(self):
        # Required due to datetime parser in image client
        setattr(self.image_obj, 'created_at', '2013-05-22T14:24:36Z')
        setattr(self.image_obj, 'updated_at', '2013-05-22T14:24:36Z')
        serialized_obj = self.image_obj._obj_to_json()
        # we do this to overcome the property ordering:
        deserialized_obj = Image._json_to_obj(serialized_obj)

        assert set(self.image_obj.__dict__) == set(deserialized_obj.__dict__)
Exemple #6
0
    def test_dict_to_obj(self):
        obj_dict = deepcopy(self.image_obj.__dict__)
        obj_dict['created_at'] = '2013-05-22T14:24:36Z'
        obj_dict['updated_at'] = '2013-05-22T14:24:36Z'
        obj_dict['id'] = obj_dict.pop('id_')
        obj_dict['self'] = obj_dict.pop('self_')
        obj_dict['file'] = obj_dict.pop('file_')
        image_obj = Image._dict_to_obj(obj_dict)

        assert self.image_obj == image_obj
Exemple #7
0
    def create_image(self,
                     id_=None,
                     name=None,
                     visibility=None,
                     status=None,
                     protected=None,
                     tags=None,
                     checksum=None,
                     size=None,
                     created_at=None,
                     updated_at=None,
                     file_=None,
                     self_=None,
                     schema=None,
                     container_format=None,
                     disk_format=None,
                     min_disk=None,
                     min_ram=None,
                     kernel_id=None,
                     ramdisk_id=None,
                     requestslib_kwargs=None):
        """
            Create a new Image.
        """
        image = Image(id_=id_,
                      name=name,
                      visibility=visibility,
                      status=status,
                      protected=protected,
                      tags=tags,
                      checksum=checksum,
                      size=size,
                      created_at=created_at,
                      updated_at=updated_at,
                      file_=file_,
                      self_=self_,
                      schema=schema,
                      container_format=container_format,
                      disk_format=disk_format,
                      min_disk=min_disk,
                      min_ram=min_ram,
                      kernel_id=kernel_id,
                      ramdisk_id=ramdisk_id)
        url = '{0}/images'.format(self.base_url)

        return self.request('POST',
                            url,
                            request_entity=image,
                            response_entity_type=Image,
                            requestslib_kwargs=requestslib_kwargs)
Exemple #8
0
    def setup_class(cls):
        cls.raw_image_str = open(os.path.join(
            os.path.dirname(__file__), 'data/image.json')).read()
        cls.raw_images_str = open(os.path.join(
            os.path.dirname(__file__), 'data/images.json')).read()

        cls.raw_images_schema_str = open(os.path.join(
            os.path.dirname(__file__), 'data/images_schema.json')).read()
        cls.raw_image_schema_str = open(os.path.join(
            os.path.dirname(__file__), 'data/image_schema.json')).read()

        if IS_MOCK:
            HTTPretty.enable()
            cls.mock_api()

        cls.image_obj = Image._json_to_obj(cls.raw_image_str)
        cls.images_obj = Image._json_to_obj(cls.raw_images_str)

        cls.images_client = ImagesClient(
            base_url='http://localhost/v2',
            auth_token='36a04b4e71484ab9aacb1d0ac95733fc',
            serialize_format='json',
            deserialize_format='json'
        )
Exemple #9
0
    def create_image(self,
                     checksum=None,
                     container_format=None,
                     created_at=None,
                     disk_format=None,
                     file_=None,
                     id_=None,
                     min_disk=None,
                     min_ram=None,
                     name=None,
                     protected=None,
                     schema=None,
                     self_=None,
                     size=None,
                     status=None,
                     tags=None,
                     updated_at=None,
                     visibility=None,
                     additional_properties=None,
                     requestslib_kwargs=None):
        """@summary:  Create a new image"""

        image = Image(checksum=checksum,
                      container_format=container_format,
                      created_at=created_at,
                      disk_format=disk_format,
                      file_=file_,
                      id_=id_,
                      min_disk=min_disk,
                      min_ram=min_ram,
                      name=name,
                      protected=protected,
                      schema=schema,
                      self_=self_,
                      size=size,
                      status=status,
                      tags=tags,
                      updated_at=updated_at,
                      visibility=visibility,
                      additional_properties=additional_properties)
        url = '{0}/images'.format(self.base_url)
        return self.request('POST',
                            url,
                            request_entity=image,
                            response_entity_type=Image,
                            requestslib_kwargs=requestslib_kwargs)
Exemple #10
0
    def test_serialization_to_json(self):
        serialized_obj = self.image_obj._obj_to_json()
        # we do this to overcome the property ordering:
        deserialized_obj = Image._json_to_obj(serialized_obj)

        assert set(self.image_obj.__dict__) == set(deserialized_obj.__dict__)
Exemple #11
0
    def test_deserialization_from_json(self):
        deserialized_obj = Image._json_to_obj(self.raw_image_str)

        assert self.image_obj == deserialized_obj
 def test_dict_to_obj(self):
     assert self.image_obj == Image._dict_to_obj(self.obj_dict)
Exemple #13
0
 def test_dict_to_obj(self):
     assert self.image_obj == Image._dict_to_obj(self.obj_dict)