[tracker/functional-tests-applications] functional tests: New tests for application operations



commit a4dde4a31974458a17d1371e95564dcc0246eeed
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Thu Jan 20 17:12:24 2011 +0100

    functional tests: New tests for application operations

 configure.ac                                       |    1 +
 tests/functional-tests/600-applications.py         |   97 ++++++++++++++++++++
 .../common/utils/applicationstest.py               |   97 ++++++++++++++++++++
 .../test-configurations/applications/Makefile.am   |    8 ++
 .../applications/tracker/tracker-miner-fs.cfg      |   57 ++++++++++++
 5 files changed, 260 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 34200d6..9536d23 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2100,6 +2100,7 @@ AC_CONFIG_FILES([
 	tests/functional-tests/test-configurations/Makefile
 	tests/functional-tests/test-configurations/miner-basic-ops/Makefile
 	tests/functional-tests/test-configurations/writeback/Makefile
+	tests/functional-tests/test-configurations/applications/Makefile
         tests/functional-tests/test-ontologies/Makefile
         tests/functional-tests/test-ontologies/basic/Makefile
         tests/functional-tests/test-ontologies/property-range-int-to-string/Makefile
diff --git a/tests/functional-tests/600-applications.py b/tests/functional-tests/600-applications.py
new file mode 100755
index 0000000..e9bc31c
--- /dev/null
+++ b/tests/functional-tests/600-applications.py
@@ -0,0 +1,97 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2011, Nokia Corporation <ivan frade nokia com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+
+"""
+Tests trying to simulate the behaviour of applications working with tracker
+"""
+
+import sys,os,dbus
+import unittest
+import time
+import random
+import string
+import datetime
+import shutil
+
+from common.utils import configuration as cfg
+import unittest2 as ut
+from common.utils.applicationstest import CommonTrackerApplicationTest as CommonTrackerApplicationTest, APPLICATIONS_TMP_DIR, path, uri, slowcopy
+
+TEST_IMAGE = "test-image-1.jpg"
+SRC_IMAGE_DIR = os.path.join (cfg.DATADIR,
+                              "tracker-tests",
+                              "data",
+                              "Images")
+SRC_IMAGE_PATH = os.path.join (SRC_IMAGE_DIR, TEST_IMAGE)
+
+
+class TrackerApplicationTests (CommonTrackerApplicationTest):
+
+    def __get_urn_count_by_url (self, url):
+        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)
+
+
+    def test_camera_insert_01 (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_insert_01/" + str(random.randint (0,100))
+        filepath = path (TEST_IMAGE)
+        fileuri = uri (TEST_IMAGE)
+
+        print "Storing new image in '%s'..." % (filepath)
+
+        # Insert new resource in the store
+        insert = """
+        INSERT { <%s> a         nie:InformationElement, nie:DataObject, nfo:Image ;
+                      nie:title \"test camera insert 01\" ;
+                      nie:url   \"%s\" }
+        """ % (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.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 ()
+        self.assertEquals (self.__get_urn_count_by_url (fileuri), 0)
+
+if __name__ == "__main__":
+	ut.main()
+
+
diff --git a/tests/functional-tests/common/utils/applicationstest.py b/tests/functional-tests/common/utils/applicationstest.py
new file mode 100644
index 0000000..39041b8
--- /dev/null
+++ b/tests/functional-tests/common/utils/applicationstest.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2010, Nokia <ivan frade nokia com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+from common.utils import configuration as cfg
+from common.utils.system import TrackerSystemAbstraction
+from common.utils.helpers import StoreHelper
+import unittest2 as ut
+
+import shutil
+import os
+import time
+
+APPLICATIONS_TMP_DIR = os.path.join (cfg.TEST_TMP_DIR, "test-applications-monitored")
+
+def path (filename):
+    return os.path.join (APPLICATIONS_TMP_DIR, filename)
+
+def uri (filename):
+    return "file://" + os.path.join (APPLICATIONS_TMP_DIR, filename)
+
+# Being rate defined in amount of BYTES per 100ms
+def slowcopy (src, dest, rate):
+    fsrc = open (src, 'rb')
+    fdest = open (dest, 'wb')
+
+    buffer = fsrc.read (rate)
+    while (buffer != ""):
+        print "Slow write..."
+        fdest.write (buffer)
+        time.sleep (0.1)
+        buffer = fsrc.read (rate)
+
+    fsrc.close ()
+    fdest.close ()
+
+
+class CommonTrackerApplicationTest (ut.TestCase):
+
+    @classmethod
+    def setUpClass (self):
+        # Create temp directory to monitor
+        if (os.path.exists (APPLICATIONS_TMP_DIR)):
+            shutil.rmtree (APPLICATIONS_TMP_DIR)
+        os.makedirs (APPLICATIONS_TMP_DIR)
+
+        self.system = TrackerSystemAbstraction ()
+
+        if (os.path.exists (os.path.join (os.getcwd(),
+                                          "test-configurations",
+                                          "applications"))):
+            # Use local directory if available
+            confdir = os.path.join (os.getcwd(),
+                                    "test-configurations",
+                                    "applications")
+        else:
+            confdir = os.path.join (os.getcwd(),
+                                    "test-configurations",
+                                    "applications")
+            confdir = os.path.join (cfg.DATADIR,
+                                    "tracker-tests",
+                                    "test-configurations",
+                                    "applications")
+
+        self.system.tracker_miner_fs_testing_start (confdir)
+
+        # Returns when ready
+        self.tracker = StoreHelper ()
+        self.tracker.wait ()
+
+        print "Ready to go!"
+        print "    Using configuration dir at '%s'..." % (confdir)
+        print "    Using temp dir at '%s'..." % (APPLICATIONS_TMP_DIR)
+
+    @classmethod
+    def tearDownClass (self):
+        #print "Stopping the daemon in test mode (Doing nothing now)"
+        self.system.tracker_miner_fs_testing_stop ()
+
+        # Remove monitored directory
+        if (os.path.exists (APPLICATIONS_TMP_DIR)):
+            shutil.rmtree (APPLICATIONS_TMP_DIR)
diff --git a/tests/functional-tests/test-configurations/applications/Makefile.am b/tests/functional-tests/test-configurations/applications/Makefile.am
new file mode 100644
index 0000000..4953de4
--- /dev/null
+++ b/tests/functional-tests/test-configurations/applications/Makefile.am
@@ -0,0 +1,8 @@
+include $(top_srcdir)/Makefile.decl
+
+conftestdir = $(datadir)/tracker-tests/test-configurations/applications/tracker
+
+conftest_DATA =  \
+	tracker/tracker-miner-fs.cfg
+
+EXTRA_DIST = $(conftest_DATA)
diff --git a/tests/functional-tests/test-configurations/applications/tracker/tracker-miner-fs.cfg b/tests/functional-tests/test-configurations/applications/tracker/tracker-miner-fs.cfg
new file mode 100644
index 0000000..67bb7ae
--- /dev/null
+++ b/tests/functional-tests/test-configurations/applications/tracker/tracker-miner-fs.cfg
@@ -0,0 +1,57 @@
+
+[General]
+# Log verbosity (0=errors, 1=minimal, 2=detailed, 3=debug)
+Verbosity=0
+# Time in seconds before crawling filesystem (0->1000)
+InitialSleep=15
+
+[Monitors]
+# Set to false to completely disable any monitoring
+EnableMonitors=true
+# Time in seconds between same events to prevent flooding (0->1000)
+ScanTimeout=0
+# Time in seconds for events to be cached (0->1000)
+CacheTimeout=60
+
+[Indexing]
+# Sets the indexing speed (0->20, where 20=slowest speed)
+Throttle=0
+# Set to true to index while running on battery
+IndexOnBattery=false
+# Set to true to index while running on battery for the first time only
+IndexOnBatteryFirstTime=true
+# Set to true to enable traversing mounted directories on other file systems
+# (this excludes removable devices)
+IndexMountedDirectories=true
+# Set to true to enable traversing mounted directories for removable devices
+# (this includes optical discs)
+IndexRemovableMedia=false
+# Set to true to enable traversing CDs, DVDs, and generally optical media
+# (if removable devices are not indexed, optical discs won't be either)
+IndexOpticalDiscs=false
+# Pause indexer when disk space is <= this value
+# (0->100, value is in % of $HOME file system, -1=disable pausing)
+LowDiskSpaceLimit=1
+# List of directories to crawl recursively for indexing (separator=;)
+# Special values include: (see /etc/xdg/user-dirs.defaults & $HOME/.config/user-dirs.default)
+#   &DESKTOP
+#   &DOCUMENTS
+#   &DOWNLOAD
+#   &MUSIC
+#   &PICTURES
+#   &PUBLIC_SHARE
+#   &TEMPLATES
+#   &VIDEOS
+# If $HOME is the default below, it is because $HOME/.config/user-dirs.default was missing.
+IndexRecursiveDirectories=$HOME/.tracker-tests/test-applications-monitored;
+# List of directories to index but not sub-directories for changes (separator=;)
+# Special values used for IndexRecursiveDirectories can also be used here
+IndexSingleDirectories=
+# List of directories to NOT crawl for indexing (separator=;)
+IgnoredDirectories=po;CVS;core-dumps;lost+found;
+# List of directories to NOT crawl for indexing based on child files (separator=;)
+IgnoredDirectoriesWithContent=backup.metadata;
+# List of files to NOT index (separator=;)
+IgnoredFiles=*~;*.o;*.la;*.lo;*.loT;*.in;*.csproj;*.m4;*.rej;*.gmo;*.orig;*.pc;*.omf;*.aux;*.tmp;*.po;*.vmdk;*.vm*;*.nvram;*.part;*.rcore;lzo;autom4te;conftest;confstat;Makefile;SCCS;litmain.sh;libtool;config.status;confdefs.h;
+# Interval in days to check the filesystem is up to date in the database. If set to 0, crawling always occurs on startup, if -1 crawling is disabled entirely. Maximum is 365.
+CrawlingInterval=0



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