Exemple #1
0
 def save(self, artifact):
     artifact_values = serialization.serialize_for_db(artifact)
     try:
         db_api_artifact = self.db_api.artifact_update(
             self.context, artifact_values, artifact.id, artifact.type_name,
             artifact.type_version)
     except (exception.ArtifactNotFound, exception.ArtifactForbidden):
         msg = _("No artifact found with ID %s") % artifact.id
         raise exception.ArtifactNotFound(msg)
     return serialization.deserialize_from_db(db_api_artifact, self.plugins)
 def save(self, artifact):
     artifact_values = serialization.serialize_for_db(artifact)
     try:
         db_api_artifact = self.db_api.artifact_update(
             self.context, artifact_values, artifact.id, artifact.type_name, artifact.type_version
         )
     except (exception.ArtifactNotFound, exception.ArtifactForbidden):
         msg = _("No artifact found with ID %s") % artifact.id
         raise exception.ArtifactNotFound(msg)
     return serialization.deserialize_from_db(db_api_artifact, self.plugins)
Exemple #3
0
 def add(self, artifact):
     artifact_values = serialization.serialize_for_db(artifact)
     artifact_values['updated_at'] = artifact.updated_at
     self.db_api.artifact_create(self.context, artifact_values,
                                 artifact.type_name, artifact.type_version)
Exemple #4
0
    def test_serialization_to_db(self):
        ref1 = defs.ArtifactType(**get_artifact_fixture(id="1"))
        ref2 = defs.ArtifactType(**get_artifact_fixture(id="2"))
        ref3 = defs.ArtifactType(**get_artifact_fixture(id="3"))

        blob1 = defs.Blob(size=100,
                          locations=['http://example.com/blob1'],
                          item_key='some_key',
                          checksum='abc')
        blob2 = defs.Blob(size=200,
                          locations=['http://example.com/blob2'],
                          item_key='another_key',
                          checksum='fff')
        blob3 = defs.Blob(size=300,
                          locations=['http://example.com/blob3'],
                          item_key='third_key',
                          checksum='123')

        fixture = get_artifact_fixture()
        tt = SerTestType(**fixture)
        tt.some_string = 'bar'
        tt.some_text = 'bazz'
        tt.some_version = '11.22.33-beta'
        tt.some_int = 50
        tt.some_numeric = 10.341
        tt.some_bool = True
        tt.some_array = ['q', 'w', 'e', 'r', 't', 'y']
        tt.another_array = [1, 1.2, False]
        tt.some_dict = {'foobar': "FOOBAR", 'baz': "QUX"}
        tt.another_dict = {'foo': 1, 'bar': True}
        tt.some_ref = ref1
        tt.some_ref_list = [ref2, ref3]
        tt.some_blob = blob1
        tt.some_blob_list = [blob2, blob3]

        results = serialization.serialize_for_db(tt)
        expected = fixture
        expected['type_name'] = 'SerTestType'
        expected['type_version'] = '1.0'
        expected['properties'] = {
            'some_string': {
                'type': 'string',
                'value': 'bar'
            },
            'some_text': {
                'type': 'text',
                'value': 'bazz'
            },
            'some_version': {
                'type': 'string',
                'value': '11.22.33-beta'
            },
            'some_int': {
                'type': 'int',
                'value': 50
            },
            'some_numeric': {
                'type': 'numeric',
                'value': 10.341
            },
            'some_bool': {
                'type': 'bool',
                'value': True
            },
            'some_array': {
                'type':
                'array',
                'value': [{
                    'type': 'string',
                    'value': 'q'
                }, {
                    'type': 'string',
                    'value': 'w'
                }, {
                    'type': 'string',
                    'value': 'e'
                }, {
                    'type': 'string',
                    'value': 'r'
                }, {
                    'type': 'string',
                    'value': 't'
                }, {
                    'type': 'string',
                    'value': 'y'
                }]
            },
            'another_array': {
                'type':
                'array',
                'value': [{
                    'type': 'int',
                    'value': 1
                }, {
                    'type': 'numeric',
                    'value': 1.2
                }, {
                    'type': 'bool',
                    'value': False
                }]
            },
            'some_dict.foobar': {
                'type': 'string',
                'value': 'FOOBAR'
            },
            'some_dict.baz': {
                'type': 'string',
                'value': 'QUX'
            },
            'another_dict.foo': {
                'type': 'int',
                'value': 1
            },
            'another_dict.bar': {
                'type': 'bool',
                'value': True
            }
        }
        expected['dependencies'] = {
            'some_ref': ['1'],
            'some_ref_list': ['2', '3']
        }
        expected['blobs'] = {
            'some_blob': [{
                'size': 100,
                'checksum': 'abc',
                'item_key': 'some_key',
                'locations': ['http://example.com/blob1']
            }],
            'some_blob_list': [{
                'size': 200,
                'checksum': 'fff',
                'item_key': 'another_key',
                'locations': ['http://example.com/blob2']
            }, {
                'size': 300,
                'checksum': '123',
                'item_key': 'third_key',
                'locations': ['http://example.com/blob3']
            }]
        }

        self.assertEqual(expected, results)
    def test_serialization_to_db(self):
        ref1 = defs.ArtifactType(**get_artifact_fixture(id="1"))
        ref2 = defs.ArtifactType(**get_artifact_fixture(id="2"))
        ref3 = defs.ArtifactType(**get_artifact_fixture(id="3"))

        blob1 = defs.Blob(size=100, locations=['http://example.com/blob1'],
                          item_key='some_key', checksum='abc')
        blob2 = defs.Blob(size=200, locations=['http://example.com/blob2'],
                          item_key='another_key', checksum='fff')
        blob3 = defs.Blob(size=300, locations=['http://example.com/blob3'],
                          item_key='third_key', checksum='123')

        fixture = get_artifact_fixture()
        tt = SerTestType(**fixture)
        tt.some_string = 'bar'
        tt.some_text = 'bazz'
        tt.some_version = '11.22.33-beta'
        tt.some_int = 50
        tt.some_numeric = 10.341
        tt.some_bool = True
        tt.some_array = ['q', 'w', 'e', 'r', 't', 'y']
        tt.another_array = [1, 1.2, False]
        tt.some_dict = {'foobar': "FOOBAR", 'baz': "QUX"}
        tt.another_dict = {'foo': 1, 'bar': True}
        tt.some_ref = ref1
        tt.some_ref_list = [ref2, ref3]
        tt.some_blob = blob1
        tt.some_blob_list = [blob2, blob3]

        results = serialization.serialize_for_db(tt)
        expected = fixture
        expected['type_name'] = 'SerTestType'
        expected['type_version'] = '1.0'
        expected['properties'] = {
            'some_string': {
                'type': 'string',
                'value': 'bar'
            },
            'some_text': {
                'type': 'text',
                'value': 'bazz'
            },
            'some_version': {
                'type': 'string',
                'value': '11.22.33-beta'
            },
            'some_int': {
                'type': 'int',
                'value': 50
            },
            'some_numeric': {
                'type': 'numeric',
                'value': 10.341
            },
            'some_bool': {
                'type': 'bool',
                'value': True
            },
            'some_array': {
                'type': 'array',
                'value': [
                    {
                        'type': 'string',
                        'value': 'q'
                    },
                    {
                        'type': 'string',
                        'value': 'w'
                    },
                    {
                        'type': 'string',
                        'value': 'e'
                    },
                    {
                        'type': 'string',
                        'value': 'r'
                    },
                    {
                        'type': 'string',
                        'value': 't'
                    },
                    {
                        'type': 'string',
                        'value': 'y'
                    }
                ]
            },
            'another_array': {
                'type': 'array',
                'value': [
                    {
                        'type': 'int',
                        'value': 1
                    },
                    {
                        'type': 'numeric',
                        'value': 1.2
                    },
                    {
                        'type': 'bool',
                        'value': False
                    }
                ]
            },
            'some_dict.foobar': {
                'type': 'string',
                'value': 'FOOBAR'
            },
            'some_dict.baz': {
                'type': 'string',
                'value': 'QUX'
            },
            'another_dict.foo': {
                'type': 'int',
                'value': 1
            },
            'another_dict.bar': {
                'type': 'bool',
                'value': True
            }
        }
        expected['dependencies'] = {
            'some_ref': ['1'],
            'some_ref_list': ['2', '3']
        }
        expected['blobs'] = {
            'some_blob': [
                {
                    'size': 100,
                    'checksum': 'abc',
                    'item_key': 'some_key',
                    'locations': ['http://example.com/blob1']
                }],
            'some_blob_list': [
                {
                    'size': 200,
                    'checksum': 'fff',
                    'item_key': 'another_key',
                    'locations': ['http://example.com/blob2']
                },
                {
                    'size': 300,
                    'checksum': '123',
                    'item_key': 'third_key',
                    'locations': ['http://example.com/blob3']
                }
            ]
        }

        self.assertEqual(expected, results)