def patch_edge(name, key, data): """Partial update edge from Database""" edge = get_edge(name, key) spec = app.config['SPECS'].get('edges_partial') util.json_validate(spec).validate(data) for key in data: if key == 'from': edge['_from'] = data[key] elif key == 'to': edge['_to'] = data[key] elif key == 'properties': for idx in data[key]: edge['properties'][idx] = data[key][idx] elif key == 'properties_metadata': for idx in data[key]: edge['properties_metadata'][idx] = data[key][idx] elif key == 'name': if data[key]: edge[key] = data[key] else: edge[key] = data[key] constructor = Constructor() inst_edge = constructor.factory(kind='Edges', name=name) inst_doc = Document(inst_edge) doc = inst_doc.update_document(edge) return doc
def patch_document(name, key, data): """Partial update document from Database""" document = get_document(name, key) spec = app.config['SPECS'].get('documents_partial') util.json_validate(spec).validate(data) for key in data: if key == 'properties': for idx in data[key]: document['properties'][idx] = data[key][idx] elif key == 'properties_metadata': for idx in data[key]: document['properties_metadata'][idx] = data[key][idx] elif key == 'name': if data[key]: document[key] = data[key] else: document[key] = data[key] constructor = Constructor() inst_coll = constructor.factory(kind='Collection', name=name) inst_doc = Document(inst_coll) doc = inst_doc.update_document(document) return doc
def test_get_document_not_exist(self): """Test get document""" inst_doc = Document(self.db_inst.collection) with self.assertRaises(gmap_exceptions.DocumentNotExist): inst_doc.get_document('doc04')
def update_edge(name, key, data): """Update edge from Database""" get_edge(name, key) spec = app.config['SPECS'].get('edges') util.json_validate(spec).validate(data) edge = { '_key': key, '_from': data['from'], '_to': data['to'], 'id': data['id'], 'name': data['name'], 'provider': data['provider'], 'timestamp': data['timestamp'], 'properties': data.get('properties'), 'metadata': data.get('metadata') } constructor = Constructor() inst_edge = constructor.factory(kind='Edges', name=name) inst_doc = Document(inst_edge) doc = inst_doc.update_document(edge) return doc
def test_get_document(self): """Test get document""" self._import_bulk('test_collection_db') inst_doc = Document(self.db_inst.collection) doc = inst_doc.get_document('doc04') doc = {'_key': doc['_key'], 'value': doc['value'], } self.assertDictEqual(doc, {'_key': 'doc04', 'value': 1})
def test_delete_document(self): """Test get document""" col_name = 'test_collection_db' self._import_bulk(col_name) inst_doc = Document(self.db_inst.collection) inst_doc.delete_document('doc04') with self.assertRaises(gmap_exceptions.DocumentNotExist): inst_doc.get_document('doc04')
def delete_document(name, key): """Get document from Database""" constructor = Constructor() inst_coll = constructor.factory(kind='Collection', name=name) inst_doc = Document(inst_coll) doc = inst_doc.delete_document(key) return True
def delete_edge(name, key): """Get edge from Database""" constructor = Constructor() inst_edge = constructor.factory(kind='Edges', name=name) inst_doc = Document(inst_edge) doc = inst_doc.delete_document(key) return True
def test_create_document(self): """Test get document""" inst_doc = Document(self.db_inst.collection) doc = inst_doc.create_document({'_key': 'doc04', 'value': 1}) doc = {'_key': doc['_key'], '_id': doc['_id'], } self.assertDictEqual( doc, {'_key': 'doc04', '_id': 'test_collection_db/doc04', })
def test_create_document(self): """Test get document""" inst_doc = Document(self.db_inst.collection) doc = inst_doc.create_document({'_key': 'doc04', 'value': 1}) doc = { '_key': doc['_key'], '_id': doc['_id'], } self.assertDictEqual(doc, { '_key': 'doc04', '_id': 'test_collection_db/doc04', })
def create_meta_collection_doc(data, kind): """Create document in meta_collection""" constructor = Constructor() inst_coll = constructor.factory( kind='Collection', name=config.META_COLLECTION) inst_doc = Document(inst_coll) document = { '_key': data.get('name'), 'name': data.get('name'), 'alias': data.get('alias'), 'kind': kind, 'icon': data.get('icon'), } doc = inst_doc.create_document(document) return doc
def create_meta_graph_doc(data): """Create document in meta_graph""" constructor = Constructor() inst_coll = constructor.factory(kind='Collection', name=app.config['META_GRAPH']) inst_doc = Document(inst_coll) document = { '_key': data.get('name'), 'name': data.get('name'), 'links': data.get('links'), 'alias': data.get('alias'), 'icon': data.get('icon'), 'description': data.get('description'), } doc = inst_doc.create_document(document) return doc
def create_edge(name, data): """Create document-edge in Database""" constructor = Constructor() inst_edge = constructor.factory(kind='Edges', name=name) edge = { '_key': util.make_key(data), '_from': data['from'], '_to': data['to'], 'id': data['id'], 'name': data.get('name', ''), 'provider': data['provider'], 'timestamp': data['timestamp'], 'properties': data.get('properties'), 'properties_metadata': data.get('properties_metadata') } inst_doc = Document(inst_edge) doc = inst_doc.create_document(edge) return doc
def update_document(name, key, data): """Update document from Database""" get_document(name, key) document = { '_key': key, 'id': data['id'], 'name': data.get('name', ''), 'provider': data['provider'], 'timestamp': data['timestamp'], 'properties': data.get('properties'), 'properties_metadata': data.get('properties_metadata') } constructor = Constructor() inst_coll = constructor.factory(kind='Collection', name=name) inst_doc = Document(inst_coll) doc = inst_doc.update_document(document) return doc
def create_document(name, data): """Create document in Database""" constructor = Constructor() inst_coll = constructor.factory(kind='Collection', name=name) document = data document = { '_key': util.make_key(data), 'id': data['id'], 'name': data.get('name', ''), 'provider': data['provider'], 'timestamp': data['timestamp'], 'properties': data.get('properties'), 'properties_metadata': data.get('properties_metadata') } inst_doc = Document(inst_coll) doc = inst_doc.create_document(document) return doc
def update_edge(name, key, data): """Update edge from Database""" get_edge(name, key) edge = { '_key': key, '_from': data['from'], '_to': data['to'], 'id': data['id'], 'name': data.get('name', ''), 'provider': data['provider'], 'timestamp': data['timestamp'], 'properties': data.get('properties'), 'properties_metadata': data.get('properties_metadata') } constructor = Constructor() inst_edge = constructor.factory(kind='Edges', name=name) inst_doc = Document(inst_edge) doc = inst_doc.update_document(edge) return doc
def create_document(name, data): """Create document in Database""" spec = app.config['SPECS'].get('documents') util.json_validate(spec).validate(data) constructor = Constructor() inst_coll = constructor.factory(kind='Collection', name=name) document = data document = { '_key': util.make_key(data), 'id': data['id'], 'name': data['name'], 'provider': data['provider'], 'timestamp': data['timestamp'], 'properties': data.get('properties'), 'metadata': data.get('metadata') } inst_doc = Document(inst_coll) doc = inst_doc.create_document(document) return doc
def create_edge(name, data): """Create document-edge in Database""" spec = app.config['SPECS'].get('edges') util.json_validate(spec).validate(data) constructor = Constructor() inst_edge = constructor.factory(kind='Edges', name=name) edge = { '_key': util.make_key(data), '_from': data['from'], '_to': data['to'], 'id': data['id'], 'name': data['name'], 'provider': data['provider'], 'timestamp': data['timestamp'], 'properties': data.get('properties'), 'metadata': data.get('metadata') } inst_doc = Document(inst_edge) doc = inst_doc.create_document(edge) return doc
def update_document(name, key, data): """Update document from Database""" get_document(name, key) spec = app.config['SPECS'].get('documents') util.json_validate(spec).validate(data) document = { '_key': key, 'id': data['id'], 'name': data['name'], 'provider': data['provider'], 'timestamp': data['timestamp'], 'properties': data.get('properties'), 'metadata': data.get('metadata') } constructor = Constructor() inst_coll = constructor.factory(kind='Collection', name=name) inst_doc = Document(inst_coll) doc = inst_doc.update_document(document) return doc
def test_delete_document_not_exist(self): """Test get document""" inst_doc = Document(self.db_inst.collection) with self.assertRaises(gmap_exceptions.DocumentNotExist): inst_doc.delete_document('doc04')