-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests_data.py
86 lines (60 loc) · 2.68 KB
/
tests_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import unittest
from artichoke import Config
from virtuoso.endpoint import Endpoint
from virtuoso import ISQLWrapper
from testconfig import ISQLWrapperTestManager
from rdflib import Namespace, Literal
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"]))
if __name__ == "__main__":
unittest.main()