class ServerCentralizedKernel(TripleSpace): """ Server side of the centralized Triple Space implementation. """ def __init__(self): super(ServerCentralizedKernel, self).__init__() self.data_access = DataAccess() self._create_server() def _create_server(self): from otsopy.network.communication.server import app self.app = app self.app.kernel = self def join_space(self, space): self.data_access.join_space(space) def leave_space(self, space): self.data_access.leave_space(space) def get_spaces(self): return self.data_access.get_spaces() def get_graph_uris(self, space): return self.data_access.get_graph_uris(space) def read_uri(self, graph, space=None): return self.data_access.read_uri(graph, space=space) def read_template(self, template, space=None): return self.data_access.read_wildcard(*template, space=space) def query(self, template, space=None): return self.data_access.query_wildcard(*template, space=space) def write(self, triples, space=None): return self.data_access.write(triples, space=space)
class TestDataAccess(unittest.TestCase): def setUp(self): self.da = DataAccess() def test_get_space(self): self.assertIsNotNone( self.da.get_space( self.da._defaultSpace ) ) self.assertRaises( Exception, self.da.get_space, "http://unexisting.space.com" ) def test_join_space(self): self.da.join_space( "http://www.space1.tk" ) self.assertIsNotNone( self.da.get_space("http://www.space1.tk") ) def test_leave_space(self): self.da.leave_space( self.da._defaultSpace ) self.assertRaises( Exception, self.da.get_space, self.da._defaultSpace ) def test_get_spaces(self): self.da.join_space( "http://www.space1.tk" ) spaces = self.da.get_spaces() self.assertEquals( 2, len(spaces) ) self.assertTrue( self.da._defaultSpace in spaces ) self.assertTrue( "http://www.space1.tk" in spaces )