[tracker/wip/sam/meson] functional-tests: Add test case for re-extracting known files
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/sam/meson] functional-tests: Add test case for re-extracting known files
- Date: Sun, 25 Sep 2016 13:16:36 +0000 (UTC)
commit 60ece7f9c1a6c53b611ec9e410bfbff4f4111869
Author: Sam Thursfield <sam afuera me uk>
Date: Wed Jul 13 15:45:55 2016 +0100
functional-tests: Add test case for re-extracting known files
This testcase should pass. I did think there was a bug here and
opened <https://bugzilla.gnome.org/show_bug.cgi?id=768706>, but
that turned out to be invalid.
...{400-extractor.py => 400-extractor-metadata.py} | 0
tests/functional-tests/410-extractor-decorator.py | 107 ++++++++++++++++++++
tests/functional-tests/Makefile.am | 3 +-
tests/functional-tests/common/utils/helpers.py | 7 ++
tests/functional-tests/common/utils/system.py | 6 +-
5 files changed, 120 insertions(+), 3 deletions(-)
---
diff --git a/tests/functional-tests/400-extractor.py b/tests/functional-tests/400-extractor-metadata.py
similarity index 100%
rename from tests/functional-tests/400-extractor.py
rename to tests/functional-tests/400-extractor-metadata.py
diff --git a/tests/functional-tests/410-extractor-decorator.py
b/tests/functional-tests/410-extractor-decorator.py
new file mode 100755
index 0000000..1b8defb
--- /dev/null
+++ b/tests/functional-tests/410-extractor-decorator.py
@@ -0,0 +1,107 @@
+#!/usr/bin/python
+
+# Copyright (C) 2016, Sam Thursfield (sam afuera me uk)
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+"""
+Tests failure cases of tracker-extract.
+"""
+
+import unittest2 as ut
+
+from gi.repository import GLib
+
+import os
+import shutil
+import time
+
+import common.utils.configuration as cfg
+from common.utils.helpers import log
+from common.utils.minertest import MINER_TMP_DIR, path, uri
+from common.utils.system import TrackerSystemAbstraction
+
+
+CONF_OPTIONS = {
+ cfg.DCONF_MINER_SCHEMA: {
+ 'index-recursive-directories': GLib.Variant.new_strv([]),
+ 'index-single-directories': GLib.Variant.new_strv([MINER_TMP_DIR]),
+ 'index-optical-discs': GLib.Variant.new_boolean(False),
+ 'index-removable-devices': GLib.Variant.new_boolean(False),
+ }
+}
+
+
+CORRUPT_FILE = os.path.join(
+ os.path.dirname(__file__), 'test-extraction-data', 'audio',
+ 'audio-corrupt.mp3')
+
+VALID_FILE = os.path.join(
+ os.path.dirname(__file__), 'test-extraction-data', 'audio',
+ 'audio-test-1.mp3')
+VALID_FILE_CLASS = 'nmm:MusicPiece'
+VALID_FILE_TITLE = 'Simply Juvenile'
+
+TRACKER_EXTRACT_FAILURE_DATA_SOURCE = 'tracker:extractor-failure-data-source'
+
+
+class ExtractorDecoratorTest(ut.TestCase):
+ def setUp(self):
+ if not os.path.exists(MINER_TMP_DIR):
+ os.makedirs(MINER_TMP_DIR)
+ assert os.path.isdir(MINER_TMP_DIR)
+
+ self.system = TrackerSystemAbstraction(CONF_OPTIONS)
+ self.system.tracker_miner_fs_testing_start()
+
+ def tearDown(self):
+ self.system.tracker_miner_fs_testing_stop()
+
+ shutil.rmtree(MINER_TMP_DIR)
+
+ def test_reextraction(self):
+ """Tests whether known files are still re-extracted on user request."""
+ miner_fs = self.system.miner_fs
+ store = self.system.store
+
+ # Insert a valid file and wait extraction of its metadata.
+ file_path = os.path.join(MINER_TMP_DIR, os.path.basename(VALID_FILE))
+ shutil.copy(VALID_FILE, file_path)
+ file_id, file_urn = store.await_resource_inserted(
+ VALID_FILE_CLASS, title=VALID_FILE_TITLE)
+
+ # Remove a key piece of metadata.
+ store.update(
+ 'DELETE { <%s> nie:title ?title }'
+ ' WHERE { <%s> nie:title ?title }' % (file_urn, file_urn))
+ store.await_property_changed(file_id, 'nie:title')
+ assert not store.ask('ASK { <%s> nie:title ?title }' % file_urn)
+
+ log("Sending re-index request")
+ # Request re-indexing (same as `tracker index --file ...`)
+ miner_fs.index_file(uri(file_path))
+
+ # The extractor should reindex the file and re-add the metadata that we
+ # deleted, so we should see the nie:title property change.
+ store.await_property_changed(file_id, 'nie:title')
+
+ title_result = store.query('SELECT ?title { <%s> nie:title ?title }' % file_urn)
+ assert len(title_result) == 1
+ self.assertEqual(title_result[0][0], VALID_FILE_TITLE)
+
+
+if __name__ == '__main__':
+ ut.main()
diff --git a/tests/functional-tests/Makefile.am b/tests/functional-tests/Makefile.am
index edd91be..2359211 100644
--- a/tests/functional-tests/Makefile.am
+++ b/tests/functional-tests/Makefile.am
@@ -48,7 +48,8 @@ if HAVE_TRACKER_FTS
standard_tests += 310-fts-indexing.py
endif
standard_tests += \
- 400-extractor.py \
+ 400-extractor-metadata.py \
+ 410-extractor-decorator.py \
500-writeback.py \
501-writeback-details.py \
600-applications-camera.py \
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index 70099c6..ee5fc11 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -555,16 +555,23 @@ class MinerFsHelper (Helper):
self.miner_fs = Gio.DBusProxy.new_sync(
self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None,
cfg.MINERFS_BUSNAME, cfg.MINERFS_OBJ_PATH, cfg.MINER_IFACE)
+ self.index = Gio.DBusProxy.new_sync(
+ self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None,
+ cfg.MINERFS_BUSNAME, cfg.MINERFS_INDEX_OBJ_PATH, cfg.MINER_INDEX_IFACE)
def stop (self):
Helper.stop (self)
+ def index_file (self, uri):
+ return self.index.IndexFile('(s)', uri)
+
class ExtractorHelper (Helper):
PROCESS_NAME = 'tracker-extract'
BUS_NAME = cfg.TRACKER_EXTRACT_BUSNAME
+
class WritebackHelper (Helper):
PROCESS_NAME = 'tracker-writeback'
diff --git a/tests/functional-tests/common/utils/system.py b/tests/functional-tests/common/utils/system.py
index 717e65f..093b468 100644
--- a/tests/functional-tests/common/utils/system.py
+++ b/tests/functional-tests/common/utils/system.py
@@ -33,9 +33,11 @@ class UnableToBootException (Exception):
pass
-class TrackerSystemAbstraction:
+class TrackerSystemAbstraction (object):
+ def __init__(self, settings=None, ontodir=None):
+ self.set_up_environment (settings=settings, ontodir=ontodir)
- def set_up_environment (self, settings, ontodir):
+ def set_up_environment (self, settings=None, ontodir=None):
"""
Sets up the XDG_*_HOME variables and make sure the directories exist
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]