Ejemplo n.º 1
0
    def test_insert(self):
        """Test inserting in the sqlite table."""
        c = city.City(name="Freiburg")
        p1 = city.Citizen(name="Peter")
        p2 = city.Citizen(name="Georg")
        c.add(p1, p2, rel=city.hasInhabitant)

        with DataspaceSession(URI) as session:
            wrapper = city.CityWrapper(session=session)
            wrapper.add(c)
            session.commit()

        check_state(self, c, p1, p2, db=DB)
Ejemplo n.º 2
0
    def test_delete(self):
        """Test to delete cuds_objects from the sqlite table."""
        c = city.City(name="Freiburg")
        p1 = city.Citizen(name="Peter")
        p2 = city.Citizen(name="Georg")
        p3 = city.Citizen(name="Hans")
        c.add(p1, p2, p3, rel=city.hasInhabitant)

        with DataspaceSession(URI) as session:
            wrapper = city.CityWrapper(session=session)
            cw = wrapper.add(c)
            session.commit()

            cw.remove(p3.uid)
            session.prune()
            session.commit()

        check_state(self, c, p1, p2, db=DB)
Ejemplo n.º 3
0
"""An example explaining how to upload files using the transport layer."""

import sys
import logging
from osp.wrappers.sqlite import SqliteSession
from osp.core.session import TransportSessionServer
from osp.core.namespaces import cuba
from osp.wrappers.dataspace import DataspaceSession

logging.getLogger("osp.core.session.transport").setLevel(logging.DEBUG)

if sys.argv[-1] == "client":
    print("Please specify where you want to cache the files on the client:")
    with DataspaceSession("ws://127.0.0.1:4587",
                          input("file destination: > ")) as session:
        wrapper = cuba.Wrapper(session=session)
        file = cuba.File(path=input("file to upload: > "))
        wrapper.add(file, rel=cuba.activeRelationship)
        session.commit()

else:
    print("Please specify where you want to cache the files on the server:")
    file_destination = input("file destination: > ")
    print("Starting server now.")
    print("Please call 'python %s client' to connect" % __file__)
    TransportSessionServer(
        SqliteSession, "localhost", 4587,
        session_kwargs={"path": "test.db"},
        file_destination=file_destination
    ).startListening()