[tracker-miners/sam/index-file-sync: 11/11] WIP: functional-tests: Add miner-on-demand test
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/index-file-sync: 11/11] WIP: functional-tests: Add miner-on-demand test
- Date: Mon, 9 Mar 2020 00:50:04 +0000 (UTC)
commit 2ae8cbc1e9778e4ccbad24b816521a6413c30751
Author: Sam Thursfield <sam afuera me uk>
Date: Mon Mar 9 01:47:31 2020 +0100
WIP: functional-tests: Add miner-on-demand test
This is for testing IndexFile, IndexFileForProcess and the
FileProcessed signal.
tests/functional-tests/fixtures.py | 8 +++++
tests/functional-tests/meson.build | 1 +
tests/functional-tests/miner-on-demand.py | 52 +++++++++++++++++++++++++++++++
tests/functional-tests/minerfshelper.py | 5 +++
4 files changed, 66 insertions(+)
---
diff --git a/tests/functional-tests/fixtures.py b/tests/functional-tests/fixtures.py
index 9cd0001a7..527a9ca16 100644
--- a/tests/functional-tests/fixtures.py
+++ b/tests/functional-tests/fixtures.py
@@ -110,6 +110,14 @@ class TrackerMinerTest(ut.TestCase):
if self.tracker.ask("ASK { <%s> a rdfs:Resource }" % urn) == True:
self.fail("Resource <%s> should not exist" % urn)
+ def assertFileNotIndexed(self, url):
+ if self.tracker.ask("ASK { <?r> a rdfs:Resource ; nie:url <%s> }" % url) == True:
+ self.fail("File <%s> should not be indexed" % url)
+
+ def assertFileIndexed(self, url):
+ if self.tracker.ask("ASK { <?r> a rdfs:Resource ; nie:url <%s> }" % url) == False:
+ self.fail("File <%s> should be indexed, but is not." % url)
+
def await_document_inserted(self, path, content=None):
"""Wraps await_insert() context manager."""
url = self.uri(path)
diff --git a/tests/functional-tests/meson.build b/tests/functional-tests/meson.build
index 4944ff2c4..67b571cdc 100644
--- a/tests/functional-tests/meson.build
+++ b/tests/functional-tests/meson.build
@@ -103,6 +103,7 @@ endif
functional_tests = [
'miner-basic',
+ 'miner-on-demand',
'miner-resource-removal',
'fts-basic',
'fts-file-operations',
diff --git a/tests/functional-tests/miner-on-demand.py b/tests/functional-tests/miner-on-demand.py
new file mode 100644
index 000000000..cf9c85c34
--- /dev/null
+++ b/tests/functional-tests/miner-on-demand.py
@@ -0,0 +1,52 @@
+# Copyright (C) 2020, 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.
+
+import pathlib
+import unittest
+
+import fixtures
+
+
+class MinerOnDemandTest(fixtures.TrackerMinerTest):
+ """
+ Tests on-demand indexing.
+
+ This covers the IndexFile and IndexFileForProcess D-Bus methods, and the
+ FileProcessed signal.
+ """
+
+ def setUp(self):
+ fixtures.TrackerMinerTest.setUp(self)
+
+ self.testfile = pathlib.Path(self.workdir).joinpath("test-not-monitored/on-demand.txt")
+ self.testfile.parent.mkdir(parents=True, exist_ok=True)
+ self.testfile.write_text("Hello, I'm a test file.")
+
+ def test_index_file_basic(self):
+ """
+ Test on-demand indexing of a file.
+ """
+
+ self.assertFileNotIndexed(self.testfile.as_uri())
+
+ self.miner_fs.index_file(self.testfile.as_uri())
+
+ self.assertFileIndexed(self.testfile.as_uri())
+
+
+if __name__ == "__main__":
+ unittest.main(failfast=True, verbosity=2)
diff --git a/tests/functional-tests/minerfshelper.py b/tests/functional-tests/minerfshelper.py
index 23edf2d2c..87f54e1b1 100644
--- a/tests/functional-tests/minerfshelper.py
+++ b/tests/functional-tests/minerfshelper.py
@@ -136,4 +136,9 @@ class MinerFsHelper ():
GLib.source_remove(timeout_id)
def index_file(self, uri):
+ log.debug("IndexFile(%s)", uri)
return self.index.IndexFile('(s)', uri)
+
+ @contextlib.contextmanager
+ def await_file_processed(self):
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]