diff options
author | Sam Thursfield <sam@afuera.me.uk> | 2014-07-21 21:05:12 +0100 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2014-12-26 23:06:26 +0000 |
commit | 547a5a17bd45350913bb987d53535c125f58f9c6 (patch) | |
tree | b45cf26bc978a0cdee0529eab0a6b1c4b3421fc4 | |
parent | 133b34bb52e9109bc4f392b50bd0a9d55b283b31 (diff) | |
download | tracker-547a5a17bd45350913bb987d53535c125f58f9c6.tar.gz |
functional-tests: Consolidate and clean up 600-applications-camera
-rwxr-xr-x | tests/functional-tests/600-applications-camera.py | 249 |
1 files changed, 103 insertions, 146 deletions
diff --git a/tests/functional-tests/600-applications-camera.py b/tests/functional-tests/600-applications-camera.py index f793665c5..31a7a56fa 100755 --- a/tests/functional-tests/600-applications-camera.py +++ b/tests/functional-tests/600-applications-camera.py @@ -22,23 +22,109 @@ 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 insert_photo_resource_info (self, urn, file_url): + """ + Insert new photo resource in the store, including nie:mimeType and nie:url + """ + insert = """ + INSERT { <%(urn)s> + a nie:InformationElement, + nie:DataObject, + nfo:Image, + nfo:Media, + nfo:Visual, + nmm:Photo + } + + DELETE { <%(urn)s> nie:mimeType ?_1 } + WHERE { <%(urn)s> nie:mimeType ?_1 } + + INSERT { <%(urn)s> + a rdfs:Resource ; + nie:mimeType \"image/jpeg\" + } + + DELETE { <%(urn)s> nie:url ?_2 } + WHERE { <%(urn)s> nie:url ?_2 } + + INSERT { <%(urn)s> + a rdfs:Resource ; + nie:url \"%(file_url)s\" ; + nie:isStoredAs <%(urn)s> + } + """ % locals() + self.tracker.update (insert) + self.assertEquals (self.get_urn_count_by_url (file_url), 1) + + def insert_video_resource_info (self, urn, file_url): + """ + Insert new video resource in the store, including nie:mimeType and nie:url + """ + insert = """ + INSERT { <%(urn)s> + a nie:InformationElement, + nie:DataObject, + nfo:Video, + nfo:Media, + nfo:Visual, + nmm:Video + } + + DELETE { <%(urn)s> nie:mimeType ?_1 } + WHERE { <%(urn)s> nie:mimeType ?_1 } + + INSERT { <%(urn)s> + a rdfs:Resource ; + nie:mimeType \"video/mp4\" + } + + DELETE { <%(urn)s> nie:url ?_2 } + WHERE { <%(urn)s> nie:url ?_2 } + + INSERT { <%(urn)s> + a rdfs:Resource ; + nie:url \"%(file_url)s\" ; + nie:isStoredAs <%(urn)s> + } + """ % locals() + self.tracker.update (insert) + self.assertEquals (self.get_urn_count_by_url (file_url), 1) + + 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\" ; + 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) + + +class TrackerCameraPicturesApplicationTests (TrackerCameraTestSuite): def test_01_camera_picture (self): """ @@ -55,32 +141,7 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest): 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, - 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, dest_fileuri) - self.tracker.update (insert) - self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1) + self.insert_photo_resource_info (fileurn, dest_fileuri) # Copy the image to the dest path self.slowcopy_file (origin_filepath, dest_filepath) @@ -94,7 +155,6 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest): 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: @@ -113,32 +173,7 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest): 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 - } - - 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, dest_fileuri) - self.tracker.update (insert) - self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1) + 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... @@ -148,21 +183,7 @@ class TrackerCameraPicturesApplicationTests (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 original_file = os.path.join (self.get_data_dir (),self.get_test_image ()) @@ -181,7 +202,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): """ @@ -198,32 +219,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\" - } - """ % (fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, dest_fileuri) - 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) @@ -257,32 +253,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\" - } - """ % (fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, fileurn, dest_fileuri) - 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... @@ -292,21 +263,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) |