Example #1
0
 def test_serialize(self):
     """Test the serialize function."""
     c = branch(
         city.City(name="Freiburg", uid=1),
         branch(city.Neighborhood(name="Littenweiler", uid=2),
                city.Street(name="Schwarzwaldstraße", uid=3)))
     self.maxDiff = None
     assertJsonLdEqual(self, json.loads(serialize(c)), CUDS_LIST)
     assertJsonLdEqual(self, serialize(c, json_dumps=False), CUDS_LIST)
Example #2
0
 def test_rdf_import(self):
     """Test the import of RDF data."""
     with TestSession() as session:
         w = branch(
             city.CityWrapper(session=session),
             branch(city.City(name="Freiburg"),
                    city.Neighborhood(name="Littenweiler")))
         g = get_rdf_graph(session)
         c = w.get(rel=city.hasPart)[0]
         c.remove(rel=cuba.relationship)
         session._rdf_import(g)
         self.assertEqual(w.get(rel=city.hasPart), [c])
         self.assertEqual(c.get(rel=city.hasPart)[0].name, "Littenweiler")
Example #3
0
 def test_branch(self):
     """Test the branch function."""
     x = branch(
         branch(city.City(name="Freiburg"),
                city.Citizen(name="Peter"),
                city.Citizen(name="Maria"),
                rel=city.hasInhabitant), city.Neighborhood(name="Herdern"),
         city.Neighborhood(name="Vauban"))
     self.assertEqual(x.name, "Freiburg")
     self.assertEqual({"Herdern", "Vauban"},
                      set(
                          map(lambda x: x.name,
                              x.get(oclass=city.Neighborhood))))
     self.assertEqual({"Peter", "Maria"},
                      set(
                          map(lambda x: x.name,
                              x.get(rel=city.hasInhabitant))))
Example #4
0
 def test_delete_cuds_object_recursively(self):
     """Test the delete_cuds_object_recursively function."""
     with TestWrapperSession() as session:
         wrapper = city.CityWrapper(session=session)
         a = city.City(name='freiburg', session=session)
         b = city.Citizen(name='peter', session=session)
         branch(wrapper, branch(a, b, rel=city.hasInhabitant))
         self.maxDiff = None
         session._reset_buffers(BufferContext.USER)
         delete_cuds_object_recursively(a)
         self.assertEqual(session._buffers, [
             [{}, {
                 wrapper.uid: wrapper
             }, {
                 a.uid: a,
                 b.uid: b
             }],
             [{}, {}, {}],
         ])
         self.assertEqual(wrapper.get(rel=cuba.relationship), [])
         self.assertEqual(a.get(rel=cuba.relationship), [])
         self.assertEqual(b.get(rel=cuba.relationship), [])
Example #5
0
from osp.core.namespaces import city
from osp.core.utils import branch, export_cuds, import_cuds, pretty_print
from osp.wrappers.sqlite import SqliteSession

uuid_re = re.compile(
    r".*(http://www\.osp-core\.com/cuds#"
    r"([a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}"
    r"-[a-z0-9]{4}-[a-z0-9]{12})).*"
)

# Create CUDS structure
c = branch(
    branch(
        city.City(name="Freiburg"),
        city.City(name="Pablo"),
        city.City(name="Yoav"),
        rel=city.hasInhabitant,
    ),
    city.Neighborhood(name="Stühlinger"),
    city.Neighborhood(name="Herdern"),
)

# Export from Core Session
export_cuds(path="test.rdf", format="ttl")

# Check output
with open("test.rdf", encoding="utf-8") as f:
    print("Exported from Core Session")
    for line in f:
        print("\t", line.strip())

# Export from a Wrapper session