def setUpClass(self): self.tmpdir = tempfile.mkdtemp(prefix='tracker-test-') try: self.conn = Tracker.SparqlConnection.new( Tracker.SparqlConnectionFlags.NONE, Gio.File.new_for_path(self.tmpdir), Gio.File.new_for_path(cfg.ontologies_dir()), None) self.tracker = trackertestutils.helpers.StoreHelper(self.conn) except Exception: shutil.rmtree(self.tmpdir, ignore_errors=True) raise
def test_import(self): """Import a Turtle file into a Tracker database.""" testdata = str(self.data_path('test-movie.ttl')) with self.tmpdir() as tmpdir: ontology_path = configuration.ontologies_dir() self.run_cli([ 'tracker3', 'endpoint', '--database', tmpdir, '--ontology-path', ontology_path ]) self.run_cli( ['tracker3', 'import', '--database', tmpdir, testdata])
def test_export(self): """Export contents of a Tracker database.""" with self.tmpdir() as tmpdir: ontology_path = configuration.ontologies_dir() # Create a database and export it as Turtle. # We don't validate the output in this test, but we should. self.run_cli([ 'tracker3', 'endpoint', '--database', tmpdir, '--ontology-path', ontology_path ]) self.run_cli(['tracker3', 'export', '--database', tmpdir]) self.run_cli( ['tracker3', 'export', '--database', tmpdir, '--show-graphs'])
def test_create_local_database(self): """Create a database using `tracker3 endpoint` for local testing""" with self.tmpdir() as tmpdir: ontology_path = configuration.ontologies_dir() # Create the database self.run_cli([ 'tracker3', 'endpoint', '--database', tmpdir, '--ontology-path', ontology_path ]) # Sanity check that it works. self.run_cli([ 'tracker3', 'sparql', '--database', tmpdir, '--query', 'ASK { ?u a rdfs:Resource }' ])
def database_process_fn(tmpdir, message_queue): # This runs in a separate process and provides a clean Tracker database # exported over D-Bus to the main test process. log.info("Started database subprocess") bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) conn = Tracker.SparqlConnection.new( Tracker.SparqlConnectionFlags.NONE, Gio.File.new_for_path(tmpdir), Gio.File.new_for_path(cfg.ontologies_dir()), None) endpoint = Tracker.EndpointDBus.new(conn, bus, None, None) message_queue.put(bus.get_unique_name()) loop = GLib.MainLoop.new(None, False) loop.run()
def test_http_endpoint(self): """Create a HTTP endpoint for local testing""" with self.tmpdir() as tmpdir: ontology_path = configuration.ontologies_dir() port = random.randint(32000, 65000) address = 'http://127.0.0.1:%d/sparql' % port # Create the database self.run_background([ 'tracker3', 'endpoint', '--database', tmpdir, '--ontology-path', ontology_path, '--http-port', port ], 'Listening') # Sanity check that it works. self.run_cli([ 'tracker3', 'sparql', '--remote-service', address, '--query', 'ASK { ?u a rdfs:Resource }' ])
def database_process_fn(self, service_name, in_queue, out_queue, dbus_address): # This runs in a separate process and provides a clean Tracker database # exported over D-Bus to the main test process. log.info("Started database thread") bus = Gio.DBusConnection.new_for_address_sync( dbus_address, Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT | Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION, None, None) conn = Tracker.SparqlConnection.new( Tracker.SparqlConnectionFlags.NONE, None, Gio.File.new_for_path(cfg.ontologies_dir()), None) endpoint = Tracker.EndpointDBus.new(conn, bus, None, None) bus.call_sync('org.freedesktop.DBus', '/org/freedesktop/DBus', 'org.freedesktop.DBus', 'RequestName', GLib.Variant('(su)', (service_name, 0x4)), None, 0, -1, None) loop = GLib.MainLoop.new(None, False) def pop_update(message_queue): try: sparql = message_queue.get_nowait() if sparql is None: loop.quit() conn.update(sparql, None) out_queue.put(None) except Exception: pass return GLib.SOURCE_CONTINUE GLib.timeout_add(50, pop_update, in_queue) out_queue.put(None) loop.run() bus.close(None)
def create_local_connection(self): return Tracker.SparqlConnection.new( Tracker.SparqlConnectionFlags.NONE, None, Gio.File.new_for_path(cfg.ontologies_dir()), None)