class CommandsTests(ISQLWrapperTestCase): def setUp(self): super(CommandsTests, self).setUp() self.isql = ISQLWrapper(self.config.host, self.config.user, self.config.password) def test_execute_script(self): "It can execute a given script" result = self.isql.execute_script("fixtures/status.sql") self.assertTrue(result.startswith("Connected to OpenLink Virtuoso")) def test_execute_bad_script(self): "Executing bad scripts should raise a ISQLWrapperException" self.assertRaises(ISQLWrapperException, self.isql.execute_script, "fixtures/bad_script.sql") def test_execute_cmd(self): "It can execute a given command string." result = self.isql.execute_cmd("status();") self.assertTrue(result.startswith("Connected to OpenLink Virtuoso")) def test_semicolon(self): "Final semicolon is optional" result = self.isql.execute_cmd("status()") self.assertTrue(result.startswith("Connected to OpenLink Virtuoso"))
def setUp(self): self.config = Config("local_test_config.ini", default_manager=ISQLWrapperTestManager()) url = "http://%s:%s%s" url %= (self.config.host, self.config.endpoint_port, self.config.endpoint_path) self.endpoint = Endpoint(url) self.isql = ISQLWrapper(self.config.host, self.config.user, self.config.password) self.isql.execute_cmd("SPARQL CLEAR GRAPH <%s>" % self.config.graph)
class DataTestCase(unittest.TestCase): def setUp(self): self.config = Config("local_test_config.ini", default_manager=ISQLWrapperTestManager()) url = "http://%s:%s%s" url %= (self.config.host, self.config.endpoint_port, self.config.endpoint_path) self.endpoint = Endpoint(url) self.isql = ISQLWrapper(self.config.host, self.config.user, self.config.password) self.isql.execute_cmd("SPARQL CLEAR GRAPH <%s>" % self.config.graph) def assertGraphHasNumberOfTriples(self, n): sparql_query = "SELECT * FROM <%s> WHERE {?s ?p ?o}" % self.config.graph results = self.endpoint.query(sparql_query) self.assertEquals(results.total_rows, n) def assertGraphIsEmpty(self): self.assertGraphHasNumberOfTriples(0) def tearDown(self): self.config.save("local_test_config.ini") self.isql.execute_cmd("SPARQL CLEAR GRAPH <%s>" % self.config.graph) def test_delete_uri(self): "Inserts a triple into the triplestore" ns = Namespace("https://github.com/juanique/artichoke/ns#") graph = self.config.graph self.assertGraphIsEmpty() self.isql.insert(graph, ns["subject"], ns["predicate"], ns["object"]) self.isql.delete(graph, ns["subject"], ns["predicate"], ns["object"]) self.assertGraphIsEmpty() def test_delete_literal(self): "Inserts a triple into the triplestore" ns = Namespace("https://github.com/juanique/artichoke/ns#") graph = self.config.graph self.assertGraphIsEmpty() self.isql.insert(graph, ns["subject"], ns["predicate"], Literal("Hello")) self.isql.delete(graph, ns["subject"], ns["predicate"], Literal("Hello")) self.assertGraphIsEmpty() def test_insert(self): "Inserts a triple into the triplestore" ns = Namespace("https://github.com/juanique/artichoke/ns#") graph = self.config.graph self.isql.insert(graph, ns["subject"], ns["predicate"], ns["object"]) query = "SELECT * FROM <%s> WHERE {?s ?p ?o}" % graph results = self.endpoint.query(query) self.assertGraphHasNumberOfTriples(1) self.assertEquals(results[0]['s'].value, str(ns["subject"])) self.assertEquals(results[0]['p'].value, str(ns["predicate"])) self.assertEquals(results[0]['o'].value, str(ns["object"]))
def setUp(self): super(CommandsTests, self).setUp() self.isql = ISQLWrapper(self.config.host, self.config.user, self.config.password)
def test_init(self): "It is initalized by giving the server's hostname, username and pass." ISQLWrapper(self.config.host, self.config.user, self.config.password)
from artichoke import Config from ucursos import xml_to_graph from virtuoso.endpoint import Endpoint from virtuoso import ISQLWrapper from testconfig import TestDefaultManager import os config = Config("local_test_config.ini", default_manager=TestDefaultManager()) url = "http://%s:%s%s" url %= (config.host, config.endpoint_port, config.endpoint_path) endpoint = Endpoint(url) isql = ISQLWrapper(config.host, config.user, config.password) isql.execute_cmd("SPARQL CLEAR GRAPH <%s>" % config.graph) isql.load_file("uchile_schema.ttl", config.graph) datadir = "../data" for dirname, dirnames, filenames in os.walk(datadir): for filename in filenames: print filename full_path = os.path.join(dirname, filename) basename, extension = os.path.splitext(filename) try: graph = xml_to_graph(full_path) isql.insert(config.graph, graph)