[tracker/functional-tests-applications: 4/14] functional tests, applications: Improved camera simulation tests, including writeback+geotags



commit 47476891198a5dd1c05bb3594c8f4ee32253430f
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Thu Jan 20 19:41:05 2011 +0100

    functional tests, applications: Improved camera simulation tests, including writeback+geotags

 tests/functional-tests/600-applications.py |  128 +++++++++++++++++++++++++--
 1 files changed, 118 insertions(+), 10 deletions(-)
---
diff --git a/tests/functional-tests/600-applications.py b/tests/functional-tests/600-applications.py
index e9bc31c..741c0c5 100755
--- a/tests/functional-tests/600-applications.py
+++ b/tests/functional-tests/600-applications.py
@@ -40,6 +40,7 @@ SRC_IMAGE_DIR = os.path.join (cfg.DATADIR,
                               "data",
                               "Images")
 SRC_IMAGE_PATH = os.path.join (SRC_IMAGE_DIR, TEST_IMAGE)
+MINER_FS_IDLE_TIMEOUT = 5
 
 
 class TrackerApplicationTests (CommonTrackerApplicationTest):
@@ -48,9 +49,7 @@ class TrackerApplicationTests (CommonTrackerApplicationTest):
         select = """
         SELECT ?u WHERE { ?u nie:url \"%s\" }
         """ % (url)
-        result = self.tracker.query (select)
-        print "SELECT returned %d results: %s" % (len(result),result)
-        return len (result)
+        return len (self.tracker.query (select))
 
 
     def test_camera_insert_01 (self):
@@ -69,26 +68,135 @@ class TrackerApplicationTests (CommonTrackerApplicationTest):
 
         print "Storing new image in '%s'..." % (filepath)
 
-        # Insert new resource in the store
+        # Insert new resource in the store, including nie:mimeType and nie:url
         insert = """
-        INSERT { <%s> a         nie:InformationElement, nie:DataObject, nfo:Image ;
-                      nie:title \"test camera insert 01\" ;
-                      nie:url   \"%s\" }
-        """ % (fileurn, fileuri)
+        INSERT { <%s> a nie:InformationElement,
+                        nie:DataObject,
+                        nfo:Image,
+                        nfo:Media,
+                        nfo:Visual,
+                        nmm:Photo
+        }
+
+        DELETE { <%s> nie:mimeType ?_1 }
+        WHERE { <%s> nie:mimeType ?_1 }
+
+        INSERT { <%s> a            rdfs:Resource ;
+                      nie:mimeType \"image/jpeg\"
+        }
+
+        DELETE { <%s> nie:url ?_2 }
+        WHERE { <%s> nie:url ?_2 }
+
+        INSERT { <%s> a       rdfs:Resource ;
+                      nie:url \"%s\"
+        }
+        """ % (fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, fileuri)
         self.tracker.update (insert)
+        self.assertEquals (self.__get_urn_count_by_url (fileuri), 1)
+
+        # Copy the image to the dest path, simulating the camera writting
+        slowcopy (SRC_IMAGE_PATH, filepath, 1024)
+        assert os.path.exists (filepath)
+        self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
+        self.assertEquals (self.__get_urn_count_by_url (fileuri), 1)
+
+        # Clean the new file so the test directory is as before
+        print "Remove and wait"
+        os.remove (filepath)
+        self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
+        self.assertEquals (self.__get_urn_count_by_url (fileuri), 0)
+
+
+    def test_camera_insert_02 (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_insert_02/" + str(random.randint (0,100))
+        filepath = path (TEST_IMAGE)
+        fileuri = uri (TEST_IMAGE)
+
+        geolocationurn = "tracker://test_camera_insert_02_geolocation/" + str(random.randint (0,100))
+        postaladdressurn = "tracker://test_camera_insert_02_postaladdress/" + str(random.randint (0,100))
+
+        print "Storing new image in '%s'..." % (filepath)
+
+        # 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
+        }
+
+        DELETE { <%s> nie:mimeType ?_1 }
+        WHERE { <%s> nie:mimeType ?_1 }
+
+        INSERT { <%s> a            rdfs:Resource ;
+                      nie:mimeType \"image/jpeg\"
+        }
+
+        DELETE { <%s> nie:url ?_2 }
+        WHERE { <%s> nie:url ?_2 }
+
+        INSERT { <%s> a       rdfs:Resource ;
+                      nie:url \"%s\"
+        }
+        """ % (fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, fileuri)
+        self.tracker.update (insert)
         self.assertEquals (self.__get_urn_count_by_url (fileuri), 1)
 
+
         # Copy the image to the dest path, simulating the camera writting
         slowcopy (SRC_IMAGE_PATH, filepath, 1024)
         assert os.path.exists (filepath)
-        self.system.tracker_miner_fs_wait_for_idle ()
+        self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
         self.assertEquals (self.__get_urn_count_by_url (fileuri), 1)
 
+        # Add slo:location to the new resource...
+        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.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
+        self.assertEquals (self.__get_urn_count_by_url (fileuri), 1)
+
+        query = """
+        SELECT ?locality ?country
+        WHERE { ?o a            nie:DataObject ;
+                   nie:url      \"%s\" ;
+                   slo:location ?u .
+                ?u nco:country  ?country ;
+                   nco:locality ?locality }
+        """ % fileuri
+        result = self.tracker.query (query)
+        print "RESULTS: %s" % (result)
+
+
         # Clean the new file so the test directory is as before
         print "Remove and wait"
         os.remove (filepath)
-        self.system.tracker_miner_fs_wait_for_idle ()
+        self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
         self.assertEquals (self.__get_urn_count_by_url (fileuri), 0)
 
 if __name__ == "__main__":



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