[tracker/sam/functional-test-fixes: 20/28] functional-tests: Fixup 300-miner-basic-ops more



commit c062c5fb5eae4eb349b1048d915e9f3e2e3850ef
Author: Sam Thursfield <sam afuera me uk>
Date:   Sat Aug 2 00:55:00 2014 +0100

    functional-tests: Fixup 300-miner-basic-ops more

 tests/functional-tests/300-miner-basic-ops.py  |   94 ++++++++++++------------
 tests/functional-tests/common/utils/helpers.py |    5 -
 2 files changed, 46 insertions(+), 53 deletions(-)
---
diff --git a/tests/functional-tests/300-miner-basic-ops.py b/tests/functional-tests/300-miner-basic-ops.py
index 9f3de4d..c2f882a 100755
--- a/tests/functional-tests/300-miner-basic-ops.py
+++ b/tests/functional-tests/300-miner-basic-ops.py
@@ -30,8 +30,8 @@ import shutil
 import time
 
 import unittest2 as ut
-from common.utils.helpers import log, path_to_url
-from common.utils.minertest import CommonTrackerMinerTest, MINER_TMP_DIR, uri, path
+from common.utils.helpers import log
+from common.utils.minertest import CommonTrackerMinerTest, uri, path
 
 class MinerCrawlTest (CommonTrackerMinerTest):
     """
@@ -84,8 +84,6 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         """
         The precreated files and folders should be there
         """
-        # Maybe the information hasn't been committed yet
-        time.sleep (1)
         result = self.__get_text_documents ()
         self.assertEquals (len (result), 3)
         unpacked_result = [ r[0] for r in result]
@@ -106,11 +104,11 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         Copy an file from unmonitored directory to monitored directory
         and verify if data base is updated accordingly
         """
-        source = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file0.txt")
-        dest = os.path.join (MINER_TMP_DIR, "test-monitored", "file0.txt")
-        shutil.copyfile (source, dest)
+        source = os.path.join("test-no-monitored", "file0.txt")
+        dest = os.path.join("test-monitored", "file0.txt")
+        shutil.copyfile (path(source), path(dest))
 
-        dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', path_to_url(dest))
+        dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
 
         # verify if miner indexed this file.
         result = self.__get_text_documents ()
@@ -123,7 +121,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
 
         # Clean the new file so the test directory is as before
         log ("Remove and wait")
-        os.remove (dest)
+        os.remove (path(dest))
         self.system.store.await_resource_deleted (dest_id)
 
     def test_03_copy_from_monitored_to_unmonitored (self):
@@ -133,9 +131,9 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         """
 
         # Copy from monitored to unmonitored
-        source = os.path.join (MINER_TMP_DIR, "test-monitored", "file1.txt")
-        dest = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file1.txt")
-        shutil.copyfile (source, dest)
+        source = os.path.join("test-monitored", "file1.txt")
+        dest = os.path.join("test-no-monitored", "file1.txt")
+        shutil.copyfile (path(source), path(dest))
 
         time.sleep (1)
         # Nothing changed
@@ -147,17 +145,17 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
 
         # Clean the file
-        os.remove (dest)
+        os.remove (path(dest))
 
     def test_04_copy_from_monitored_to_monitored (self):
         """
         Copy a file between monitored directories
         """
-        source = os.path.join (MINER_TMP_DIR, "test-monitored", "file1.txt")
-        dest = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "dir2", "file-test04.txt")
-        shutil.copyfile (source, dest)
+        source = os.path.join("test-monitored", "file1.txt")
+        dest = os.path.join("test-monitored", "dir1", "dir2", "file-test04.txt")
+        shutil.copyfile (path(source), path(dest))
 
-        dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', path_to_url(dest))
+        dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
 
         result = self.__get_text_documents ()
         self.assertEquals (len (result), 4)
@@ -168,7 +166,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         self.assertIn ( uri ("test-monitored/dir1/dir2/file-test04.txt"), unpacked_result)
 
         # Clean the file
-        os.remove (dest)
+        os.remove (path(dest))
         self.system.store.await_resource_deleted (dest_id)
         self.assertEquals (3, self.tracker.count_instances ("nfo:TextDocument"))
 
@@ -177,10 +175,10 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         """
         Move a file from unmonitored to monitored directory
         """
-        source = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file0.txt")
-        dest = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file-test05.txt")
-        shutil.move (source, dest)
-        dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', path_to_url(dest))
+        source = os.path.join("test-no-monitored", "file0.txt")
+        dest = os.path.join("test-monitored", "dir1", "file-test05.txt")
+        shutil.move (path(source), path(dest))
+        dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
 
         result = self.__get_text_documents ()
         self.assertEquals (len (result), 4)
@@ -191,7 +189,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         self.assertIn ( uri ("test-monitored/dir1/file-test05.txt"), unpacked_result)
 
         # Clean the file
-        os.remove (dest)
+        os.remove (path(dest))
         self.system.store.await_resource_deleted (dest_id)
         self.assertEquals (3, self.tracker.count_instances ("nfo:TextDocument"))
 
@@ -203,10 +201,10 @@ 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 (path_to_url(source))
-        shutil.move (source, dest)
+        source = os.path.join("test-monitored", "dir1", "file2.txt")
+        dest = os.path.join("test-no-monitored", "file2.txt")
+        source_id = self.system.store.get_resource_id (uri(source))
+        shutil.move (path(source), path(dest))
         self.system.store.await_resource_deleted (source_id)
 
         result = self.__get_text_documents ()
@@ -216,8 +214,8 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
 
         # Restore the file
-        shutil.move (dest, source)
-        self.system.store.await_resource_inserted ('nfo:TextDocument', path_to_url(dest))
+        shutil.move (path(dest), path(source))
+        self.system.store.await_resource_inserted ('nfo:TextDocument', uri(source))
         self.assertEquals (3, self.tracker.count_instances ("nfo:TextDocument"))
 
 
@@ -225,22 +223,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 = os.path.join("test-monitored", "dir1", "file2.txt")
+        dest = os.path.join("test-monitored", "file2.txt")
 
-        source_dir_urn = self.__get_file_urn (os.path.join (MINER_TMP_DIR, "test-monitored", "dir1"))
+        source_dir_urn = self.__get_file_urn (os.basename(path(source)))
         parent_before = self.__get_parent_urn (source)
         self.assertEquals (source_dir_urn, parent_before)
 
-        shutil.move (source, dest)
+        shutil.move (path(source), path(dest))
         # FIXME: resource won't be inserted, just the nie:url field updated.
         # For now, use wait_for_idle :(
         self.system.tracker_miner_fs_wait_for_idle ()
 
         # 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"))
-        parent_after = self.__get_parent_urn (dest)
+        dest_dir_urn = self.__get_file_urn (os.path.basename(path(dest)))
+        parent_after = self.__get_parent_urn (path(dest))
         self.assertNotEquals (parent_before, parent_after)
         self.assertEquals (dest_dir_urn, parent_after)
 
@@ -252,8 +250,8 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
 
         # Restore the file
-        shutil.move (dest, source)
-        self.system.store.await_resource_inserted ('nfo:TextDocument', path_to_url(source))
+        shutil.move (path(dest), path(source))
+        self.system.store.await_resource_inserted ('nfo:TextDocument', uri(source))
 
         result = self.__get_text_documents ()
         self.assertEquals (len (result), 3)
@@ -265,9 +263,9 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         """
         Delete one of the files
         """
-        victim = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file2.txt")
-        victim_id = self.system.store.get_resource_id (path_to_url(victim))
-        os.remove (victim)
+        victim = os.path.join("test-monitored", "dir1", "file2.txt")
+        victim_id = self.system.store.get_resource_id (uri(victim))
+        os.remove (path(victim))
         self.system.store.await_resource_deleted (victim_id)
 
         result = self.__get_text_documents ()
@@ -277,19 +275,19 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
 
         # Restore the file
-        f = open (victim, "w")
+        f = open (path(victim), "w")
         f.write ("Don't panic, everything is fine")
         f.close ()
-        self.system.store.await_resource_inserted ('nfo:TextDocument', path_to_url(victim))
+        self.system.store.await_resource_inserted ('nfo:TextDocument', uri(victim))
 
     def test_09_deletion_directory (self):
         """
         Delete a directory
         """
-        victim = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1")
-        shutil.rmtree (victim)
+        victim = os.path.join("test-monitored", "dir1")
+        shutil.rmtree (path(victim))
 
-        file_inside_victim_url = path_to_url(os.path.join (victim, "file2.txt"))
+        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)
 
@@ -299,11 +297,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/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index 1ff422a..cc62db3 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -42,11 +42,6 @@ def log (message):
         print (message)
 
 
-def path_to_url (path):
-    encoded_path = urllib.pathname2url(path)
-    return urlparse.urljoin('file:', encoded_path)
-
-
 class Helper:
     """
     Abstract helper for Tracker processes. Launches the process manually


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