Ejemplo n.º 1
0
    def findEntity(self, thID):

        db = vdms.VDMS()
        db.connect(hostname, port)

        constraints = {}
        constraints["threadid"] = ["==", thID]

        findEntity = {}
        findEntity["constraints"] = constraints
        findEntity["class"] = "AwesomePeople"

        results = {}
        results["list"] = ["name", "lastname", "threadid"]
        findEntity["results"] = results

        query = {}
        query["FindEntity"] = findEntity

        all_queries = []
        all_queries.append(query)

        response, res_arr = db.query(all_queries)
        response = json.loads(response)
        # print vdms.aux_print_json(response)

        self.assertEqual(response[0]["FindEntity"]["status"], 0)
        self.assertEqual(response[0]["FindEntity"]["entities"][0]["lastname"],
                         "Ferro")
        self.assertEqual(response[0]["FindEntity"]["entities"][0]["threadid"],
                         thID)
Ejemplo n.º 2
0
    def addEntity(self, thID=0):

        db = vdms.VDMS()
        db.connect(hostname, port)

        props = {}
        props["name"] = "Luis"
        props["lastname"] = "Ferro"
        props["age"] = 27
        props["threadid"] = thID

        addEntity = {}
        addEntity["properties"] = props
        addEntity["class"] = "AwesomePeople"

        query = {}
        query["AddEntity"] = addEntity

        all_queries = []
        all_queries.append(query)

        response, res_arr = db.query(all_queries)
        response = json.loads(response)

        self.assertEqual(response[0]["AddEntity"]["status"], 0)
Ejemplo n.º 3
0
    def test_findImage_multiple_res(self):
        db = vdms.VDMS()
        db.connect(hostname, port)

        prefix_name = "fimg_brain_multiple"

        number_of_inserts = 4
        for i in range(0, number_of_inserts):
            props = {}
            props["name"] = prefix_name
            self.insertImage(db, props=props)

        constraints = {}
        constraints["name"] = ["==", prefix_name]

        results = {}
        results["list"] = ["name"]

        img_params = {}
        img_params["constraints"] = constraints

        query = {}
        query["FindImage"] = img_params

        all_queries = []
        all_queries.append(query)

        response, img_array = db.query(all_queries)
        # print vdms.aux_print_json(response)

        response = json.loads(response)
        self.assertEqual(len(img_array), number_of_inserts)
        self.assertEqual(response[0]["FindImage"]["status"], 0)
        self.assertEqual(response[0]["FindImage"]["returned"],
                         number_of_inserts)
Ejemplo n.º 4
0
    def test_findImage(self):
        db = vdms.VDMS()
        db.connect(hostname, port)

        prefix_name = "fimg_brain_"

        for i in range(0, 2):
            props = {}
            props["name"] = prefix_name + str(i)
            self.insertImage(db, props=props)

        all_queries = []

        for i in range(0, 2):
            constraints = {}
            constraints["name"] = ["==", prefix_name + str(i)]

            img_params = {}
            img_params["constraints"] = constraints

            query = {}
            query["FindImage"] = img_params

            all_queries.append(query)

        response, img_array = db.query(all_queries)
        # print vdms.aux_print_json(response)

        response = json.loads(response)
        self.assertEqual(response[0]["FindImage"]["status"], 0)
        self.assertEqual(response[1]["FindImage"]["status"], 0)
        # self.assertEqual(response[0]["FindImage"]["entities"][0]["name"], prefix_name + "0")
        # self.assertEqual(response[1]["FindImage"]["entities"][0]["name"], prefix_name + "1")
        self.assertEqual(len(img_array), 2)
Ejemplo n.º 5
0
    def test_addImageWithLink(self):
        db = vdms.VDMS()
        db.connect(hostname, port)

        all_queries = []

        props = {}
        props["name"] = "Luis"
        props["lastname"] = "Ferro"
        props["age"] = 27

        addEntity = {}
        addEntity["_ref"] = 32
        addEntity["properties"] = props
        addEntity["class"] = "AwesomePeople"

        query = {}
        query["AddEntity"] = addEntity

        all_queries.append(query)

        props = {}
        props["name"] = "Luis"
        props["lastname"] = "Malo"
        props["age"] = 27

        link = {}
        link["ref"] = 32
        link["direction"] = "in"
        link["class"] = "Friends"

        addImage = {}
        addImage["properties"] = props
        addImage["link"] = link

        imgs_arr = []

        fd = open("../test_images/brain.png")
        imgs_arr.append(fd.read())

        img_params = {}

        query = {}
        query["AddImage"] = addImage

        all_queries.append(query)

        # print json.dumps(all_queries)
        # vdms.aux_print_json(all_queries)

        response, res_arr = db.query(all_queries, [imgs_arr])
        response = json.loads(response)
        # vdms.aux_print_json(response)

        self.assertEqual(response[0]["AddEntity"]["status"], 0)
        self.assertEqual(response[1]["AddImage"]["status"], 0)
Ejemplo n.º 6
0
    def test_addImage(self):
        db = vdms.VDMS()
        db.connect(hostname, port)

        all_queries = []
        imgs_arr = []

        number_of_inserts = 2

        for i in range(0, number_of_inserts):
            #Read Brain Image
            fd = open("../test_images/brain.png")
            imgs_arr.append(fd.read())

            op_params_resize = {}
            op_params_resize["height"] = 512
            op_params_resize["width"] = 512
            op_params_resize["type"] = "resize"

            props = {}
            props["name"] = "brain_" + str(i)
            props["doctor"] = "Dr. Strange Love"

            img_params = {}
            img_params["properties"] = props
            img_params["operations"] = [op_params_resize]
            img_params["format"] = "png"

            query = {}
            query["AddImage"] = img_params

            all_queries.append(query)

        response, img_array = db.query(all_queries, [imgs_arr])

        response = json.loads(response)
        self.assertEqual(len(response), number_of_inserts)
        for i in range(0, number_of_inserts):
            self.assertEqual(response[i]["AddImage"]["status"], 0)
Ejemplo n.º 7
0
    def ztest_zFindImageWithCollection(self):
        db = vdms.VDMS()
        db.connect(hostname, port)

        prefix_name = "fimg_brain_collection_"
        number_of_inserts = 4

        colls = {}
        colls = ["brainScans"]

        for i in range(0, number_of_inserts):
            props = {}
            props["name"] = prefix_name + str(i)

            self.insertImage(db, props=props, collections=colls)

        all_queries = []

        for i in range(0, 1):

            results = {}
            results["list"] = ["name"]

            img_params = {}
            img_params["collections"] = ["brainScans"]
            img_params["results"] = results

            query = {}
            query["FindImage"] = img_params

            all_queries.append(query)

        response, img_array = db.query(all_queries)
        # print vdms.aux_print_json(response)

        response = json.loads(response)
        self.assertEqual(response[0]["FindImage"]["status"], 0)
        self.assertEqual(len(img_array), number_of_inserts)
Ejemplo n.º 8
0
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

#! /usr/bin/python
from threading import Thread
import sys
import os
import urllib
import time
import json
import unittest

import vdms

if len(sys.argv) != 2:
    print "You must provide a json file"
else:
    hostname = "localhost"

    db = vdms.VDMS()
    db.connect(hostname)

    with open(sys.argv[1]) as json_file:
        query = json.load(json_file)

    response, img_array = db.query(query)
    print vdms.aux_print_json(response)