Example #1
0
def _extract_attributes_v2(image, include_locations=False):
    include_locations_attrs = ['direct_url', 'locations']
    omit_attrs = [
        'self', 'schema', 'protected', 'virtual_size', 'file', 'tags'
    ]
    raw_schema = image.schema
    schema = schemas.Schema(raw_schema)
    output = {
        'properties': {},
        'deleted': False,
        'deleted_at': None,
        'disk_format': None,
        'container_format': None,
        'name': None,
        'checksum': None
    }
    for name, value in image.items():
        if (name in omit_attrs
                or name in include_locations_attrs and not include_locations):
            continue
        elif name == 'visibility':
            output['is_public'] = value == 'public'
        elif name == 'size' and value is None:
            output['size'] = 0
        elif schema.is_base_property(name):
            output[name] = value
        else:
            output['properties'][name] = value

    return output
 def test_property_is_base(self):
     raw_schema = {'name': 'Country',
                   'properties': {
                       'size': {},
                       'population': {'is_base': False}}}
     schema = schemas.Schema(raw_schema)
     self.assertTrue(schema.is_base_property('size'))
     self.assertFalse(schema.is_base_property('population'))
     self.assertFalse(schema.is_base_property('foo'))
Example #3
0
    def _mock_client_setup(self):
        self.schema_dict = {
            'name': 'image',
            'properties': {
                'name': {'type': 'string', 'description': 'Name of image'},
            },
        }

        self.client = mock.Mock()
        self.client.schemas.get.return_value = schemas.Schema(self.schema_dict)
 def test_raw(self):
     raw_schema = {'name': 'Country', 'properties': {}}
     schema = schemas.Schema(raw_schema)
     self.assertEqual(raw_schema, schema.raw())
 def test_schema_with_property(self):
     raw_schema = {'name': 'Country', 'properties': {'size': {}}}
     schema = schemas.Schema(raw_schema)
     self.assertEqual('Country', schema.name)
     self.assertEqual(['size'], [p.name for p in schema.properties])
 def test_schema_minimum(self):
     raw_schema = {'name': 'Country', 'properties': {}}
     schema = schemas.Schema(raw_schema)
     self.assertEqual('Country', schema.name)
     self.assertEqual([], schema.properties)
                    'name': {'type': 'string',
                             'description': 'Name of image'},
                    'tags': {'type': 'array'}
                },

            },
        ),
    },
}


_SCHEMA = schemas.Schema({
    'name': 'image',
    'properties': {
        'name': {'type': 'string'},
        'color': {'type': 'string'},
        'shape': {'type': 'string', 'is_base': False},
        'tags': {'type': 'array'}
    },
})


def compare_json_patches(a, b):
    """Return 0 if a and b describe the same JSON patch."""
    return(jsonpatch.JsonPatch.from_string(a) ==
           jsonpatch.JsonPatch.from_string(b))


class TestSchemaProperty(testtools.TestCase):
    def test_property_minimum(self):
        prop = schemas.SchemaProperty('size')
Example #8
0
 def get(self, *args, **kwargs):
     _, raw_schema = self._request('GET', *args, **kwargs)
     return schemas.Schema(raw_schema)
                    'name': {
                        'type': 'string',
                        'description': 'Name of image'
                    },
                },
            },
        ),
    },
}

_SCHEMA = schemas.Schema({
    'name': 'image',
    'properties': {
        'name': {
            'type': 'string'
        },
        'color': {
            'type': 'string'
        },
    },
})


def compare_json_patches(a, b):
    """Return 0 if a and b describe the same JSON patch."""
    return JsonPatch.from_string(a) == JsonPatch.from_string(b)


class TestSchemaProperty(testtools.TestCase):
    def test_property_minimum(self):
        prop = schemas.SchemaProperty('size')