Exemplo n.º 1
0
Arquivo: tests.py Projeto: opt9/hoply
def test_seed_subject_lookup(storage_class, path):
    with storage_class(path) as storage:
        with h.transaction(storage) as tr:
            hyperdev = uuid4()
            triplestore.add(tr, hyperdev, "title", "hyperdev.fr")
            triplestore.add(tr, hyperdev, "keyword", "scheme")
            triplestore.add(tr, hyperdev, "keyword", "hacker")
        with h.transaction(storage) as tr:
            dolead = uuid4()
            triplestore.add(tr, dolead, "title", "blog.dolead.com")
            triplestore.add(tr, dolead, "keyword", "corporate")
        with h.transaction(storage) as tr:
            julien = uuid4()
            triplestore.add(tr, julien, "title", "julien.danjou.info")
            triplestore.add(tr, julien, "keyword", "python")
            triplestore.add(tr, julien, "keyword", "hacker")

        with h.transaction(storage) as tr:
            query = triplestore.FROM(tr, dolead, h.var("key"), h.var("value"))
            out = [dict(x) for x in query]

        expected = [
            {
                "key": "keyword",
                "value": "corporate"
            },
            {
                "key": "title",
                "value": "blog.dolead.com"
            },
        ]
        assert out == expected
Exemplo n.º 2
0
 async def projects(request):
     db = request.app["db"]
     query = h.compose(
         h.where(h.var("uid"), "type", "project"),
         h.where(h.var("uid"), "project/title", h.var("title")),
     )
     out = [pick(binding, ("uid", "title")) for binding in query(db)]
     return web.json_response(out)
Exemplo n.º 3
0
    async def project_get(request):
        uid = request.match_info["uid"]
        log.debug("Looking up project uid=%r", uid)
        out = dict(uid=uid)
        db = request.app["db"]
        # query project title
        query = h.compose(h.where(uid, "project/title", h.var("title")))
        out["title"] = list(query(db))[0]["title"]

        # query projet's items
        query = h.compose(
            h.where(h.var("uid"), "item/project", uid),
            # h.where(h.var('uid'), 'type', 'item'),
            h.where(h.var("uid"), "item/type", h.var("type")),
            h.where(h.var("uid"), "item/value", h.var("value")),
            h.where(h.var("uid"), "item/timestamp", h.var("timestamp")),
        )
        items = list()
        keys = ("uid", "type", "value", "timestamp")
        for binding in query(db):
            item = pick(binding, keys)
            item["value"] = json.loads(item["value"])
            items.append(item)
        items.sort(key=lambda x: x["timestamp"])
        out["items"] = items

        return web.json_response(out)
Exemplo n.º 4
0
Arquivo: tests.py Projeto: opt9/hoply
def test_simple_single_item_db_subject_lookup(storage_class, path):
    with storage_class(path) as storage:
        expected = uuid4()
        with h.transaction(storage) as tr:
            triplestore.add(tr, expected, "title", "hyperdev.fr")
        with h.transaction(storage) as tr:
            query = triplestore.FROM(tr, h.var("subject"), "title",
                                     "hyperdev.fr")
            out = list(query)
            out = out[0]["subject"]
        assert out == expected
Exemplo n.º 5
0
Arquivo: tests.py Projeto: opt9/hoply
def test_simple_multiple_items_db_subject_lookup(storage_class, path):
    with storage_class(path) as storage:
        expected = uuid4()
        with h.transaction(storage) as tr:
            triplestore.add(tr, expected, "title", "hyperdev.fr")
            triplestore.add(tr, uuid4(), "title", "blog.dolead.com")
            triplestore.add(tr, uuid4(), "title", "julien.danjou.info")
        with h.transaction(storage) as tr:
            query = triplestore.FROM(tr, h.var("subject"), "title",
                                     "hyperdev.fr")
            out = list(query)
            out = out[0]["subject"]
        assert out == expected
Exemplo n.º 6
0
Arquivo: tests.py Projeto: opt9/hoply
def test_complex(storage_class, path):
    with storage_class(path) as storage:
        hyperdev = uuid4()
        with h.transaction(storage) as tr:
            triplestore.add(tr, hyperdev, "title", "hyperdev.fr")
            triplestore.add(tr, hyperdev, "keyword", "scheme")
            triplestore.add(tr, hyperdev, "keyword", "hacker")
            dolead = uuid4()
            triplestore.add(tr, dolead, "title", "blog.dolead.com")
            triplestore.add(tr, dolead, "keyword", "corporate")
            julien = uuid4()
            triplestore.add(tr, julien, "title", "julien.danjou.info")
            triplestore.add(tr, julien, "keyword", "python")
            triplestore.add(tr, julien, "keyword", "hacker")
        with h.transaction(storage) as tr:
            out = h.select(
                triplestore.FROM(tr, h.var("identifier"), "keyword", "hacker"),
                triplestore.where(tr, h.var("identifier"), "title",
                                  h.var("blog")),
            )
            out = sorted([x["blog"] for x in out])
        assert out == ["hyperdev.fr", "julien.danjou.info"]
Exemplo n.º 7
0
Arquivo: tests.py Projeto: opt9/hoply
def test_subject_variable(storage_class, path):
    with storage_class(path) as storage:
        # prepare
        with h.transaction(storage) as tr:
            hyperdev = uuid4()
            triplestore.add(tr, hyperdev, "title", "hyperdev.fr")
            triplestore.add(tr, hyperdev, "keyword", "scheme")
            triplestore.add(tr, hyperdev, "keyword", "hacker")
            post1 = uuid4()
            triplestore.add(tr, post1, "blog", hyperdev)
            triplestore.add(tr, post1, "title", "hoply is awesome")
            post2 = uuid4()
            triplestore.add(tr, post2, "blog", hyperdev)
            triplestore.add(tr, post2, "title", "hoply triple store")

        # exec, fetch all blog title from hyperdev.fr
        with h.transaction(storage) as tr:
            out = h.select(
                triplestore.FROM(tr, h.var("blog"), "title", "hyperdev.fr"),
                triplestore.where(tr, h.var("post"), "blog", h.var("blog")),
                triplestore.where(tr, h.var("post"), "title", h.var("title")),
            )
            out = sorted([x["title"] for x in out])
        assert out == ["hoply is awesome", "hoply triple store"]
Exemplo n.º 8
0
Arquivo: tests.py Projeto: opt9/hoply
def test_seed_object_variable(storage_class, path):
    with storage_class(path) as storage:
        with h.transaction(storage) as tr:
            hyperdev = uuid4()
            triplestore.add(tr, hyperdev, "title", "hyperdev.fr")
            triplestore.add(tr, hyperdev, "keyword", "scheme")
            triplestore.add(tr, hyperdev, "keyword", "hacker")
        with h.transaction(storage) as tr:
            dolead = uuid4()
            triplestore.add(tr, dolead, "title", "blog.dolead.com")
            triplestore.add(tr, dolead, "keyword", "corporate")
        with h.transaction(storage) as tr:
            julien = uuid4()
            triplestore.add(tr, julien, "title", "julien.danjou.info")
            triplestore.add(tr, julien, "keyword", "python")
            triplestore.add(tr, julien, "keyword", "hacker")
        with h.transaction(storage) as tr:
            query = triplestore.FROM(tr, hyperdev, "title", h.var("title"))
            out = list(query)[0]["title"]
        assert out == "hyperdev.fr"