[tracker/sam/functional-test-fixes: 27/28] functional-tests: Consolidate and clean up 600-applications-camera



commit 54a932d0bf420783b794e08797fc92af917ea5e7
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon Jul 21 21:05:12 2014 +0100

    functional-tests: Consolidate and clean up 600-applications-camera
    
    Two of the four tests still fail right now, due to the filesystem miner
    not removing the metadata for photo resources when they are deleted on disk.

 tests/functional-tests/600-applications-camera.py |  223 ++++++++-------------
 1 files changed, 85 insertions(+), 138 deletions(-)
---
diff --git a/tests/functional-tests/600-applications-camera.py 
b/tests/functional-tests/600-applications-camera.py
index 7be69c1..b6495e1 100755
--- a/tests/functional-tests/600-applications-camera.py
+++ b/tests/functional-tests/600-applications-camera.py
@@ -22,40 +22,23 @@
 Tests trying to simulate the behaviour of applications working with tracker
 """
 
-import sys,os,dbus
-import unittest
-import time
+import os
 import random
-import string
-import datetime
-import shutil
-import fcntl
 
-from common.utils import configuration as cfg
 import unittest2 as ut
 from common.utils.applicationstest import CommonTrackerApplicationTest as CommonTrackerApplicationTest
 from common.utils.helpers import log
 
-MINER_FS_IDLE_TIMEOUT = 30
 
-class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest):
+class TrackerCameraTestSuite (CommonTrackerApplicationTest):
+    """
+    Common functionality for camera tests.
+    """
 
-    def test_01_camera_picture (self):
+    def insert_photo_resource_info (self, urn, url):
         """
-        Camera simulation:
-
-        1. Create resource in the store for the new file
-        2. Write the file
-        3. Wait for miner-fs to index it
-        4. Ensure no duplicates are found
+        Insert new photo resource in the store, including nie:mimeType and nie:url
         """
-
-        fileurn = "tracker://test_camera_picture_01/" + str(random.randint (0,100))
-        origin_filepath = os.path.join (self.get_data_dir (), self.get_test_image ())
-        dest_filepath = os.path.join (self.get_dest_dir (), self.get_test_image ())
-        dest_fileuri = "file://" + dest_filepath
-
-        # Insert new resource in the store, including nie:mimeType and nie:url
         insert = """
         INSERT { <%s> a nie:InformationElement,
                         nie:DataObject,
@@ -79,56 +62,28 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest):
                       nie:url \"%s\" ;
                       nie:isStoredAs <%s>
         }
-        """ % (fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, dest_fileuri, fileurn)
+        """ % (urn, urn, urn, urn, urn, urn, urn, url, urn)
         self.tracker.update (insert)
-        self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
+        self.assertEquals (self.get_urn_count_by_url (url), 1)
 
-        # Copy the image to the dest path
-        self.slowcopy_file (origin_filepath, dest_filepath)
-        assert os.path.exists (dest_filepath)
-        dest_id, dest_urn = self.system.store.await_resource_inserted ('nmm:Photo', dest_fileuri)
-        self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
-
-        # Clean the new file so the test directory is as before
-        log ("Remove and wait")
-        os.remove (dest_filepath)
-        self.system.store.await_resource_deleted (dest_id)
-        self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
-
-
-    def test_02_camera_picture_geolocation (self):
+    def insert_video_resource_info (self, urn, url):
         """
-        Camera simulation:
-
-        1. Create resource in the store for the new file
-        2. Set nlo:location
-        2. Write the file
-        3. Wait for miner-fs to index it
-        4. Ensure no duplicates are found
+        Insert new video resource in the store, including nie:mimeType and nie:url
         """
-
-        fileurn = "tracker://test_camera_picture_02/" + str(random.randint (0,100))
-        dest_filepath = os.path.join (self.get_dest_dir (), self.get_test_image ())
-        dest_fileuri = "file://" + dest_filepath
-
-        geolocationurn = "tracker://test_camera_picture_02_geolocation/" + str(random.randint (0,100))
-        postaladdressurn = "tracker://test_camera_picture_02_postaladdress/" + str(random.randint (0,100))
-
-        # Insert new resource in the store, including nie:mimeType and nie:url
         insert = """
         INSERT { <%s> a nie:InformationElement,
                         nie:DataObject,
                         nfo:Image,
                         nfo:Media,
                         nfo:Visual,
-                        nmm:Photo
+                        nmm:Video
         }
 
         DELETE { <%s> nie:mimeType ?_1 }
         WHERE { <%s> nie:mimeType ?_1 }
 
         INSERT { <%s> a            rdfs:Resource ;
-                      nie:mimeType \"image/jpeg\"
+                      nie:mimeType \"video/mp4\"
         }
 
         DELETE { <%s> nie:url ?_2 }
@@ -138,18 +93,14 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest):
                       nie:url \"%s\" ;
                       nie:isStoredAs <%s>
         }
-        """ % (fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, dest_fileuri, fileurn)
+        """ % (urn, urn, urn, urn, urn, urn, urn, url, urn)
         self.tracker.update (insert)
-        self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
-
-        # FIRST, open the file for writing, and just write some garbage, to simulate that
-        # we already started recording the video...
-        fdest = open (dest_filepath, 'wb')
-        fdest.write ("some garbage written here")
-        fdest.write ("to simulate we're recording something...")
-        fdest.seek (0)
+        self.assertEquals (self.get_urn_count_by_url (url), 1)
 
-        # SECOND, set slo:location
+    def insert_dummy_location_info (self, fileurn, geolocationurn, postaladdressurn):
+        """
+        Insert placeholder location info for a file
+        """
         location_insert = """
         INSERT { <%s> a             nco:PostalAddress ;
                       nco:country  \"SPAIN\" ;
@@ -166,6 +117,68 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest):
         """ % (postaladdressurn, geolocationurn, postaladdressurn, fileurn, geolocationurn)
         self.tracker.update (location_insert)
 
+
+class TrackerCameraPicturesApplicationTests (TrackerCameraTestSuite):
+
+    def test_01_camera_picture (self):
+        """
+        Camera simulation:
+
+        1. Create resource in the store for the new file
+        2. Write the file
+        3. Wait for miner-fs to index it
+        4. Ensure no duplicates are found
+        """
+
+        fileurn = "tracker://test_camera_picture_01/" + str(random.randint (0,100))
+        origin_filepath = os.path.join (self.get_data_dir (), self.get_test_image ())
+        dest_filepath = os.path.join (self.get_dest_dir (), self.get_test_image ())
+        dest_fileuri = "file://" + dest_filepath
+
+        self.insert_photo_resource_info (fileurn, dest_fileuri)
+
+        # Copy the image to the dest path
+        self.slowcopy_file (origin_filepath, dest_filepath)
+        assert os.path.exists (dest_filepath)
+        dest_id, dest_urn = self.system.store.await_resource_inserted ('nmm:Photo', dest_fileuri)
+        self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
+
+        # Clean the new file so the test directory is as before
+        log ("Remove and wait")
+        os.remove (dest_filepath)
+        self.system.store.await_resource_deleted (dest_id)
+        self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
+
+    def test_02_camera_picture_geolocation (self):
+        """
+        Camera simulation:
+
+        1. Create resource in the store for the new file
+        2. Set nlo:location
+        2. Write the file
+        3. Wait for miner-fs to index it
+        4. Ensure no duplicates are found
+        """
+
+        fileurn = "tracker://test_camera_picture_02/" + str(random.randint (0,100))
+        dest_filepath = os.path.join (self.get_dest_dir (), self.get_test_image ())
+        dest_fileuri = "file://" + dest_filepath
+
+        geolocationurn = "tracker://test_camera_picture_02_geolocation/" + str(random.randint (0,100))
+        postaladdressurn = "tracker://test_camera_picture_02_postaladdress/" + str(random.randint (0,100))
+
+        self.insert_photo_resource_info (fileurn, dest_fileuri)
+
+        # FIRST, open the file for writing, and just write some garbage, to simulate that
+        # we already started recording the video...
+        fdest = open (dest_filepath, 'wb')
+        fdest.write ("some garbage written here")
+        fdest.write ("to simulate we're recording something...")
+        fdest.seek (0)
+
+        # SECOND, set slo:location
+        self.insert_dummy_location_info (fileurn, geolocationurn, postaladdressurn)
+
         #THIRD, start copying the image to the dest path
         original_file = os.path.join (self.get_data_dir (),self.get_test_image ())
         self.slowcopy_file_fd (original_file, fdest)
@@ -183,7 +196,7 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest):
         self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
 
 
-class TrackerCameraVideosApplicationTests (CommonTrackerApplicationTest):
+class TrackerCameraVideosApplicationTests (TrackerCameraTestSuite):
 
     def test_01_camera_video (self):
         """
@@ -200,33 +213,7 @@ class TrackerCameraVideosApplicationTests (CommonTrackerApplicationTest):
         dest_filepath = os.path.join (self.get_dest_dir (), self.get_test_video ())
         dest_fileuri = "file://" + dest_filepath
 
-        # Insert new resource in the store, including nie:mimeType and nie:url
-        insert = """
-        INSERT { <%s> a nie:InformationElement,
-                        nie:DataObject,
-                        nfo:Video,
-                        nfo:Media,
-                        nfo:Visual,
-                        nmm:Video
-        }
-
-        DELETE { <%s> nie:mimeType ?_1 }
-        WHERE { <%s> nie:mimeType ?_1 }
-
-        INSERT { <%s> a            rdfs:Resource ;
-                      nie:mimeType \"video/mp4\"
-        }
-
-        DELETE { <%s> nie:url ?_2 }
-        WHERE { <%s> nie:url ?_2 }
-
-        INSERT { <%s> a       rdfs:Resource ;
-                      nie:url \"%s\" ;
-                      nie:isStoredAs <%s>
-        }
-        """ % (fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, dest_fileuri, fileurn)
-        self.tracker.update (insert)
-        self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
+        self.insert_video_resource_info(fileurn, dest_fileuri)
 
         # Copy the image to the dest path
         self.slowcopy_file (origin_filepath, dest_filepath)
@@ -260,33 +247,7 @@ class TrackerCameraVideosApplicationTests (CommonTrackerApplicationTest):
         geolocationurn = "tracker://test_camera_video_02_geolocation/" + str(random.randint (0,100))
         postaladdressurn = "tracker://test_camera_video_02_postaladdress/" + str(random.randint (0,100))
 
-        # Insert new resource in the store, including nie:mimeType and nie:url
-        insert = """
-        INSERT { <%s> a nie:InformationElement,
-                        nie:DataObject,
-                        nfo:Video,
-                        nfo:Media,
-                        nfo:Visual,
-                        nmm:Video
-        }
-
-        DELETE { <%s> nie:mimeType ?_1 }
-        WHERE { <%s> nie:mimeType ?_1 }
-
-        INSERT { <%s> a            rdfs:Resource ;
-                      nie:mimeType \"video/mp4\"
-        }
-
-        DELETE { <%s> nie:url ?_2 }
-        WHERE { <%s> nie:url ?_2 }
-
-        INSERT { <%s> a       rdfs:Resource ;
-                      nie:url \"%s\" ;
-                      nie:isStoredAs <%s>
-        }
-        """ % (fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, dest_fileuri, fileurn)
-        self.tracker.update (insert)
-        self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
+        self.insert_video_resource_info (fileurn, dest_fileuri)
 
         # FIRST, open the file for writing, and just write some garbage, to simulate that
         # we already started recording the video...
@@ -296,21 +257,7 @@ class TrackerCameraVideosApplicationTests (CommonTrackerApplicationTest):
         fdest.seek (0)
 
         # SECOND, set slo:location
-        location_insert = """
-        INSERT { <%s> a             nco:PostalAddress ;
-                      nco:country  \"SPAIN\" ;
-                      nco:locality \"Tres Cantos\"
-        }
-
-        INSERT { <%s> a                 slo:GeoLocation ;
-                      slo:postalAddress <%s>
-        }
-
-        INSERT { <%s> a            rdfs:Resource ;
-                      slo:location <%s>
-        }
-        """ % (postaladdressurn, geolocationurn, postaladdressurn, fileurn, geolocationurn)
-        self.tracker.update (location_insert)
+        self.insert_dummy_location_info (fileurn, geolocationurn, postaladdressurn)
 
         #THIRD, start copying the image to the dest path
         self.slowcopy_file_fd (origin_filepath, fdest)


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