diff options
author | Sam Thursfield <sam@afuera.me.uk> | 2014-12-26 23:23:31 +0000 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2014-12-26 23:23:31 +0000 |
commit | fc21da4d950cbd277575191457987ef2c3c1dbe0 (patch) | |
tree | 629c736de9e32e5673985b551fff8c3f2999af02 | |
parent | 133b34bb52e9109bc4f392b50bd0a9d55b283b31 (diff) | |
parent | d9bee0e3da28316364c4965f1c436e41811ae26a (diff) | |
download | tracker-fc21da4d950cbd277575191457987ef2c3c1dbe0.tar.gz |
Merge branch 'sam/functional-test-60x-fixes'
-rwxr-xr-x | tests/functional-tests/600-applications-camera.py | 249 | ||||
-rwxr-xr-x | tests/functional-tests/601-applications-sync.py | 20 |
2 files changed, 122 insertions, 147 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) diff --git a/tests/functional-tests/601-applications-sync.py b/tests/functional-tests/601-applications-sync.py index 26dad9558..c3747c62d 100755 --- a/tests/functional-tests/601-applications-sync.py +++ b/tests/functional-tests/601-applications-sync.py @@ -47,6 +47,19 @@ class TrackerSyncApplicationTests (CommonTrackerApplicationTest): 2. Write the file 3. Wait for miner-fs to index it 4. Ensure no duplicates are found + + During stage 3 you should see the following error from the FS miner, if + viewing its logs: + + (tracker-miner-fs:16008): Tracker-CRITICAL **: (Sparql buffer) + Error in task 0 of the array-update: UNIQUE constraint failed: + nie:DataObject.nie:url (strerror of errno ...) + + (tracker-miner-fs:16008): Tracker-CRITICAL **: Could not execute + sparql: UNIQUE constraint failed: nie:DataObject.nie:url + (strerror of errno ...) + + This is because the test already inserted the resource in the store. """ origin_filepath = os.path.join (self.get_data_dir (), self.get_test_music ()) @@ -73,7 +86,8 @@ class TrackerSyncApplicationTests (CommonTrackerApplicationTest): nfo:averageAudioBitrate '32000' ; nfo:genre 'Pop' ; nfo:isContentEncrypted 'false' ; - nie:title 'Simply Juvenile' + nie:title 'Simply Juvenile' ; + nie:isStoredAs _:x } INSERT { <urn:album:SinCos> a nmm:MusicAlbum; @@ -87,15 +101,19 @@ class TrackerSyncApplicationTests (CommonTrackerApplicationTest): self.tracker.update (insert) self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1) + resource_id = self.tracker.get_resource_id(dest_fileuri) + # Copy the image to the dest path self.slowcopy_file (origin_filepath, dest_filepath) assert os.path.exists (dest_filepath) self.tracker.await_resource_inserted ('nmm:MusicPiece', url=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.tracker.await_resource_deleted (resource_id) self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0) if __name__ == "__main__": |