-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests_endpoint.py
70 lines (47 loc) · 2.25 KB
/
tests_endpoint.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
import unittest
from artichoke import Config
from virtuoso.endpoint import Endpoint, ResultSet
from testconfig import ISQLWrapperTestManager
from rdflib import Namespace
class EndpointTestCase(unittest.TestCase):
def setUp(self):
self.config = Config("local_test_config.ini",
default_manager=ISQLWrapperTestManager())
def tearDown(self):
self.config.save("local_test_config.ini")
class EndpointInitTests(EndpointTestCase):
def test_init(self):
"It is initialized using a given host, port and path"
Endpoint(self.config.host, self.config.endpoint_port, self.config.endpoint_path)
def test_init_auto(self):
"It can be initialized using a string containing the endpoints host, port and path"
url = "http://%s:%s%s"
url %= (self.config.host, self.config.endpoint_port, self.config.endpoint_path)
endpoint = Endpoint(url)
self.assertEquals(endpoint.host, self.config.host)
self.assertEquals(endpoint.port, self.config.endpoint_port)
self.assertEquals(endpoint.path, self.config.endpoint_path)
self.assertEquals(endpoint.get_full_path(), url)
class QueryTests(EndpointTestCase):
def setUp(self):
super(QueryTests, self).setUp()
url = "http://%s:%s%s"
url %= (self.config.host, self.config.endpoint_port, self.config.endpoint_path)
self.endpoint = Endpoint(url)
def test_register_namespace(self):
"It can register a namespace to remember accross all queries"
nfo_base_uri = 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#'
NFO = Namespace(nfo_base_uri)
self.endpoint.register_namespace("nfo", NFO)
self.assertEquals(self.endpoint.get_registered_namespaces_header(),
"PREFIX nfo: <%s>" % nfo_base_uri)
def test_graph_query(self):
sparql = "SELECT ?g WHERE { GRAPH ?g { ?s ?p ?o } } GROUP BY ?g"
results = self.endpoint.query(sparql)
self.assertTrue(isinstance(results, ResultSet))
for result in results:
if result['g'].value == "http://www.openlinksw.com/schemas/virtrdf#":
return
self.assertTrue(False, "Could not find virutoso schema graph")
if __name__ == "__main__":
unittest.main()