def test_delete_totalFriends(self): cursor = self.connect.cursor() ss = SparqlSpace(self.uri, cursor) #q = '''SPARQL INSERT in GRAPH <%s> { <%s> <http://purl.org/ontology/myspace#totalFriends>''' self.connect.execute('SPARQL DELETE from graph <%s> {<%s> <http://purl.org/dc/terms/modified> ?o} from <%s> where { <%s> ?p ?o }' % (GRAPH ,self.uri , GRAPH, self.uri)) self.connect.execute('SPARQL INSERT in graph <%s> {<%s> <http://purl.org/dc/terms/modified> "2009-03-17T14:27:59+01:00"^^xsd:dateTime}' % (GRAPH ,self.uri)) assert not ss.select(GRAPH)
def test_select(self): uri = self.uri cursor = self.connect.cursor() ss = SparqlSpace(uri, cursor) assert ss.select(GRAPH), 'this uri should be present: '+str(uri) ss = SparqlSpace('http://junk.uri', cursor) assert not ss.select(GRAPH), 'this uri should not be present: http://junk.uri' cursor.close()
def default(self, uid): if uid.endswith('.rdf'): # serve the data cherrypy.response.headers['Content-Type'] = 'application/rdf+xml; charset=UTF-8;' print USE_SPARQL sparql_match = False if USE_SPARQL: #print "USING SPARQL" # check sparql endpoint connect = VODBC.connect() cursor = connect.cursor() ss = SparqlSpace('http://dbtune.org/myspace/uid/'+str(uid.rsplit('.rdf')[0]), cursor) if ss.select(): #print "FOUND SPARQL MATCH" sparql_match = True ret = ss.make_graph() cursor.close() connect.commit() connect.close() return ret if not sparql_match: M = MyspaceScrape(uid=uid.rsplit('.rdf')[0]) M.run() if USE_SPARQL: M.insert_sparql(cursor) cursor.close() connect.commit() connect.close() return M.serialize() elif uid.endswith('.html'): # serve the html - THIS NEVER HAPPENS AND PRY NEVER WILL :p mh = Htmlify("http://dbtune.org/myspace/uid/"+uid.rsplit('.html')[0]) mh.parse_rdf() mh.get_all() return mh.html_head + mh.serialize_n3() + mh.get_available_as() +mh.html_tail else: raise cherrypy.HTTPRedirect(URL_BASE+'/uid/'+uid+'.rdf', 303)
def test_make_graph(self): cursor = self.connect.cursor() ss = SparqlSpace(self.uri, cursor) ss.select(GRAPH) print ss.make_graph()
def test__still_fresh__(self): d = '2009-03-17T14:27:59+01:00' ss = SparqlSpace(self.uri, self.connect) assert not ss.__still_fresh__(d), 'this date should not be fresh'