Example #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"
Example #2
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"
Example #3
0
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 ... ."
Example #4
0
    "@context": {
        "hydra": "http://www.w3.org/ns/hydra/core#",
    },
    "@id": "urn:test:vocab:MyClass",
    "@type": "hydra:Class",
    "hydra:supportedProperty": [{
        "hydra:property": "urn:test:vocab:isWorking"
    }]
}
parse_graph_safely(schema_graph,
                   data=json.dumps(my_class_def),
                   format="json-ld")

context_file_path = path.join(path.dirname(__file__), "basic_context.jsonld")
context_iri = "/contexts/context.jsonld"

store = SPARQLDataStore(Graph(), schema_graph=schema_graph)
store.create_model("MyClass", context_iri, context_file_path=context_file_path)

client_manager = ClientResourceManager(store)
client_manager.import_store_models()
model = client_manager.get_model("MyClass")


class ContextUriTest(TestCase):
    def test_context_uri(self):
        obj = model.new(is_working=True)
        self.assertEquals(obj.context, context_iri)
        self.assertTrue(obj.is_working)
        print obj.to_rdf()