[tracker: 2/6] functional-tests: Many fixes to 3xx-miner tests



commit 9594aff3020f7219e11296088b205eb929905354
Author: Sam Thursfield <sam afuera me uk>
Date:   Wed Dec 24 18:17:21 2014 +0000

    functional-tests: Many fixes to 3xx-miner tests
    
    All 3xx tests should now pass except 2 of the 310-fts-indexing tests.

 tests/functional-tests/300-miner-basic-ops.py      |   38 +++++++++++--------
 .../functional-tests/301-miner-resource-removal.py |   35 ++++++++----------
 tests/functional-tests/310-fts-indexing.py         |   24 ++++++++++---
 tests/functional-tests/common/utils/minertest.py   |    3 ++
 4 files changed, 59 insertions(+), 41 deletions(-)
---
diff --git a/tests/functional-tests/300-miner-basic-ops.py b/tests/functional-tests/300-miner-basic-ops.py
index 9725997..156e471 100755
--- a/tests/functional-tests/300-miner-basic-ops.py
+++ b/tests/functional-tests/300-miner-basic-ops.py
@@ -203,9 +203,9 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         """
         Move a file from monitored to unmonitored directory
         """
-        source = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file2.txt")
-        dest = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file2.txt")
-        source_id = self.system.store.get_resource_id (uri(dest))
+        source = path("test-monitored/dir1/file2.txt")
+        dest = path("test-no-monitored/file2.txt")
+        source_id = self.system.store.get_resource_id (uri(source))
         shutil.move (source, dest)
         self.system.store.await_resource_deleted (source_id)
 
@@ -217,7 +217,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
 
         # Restore the file
         shutil.move (dest, source)
-        self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
+        self.system.store.await_resource_inserted ('nfo:TextDocument', uri(source))
         self.assertEquals (3, self.tracker.count_instances ("nfo:TextDocument"))
 
 
@@ -225,19 +225,22 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         """
         Move a file between monitored directories
         """
-        source = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file2.txt")
-        dest = os.path.join (MINER_TMP_DIR, "test-monitored", "file2.txt")
 
-        source_dir_urn = self.__get_file_urn (os.path.join (MINER_TMP_DIR, "test-monitored", "dir1"))
+        source = path("test-monitored/dir1/file2.txt")
+        dest = path("test-monitored/file2.txt")
+
+        resource_id = self.tracker.get_resource_id(url=uri(source))
+
+        source_dir_urn = self.__get_file_urn (os.path.dirname(source))
         parent_before = self.__get_parent_urn (source)
         self.assertEquals (source_dir_urn, parent_before)
 
         shutil.move (source, dest)
-        self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
+        self.tracker.await_property_changed(resource_id, 'nie:url')
 
         # Checking fix for NB#214413: After a move operation, nfo:belongsToContainer
         # should be changed to the new one
-        dest_dir_urn = self.__get_file_urn (os.path.join (MINER_TMP_DIR, "test-monitored"))
+        dest_dir_urn = self.__get_file_urn (os.path.dirname(dest))
         parent_after = self.__get_parent_urn (dest)
         self.assertNotEquals (parent_before, parent_after)
         self.assertEquals (dest_dir_urn, parent_after)
@@ -251,7 +254,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
 
         # Restore the file
         shutil.move (dest, source)
-        self.system.store.await_resource_inserted ('nfo:TextDocument', uri(source))
+        self.tracker.await_property_changed(resource_id, 'nie:url')
 
         result = self.__get_text_documents ()
         self.assertEquals (len (result), 3)
@@ -263,7 +266,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         """
         Delete one of the files
         """
-        victim = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file2.txt")
+        victim = path("test-monitored/dir1/file2.txt")
         victim_id = self.system.store.get_resource_id (uri(victim))
         os.remove (victim)
         self.system.store.await_resource_deleted (victim_id)
@@ -284,10 +287,13 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         """
         Delete a directory
         """
-        victim = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1")
+        victim = path("test-monitored/dir1")
         victim_id = self.system.store.get_resource_id (uri(victim))
         shutil.rmtree (victim)
-        self.system.store.await_resource_deleted (victim_id)
+
+        file_inside_victim_url = uri (os.path.join (victim, "file2.txt"))
+        file_inside_victim_id = self.system.store.get_resource_id (file_inside_victim_url)
+        self.system.store.await_resource_deleted (file_inside_victim_id)
 
         result = self.__get_text_documents ()
         self.assertEquals (len (result), 1)
@@ -295,11 +301,11 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         self.assertIn ( uri ("test-monitored/file1.txt"), unpacked_result)
 
         # Restore the dirs
-        os.makedirs (os.path.join (MINER_TMP_DIR, "test-monitored", "dir1"))
-        os.makedirs (os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "dir2"))
+        os.makedirs (path("test-monitored/dir1"))
+        os.makedirs (path("test-monitored/dir1/dir2"))
         for f in ["test-monitored/dir1/file2.txt",
                   "test-monitored/dir1/dir2/file3.txt"]:
-            filename = os.path.join (MINER_TMP_DIR, f)
+            filename = path(f)
             writer = open (filename, "w")
             writer.write ("Don't panic, everything is fine")
             writer.close ()
diff --git a/tests/functional-tests/301-miner-resource-removal.py 
b/tests/functional-tests/301-miner-resource-removal.py
index 976c82e..d49d32b 100755
--- a/tests/functional-tests/301-miner-resource-removal.py
+++ b/tests/functional-tests/301-miner-resource-removal.py
@@ -25,6 +25,7 @@ especially in the case where nie:InformationElement != nie:DataObject
 from common.utils import configuration as cfg
 from common.utils.dconf import DConfClient
 from common.utils.helpers import MinerFsHelper, StoreHelper, ExtractorHelper, log
+from common.utils.minertest import CommonTrackerMinerTest, path, uri
 from common.utils.system import TrackerSystemAbstraction
 
 from gi.repository import GLib
@@ -37,12 +38,6 @@ import unittest2 as ut
 
 MINER_TMP_DIR = cfg.TEST_MONITORED_TMP_DIR
 
-def get_test_path (filename):
-    return os.path.join (MINER_TMP_DIR, filename)
-
-def get_test_uri (filename):
-    return "file://" + os.path.join (MINER_TMP_DIR, filename)
-
 
 CONF_OPTIONS = {
     cfg.DCONF_MINER_SCHEMA: {
@@ -107,14 +102,14 @@ class MinerResourceRemovalTest (ut.TestCase):
                                                    title = title)
 
     def create_test_file (self, file_name):
-        file_path = get_test_path (file_name)
+        file_path = path(file_name)
 
         file = open (file_path, 'w')
         file.write ("Test")
         file.close ()
 
         return self.store.await_resource_inserted (rdf_class = 'nfo:Document',
-                                                   url = get_test_uri (file_name));
+                                                   url = uri(file_name))
 
     def assertResourceExists (self, urn):
         if self.store.ask ("ASK { <%s> a rdfs:Resource }" % urn) == False:
@@ -131,12 +126,12 @@ class MinerResourceRemovalTest (ut.TestCase):
         in a file is deleted when the file is deleted.
         """
 
-        (file_1_id, file_1_urn) = self.create_test_file ("test_1.txt")
-        (file_2_id, file_2_urn) = self.create_test_file ("test_2.txt")
+        (file_1_id, file_1_urn) = self.create_test_file ("test-monitored/test_1.txt")
+        (file_2_id, file_2_urn) = self.create_test_file ("test-monitored/test_2.txt")
         (ie_1_id, ie_1_urn) = self.create_test_content (file_1_urn, "Test resource 1")
         (ie_2_id, ie_2_urn) = self.create_test_content (file_2_urn, "Test resource 2")
 
-        os.unlink (get_test_path ("test_1.txt"))
+        os.unlink (path ("test-monitored/test_1.txt"))
 
         self.store.await_resource_deleted (file_1_id)
         self.store.await_resource_deleted (ie_1_id,
@@ -148,15 +143,15 @@ class MinerResourceRemovalTest (ut.TestCase):
         self.assertResourceExists (file_2_urn)
         self.assertResourceExists (ie_2_urn)
 
-    def test_02_removable_device_data (self):
-        """
-        Tracker does periodic cleanups of data on removable volumes that haven't
-        been seen since 'removable-days-threshold', and will also remove all data
-        from removable volumes if 'index-removable-devices' is disabled.
-
-        FIXME: not yet possible to test this - we need some way of mounting
-        a fake removable volume: https://bugzilla.gnome.org/show_bug.cgi?id=659739
-        """
+    #def test_02_removable_device_data (self):
+    #    """
+    #    Tracker does periodic cleanups of data on removable volumes that haven't
+    #    been seen since 'removable-days-threshold', and will also remove all data
+    #    from removable volumes if 'index-removable-devices' is disabled.
+    #
+    #    FIXME: not yet possible to test this - we need some way of mounting
+    #    a fake removable volume: https://bugzilla.gnome.org/show_bug.cgi?id=659739
+    #    """
 
         #dconf = DConfClient ()
         #dconf.write (cfg.DCONF_MINER_SCHEMA, 'index-removable-devices', 'true')
diff --git a/tests/functional-tests/310-fts-indexing.py b/tests/functional-tests/310-fts-indexing.py
index 78010f7..872f495 100755
--- a/tests/functional-tests/310-fts-indexing.py
+++ b/tests/functional-tests/310-fts-indexing.py
@@ -55,13 +55,22 @@ class CommonMinerFTS (CommonTrackerMinerTest):
         pass
 
     def set_text (self, text):
+        exists = os.path.exists(path(self.testfile))
+
         f = open (path (self.testfile), "w")
         f.write (text)
         f.close ()
-        self.tracker.await_resource_inserted (rdf_class = 'nfo:Document',
-                                              url = uri (self.testfile),
-                                              required_property = 'nie:plainTextContent')
-        self.tracker.reset_graph_updates_tracking ()
+
+        if exists:
+            subject_id = self.tracker.get_resource_id(uri(self.testfile))
+            self.tracker.await_property_changed(
+                subject_id=subject_id, property_uri='nie:plainTextContent')
+        else:
+            self.tracker.await_resource_inserted(
+                rdf_class='nfo:Document', url=uri(self.testfile),
+                required_property='nie:plainTextContent')
+
+        self.tracker.reset_graph_updates_tracking()
 
     def search_word (self, word):
         """
@@ -198,6 +207,8 @@ class MinerFTSFileOperationsTest (CommonMinerFTS):
     def test_02_empty_the_file (self):
         """
         Emptying the file, the indexed words are also removed
+
+        FIXME: this test currently fails!
         """
         TEXT = "automobile is red and big and whatnot"
         self.basic_test (TEXT, "automobile")
@@ -209,6 +220,8 @@ class MinerFTSFileOperationsTest (CommonMinerFTS):
     def test_03_update_the_file (self):
         """
         Changing the contents of the file, updates the index
+
+        FIXME: this test fails!
         """
         TEXT = "automobile is red and big and whatnot"
         self.basic_test (TEXT, "automobile")
@@ -264,7 +277,8 @@ class MinerFTSFileOperationsTest (CommonMinerFTS):
 
         shutil.copyfile ( path (TEST_16_SOURCE), path (TEST_16_DEST))
         self.tracker.await_resource_inserted (rdf_class = 'nfo:Document',
-                                              url = uri (TEST_16_DEST))
+                                              url = uri(TEST_16_DEST),
+                                              required_property = 'nie:plainTextContent')
 
         results = self.search_word ("airplane")
         self.assertEquals (len (results), 1)
diff --git a/tests/functional-tests/common/utils/minertest.py 
b/tests/functional-tests/common/utils/minertest.py
index 113eca9..b2a0a3d 100644
--- a/tests/functional-tests/common/utils/minertest.py
+++ b/tests/functional-tests/common/utils/minertest.py
@@ -110,3 +110,6 @@ class CommonTrackerMinerTest (ut.TestCase):
     @classmethod
     def tearDownClass (self):
         self.system.tracker_miner_fs_testing_stop ()
+
+    def setUp (self):
+        self.tracker.reset_graph_updates_tracking ()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]