[tracker/miner-web-review: 30/74] Add functional test cases for virtual files
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-web-review: 30/74] Add functional test cases for virtual files
- Date: Mon, 1 Mar 2010 12:33:24 +0000 (UTC)
commit 4572582351166d422fe71c1fc4abdc5e297fb47d
Author: Amit Jain <ext-amit 1 jain nokia com>
Date: Thu Feb 25 11:14:36 2010 +0100
Add functional test cases for virtual files
configure.ac | 1 +
tests/functional-tests/Makefile.am | 3 +-
tests/functional-tests/data/Images/Makefile.am | 10 ++
.../functional-tests/data/Images/test-image-1.jpg | Bin 0 -> 4752 bytes
tests/functional-tests/data/Makefile.am | 3 +-
tests/functional-tests/virtual-files-tc.py | 158 ++++++++++++++++++++
6 files changed, 173 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8289c32..e817d48 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1671,6 +1671,7 @@ AC_CONFIG_FILES([
tests/functional-tests/Makefile
tests/functional-tests/data/Makefile
tests/functional-tests/data/Music/Makefile
+ tests/functional-tests/data/Images/Makefile
tests/Makefile
tests/tracker-miner-fs/Makefile
tests/tracker-extract/Makefile
diff --git a/tests/functional-tests/Makefile.am b/tests/functional-tests/Makefile.am
index e800eda..ecc0baa 100644
--- a/tests/functional-tests/Makefile.am
+++ b/tests/functional-tests/Makefile.am
@@ -14,7 +14,8 @@ config_DATA = \
metadata_extraction_tc.py \
writeback-tc.py \
04-group-concat.py \
- 05-coalesce.py
+ 05-coalesce.py \
+ virtual-files-tc.py
EXTRA_DIST = $(config_DATA)
endif
diff --git a/tests/functional-tests/data/Images/Makefile.am b/tests/functional-tests/data/Images/Makefile.am
new file mode 100644
index 0000000..f6ec4bf
--- /dev/null
+++ b/tests/functional-tests/data/Images/Makefile.am
@@ -0,0 +1,10 @@
+include $(top_srcdir)/Makefile.decl
+
+if DIST_FUNCTIONAL_TESTS
+configdir = $(datadir)/tracker-tests/data/Images
+
+config_DATA = \
+ test-image-1.jpg
+
+EXTRA_DIST = $(config_DATA)
+endif
diff --git a/tests/functional-tests/data/Images/test-image-1.jpg b/tests/functional-tests/data/Images/test-image-1.jpg
new file mode 100644
index 0000000..42e61af
Binary files /dev/null and b/tests/functional-tests/data/Images/test-image-1.jpg differ
diff --git a/tests/functional-tests/data/Makefile.am b/tests/functional-tests/data/Makefile.am
index 968b094..4365c62 100644
--- a/tests/functional-tests/data/Makefile.am
+++ b/tests/functional-tests/data/Makefile.am
@@ -1,7 +1,8 @@
include $(top_srcdir)/Makefile.decl
SUBDIRS = \
- Music
+ Music \
+ Images
if DIST_FUNCTIONAL_TESTS
configdir = $(datadir)/tracker-tests/data
diff --git a/tests/functional-tests/virtual-files-tc.py b/tests/functional-tests/virtual-files-tc.py
new file mode 100644
index 0000000..8b508be
--- /dev/null
+++ b/tests/functional-tests/virtual-files-tc.py
@@ -0,0 +1,158 @@
+#!/usr/bin/env python2.5
+# Copyright (C) 2008, Nokia (urho konttori nokia com)
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+
+import sys,os,dbus
+import unittest
+import time
+import random
+import configuration
+import commands
+import signal
+import string
+
+TRACKER = "org.freedesktop.Tracker1"
+TRACKER_OBJ = "/org/freedesktop/Tracker1/Resources"
+RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
+MINER="org.freedesktop.Tracker1.Miner.Files"
+MINER_OBJ="/org/freedesktop/Tracker1/Miner/Files"
+MINER_IFACE="org.freedesktop.Tracker1.Miner"
+
+
+target = configuration.check_target()
+if target == '2' :
+ dir_path = os.environ['HOME'] + '/MyDocs'
+ dir_path_parent = os.environ['HOME']
+else :
+ dir_path = sys.prefix + '/share/tracker-tests/data'
+ dir_path_parent = sys.prefix + '/share/tracker-tests'
+print dir_path
+
+""" copy the test data to proper location. """
+def copy_file():
+
+ src = sys.prefix + '/share/tracker-tests/data/Images/test-image-1.jpg'
+ dest = dir_path
+ print 'Copying '+src+' to '+dest
+ commands.getoutput('cp '+src+ ' '+dest)
+
+copy_file()
+
+class TestVirtualFiles (unittest.TestCase):
+ def setUp(self):
+ bus = dbus.SessionBus()
+ tracker = bus.get_object(TRACKER, TRACKER_OBJ)
+ self.resources = dbus.Interface (tracker, dbus_interface=RESOURCES_IFACE)
+ miner_obj= bus.get_object(MINER,MINER_OBJ)
+ self.miner=dbus.Interface (miner_obj,dbus_interface=MINER_IFACE)
+
+ def sparql_update(self,query):
+ return self.resources.SparqlUpdate(query)
+ def query(self,query):
+ return self.resources.SparqlQuery(query)
+ def ignore(self,uri):
+ return self.miner.IgnoreNextUpdate(uri)
+
+
+class virtual_files(TestVirtualFiles):
+
+ def test_Virttual_01(self):
+ """
+ Test if the update is ignored until the creation of the file is completed.
+ 1. Move the file to some other location.
+ 2. Create resource in tracker , by making instance of nie:DataObject.
+ 3. IgnoreNextUpdate on the files.
+ 4. Copy the original file to the present directory.
+ 5. Query for the title of the file.
+ """
+
+ test_file = 'test-image-1.jpg'
+ file= dir_path + '/' + test_file
+ uri='file://' + file
+ print uri
+
+ time.sleep(10)
+ commands.getoutput('mv ' + file + ' ' + dir_path_parent)
+
+ Insert = """
+ INSERT { _:x a nfo:Image, nie:DataObject ;
+ nie:url <%s> ;
+ nie:title 'title_test'. }""" %(uri)
+ print Insert
+
+ self.sparql_update(Insert)
+ time.sleep(10)
+
+ self.miner.IgnoreNextUpdate([uri])
+
+ commands.getoutput('cp ' + dir_path_parent + '/'+ test_file + ' ' + dir_path)
+
+ QUERY = """
+ SELECT ?t WHERE { ?file a nfo:FileDataObject ;
+ nie:title ?t ;
+ nie:url <%s> .}
+ """ %(uri)
+ print QUERY
+
+ result=self.query(QUERY)
+ print result
+
+ self.assert_(result[0][0].find('title_test')!=-1 , "File is not ignored")
+
+
+ def test_Virtual_02(self):
+
+ """
+ 1) Insert in tracker a "virtual" file (can be a text file) tagged as Favourite
+ 2) Start writing the file (with some sleep to make the process long)
+ 3) Close the file, wait for tracker to discover it
+ 4) Check the metadata of the file AND that the tag (favourite) is there
+ """
+
+ test_file = 'testfilename.txt'
+ file= dir_path + '/' + test_file
+ url='file://' + file
+ print url
+
+ insert="""
+ INSERT { _:x a nfo:Image, nie:DataObject ; \
+ nie:url <%s> ; \
+ nie:title 'title_test';
+ nao:hasTag [a nao:Tag ; nao:prefLabel "Favorite"] ;
+ nie:plainTextContent 'This is script to test virtual file support'.
+ }
+ """ %url
+ self.sparql_update(insert)
+
+ time.sleep(3)
+
+ QUERY="""
+ SELECT ?label ?content WHERE { ?file a nie:DataObject ;nao:hasTag[a nao:Tag ;nao:prefLabel ?label]; nie:url <%s> ;
+ nie:plainTextContent ?content.
+ }
+ """ %url
+
+ result=self.query(QUERY)
+
+ self.assert_(result[0][0].find('Favorite')!=-1 and result[1][1].find("This is script to test virtual file support")!=-1, "File is not monitored by tracker")
+
+
+
+if __name__ == "__main__":
+
+ unittest.main()
+
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]