Esempio n. 1
0
    def test_no_property_context(self):
        self.store.create_model("MyClass", NO_PROPERTY_CONTEXT_DICT)
        client = ClientResourceManager(self.store)
        client.import_store_models()
        model = client.get_model("MyClass")

        obj = model.new(test_hasX=2)

        with self.assertRaises(OMAttributeTypeCheckError):
            obj.test_hasX = "not a number"
Esempio n. 2
0
    def test_no_property_context(self):
        self.store.create_model("MyClass", NO_PROPERTY_CONTEXT_DICT)
        client = ClientResourceManager(self.store)
        client.import_store_models()
        model = client.get_model("MyClass")

        obj = model.new(test_hasX=2)

        with self.assertRaises(OMAttributeTypeCheckError):
            obj.test_hasX = "not a number"
Esempio n. 3
0
    def test_no_datatype_context(self):
        context = deepcopy(NO_PROPERTY_CONTEXT_DICT)
        context["@context"]["hasX"] = "test:hasX"
        self.store.create_model("MyClass", context)
        client = ClientResourceManager(self.store)
        client.import_store_models()
        model = client.get_model("MyClass")

        obj = model.new(hasX=2)
        with self.assertRaises(OMAttributeTypeCheckError):
            obj.hasX = "not a number"
Esempio n. 4
0
    def test_complete_context(self):
        context = deepcopy(NO_PROPERTY_CONTEXT_DICT)
        context["@context"]["hasX"] = {"@id": "test:hasX", "@type": "xsd:int"}
        self.store.create_model("MyClass", context)
        client = ClientResourceManager(self.store)
        client.import_store_models()
        model = client.get_model("MyClass")

        obj = model.new(hasX=2)
        with self.assertRaises(OMAttributeTypeCheckError):
            obj.hasX = "not a number"
Esempio n. 5
0
# Cache
#cache_region = None
cache_region = make_region().configure('dogpile.cache.memory_pickle')

data_store = SPARQLDataStore(data_graph, schema_graph=schema_graph, cache_region=cache_region)
# Takes the prefixes from the schema graph
data_store.extract_prefixes(schema_graph)

#lp_name_or_iri = "LocalPerson"
lp_name_or_iri = MY_VOC + "LocalPerson"
data_store.create_model(lp_name_or_iri, context, iri_prefix="http://localhost/persons/", iri_fragment="me")
data_store.create_model("LocalRSAPublicKey", context)
data_store.create_model("LocalGPGPublicKey", context)

client_manager = ClientResourceManager(data_store)
client_manager.import_store_models()

lp_model = client_manager.get_model(lp_name_or_iri)
rsa_model = client_manager.get_model("LocalRSAPublicKey")
gpg_model = client_manager.get_model("LocalGPGPublicKey")


crud_controller = HashLessCRUDer(client_manager)

bob_name = "Bob"
bob_blog = "http://blog.example.com/"
bob_email1 = "bob@localhost"
bob_email2 = "*****@*****.**"
bob_emails = {bob_email1, bob_email2}
bob_bio_en = "I grow up in ... ."
bob_bio_fr = u"J'ai grandi en ... ."
Esempio n. 6
0
                             schema_graph=schema_graph,
                             cache_region=cache_region)
# Takes the prefixes from the schema graph
data_store.extract_prefixes(schema_graph)

#lp_name_or_iri = "LocalPerson"
lp_name_or_iri = MY_VOC + "LocalPerson"
data_store.create_model(lp_name_or_iri,
                        context,
                        iri_prefix="http://localhost/persons/",
                        iri_fragment="me")
data_store.create_model("LocalRSAPublicKey", context)
data_store.create_model("LocalGPGPublicKey", context)

client_manager = ClientResourceManager(data_store)
client_manager.import_store_models()

lp_model = client_manager.get_model(lp_name_or_iri)
rsa_model = client_manager.get_model("LocalRSAPublicKey")
gpg_model = client_manager.get_model("LocalGPGPublicKey")

crud_controller = HashLessCRUDer(client_manager)

bob_name = "Bob"
bob_blog = "http://blog.example.com/"
bob_email1 = "bob@localhost"
bob_email2 = "*****@*****.**"
bob_emails = {bob_email1, bob_email2}
bob_bio_en = "I grow up in ... ."
bob_bio_fr = u"J'ai grandi en ... ."
alice_name = "Alice"
Esempio n. 7
0
from os import path
from unittest import TestCase
from rdflib import Graph
from oldman import HttpDataStore, ClientResourceManager, parse_graph_safely

directory = path.dirname(__file__)
schema_graph = parse_graph_safely(Graph(), path.join(directory, 'api_schema.ttl'), format="turtle")
schema_graph.namespace_manager.bind("hydra", "http://www.w3.org/ns/hydra/core#")

context_uri = path.join(directory, 'api_documentation.json')

data_store = HttpDataStore(schema_graph=schema_graph)
data_store.create_model('ApiDocumentation', context_uri)

manager = ClientResourceManager(data_store)
manager.import_store_models()

doc_model = manager.get_model('ApiDocumentation')


class HttpStoreTest(TestCase):
    def test_get(self):
        iri = u"http://www.markus-lanthaler.com/hydra/api-demo/vocab"
        doc = doc_model.get(iri)
        self.assertTrue(doc is not None)
        self.assertEquals(doc.id, iri)
        expected_classes = {u'http://www.markus-lanthaler.com/hydra/api-demo/vocab#User',
                            u'http://www.w3.org/ns/hydra/core#Collection',
                            u'http://www.w3.org/ns/hydra/core#Resource',
                            u'http://www.markus-lanthaler.com/hydra/api-demo/vocab#Comment',
                            u'http://www.markus-lanthaler.com/hydra/api-demo/vocab#EntryPoint',