summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIvan Frade <ivan.frade@nokia.com>2009-11-05 18:02:03 +0200
committerIvan Frade <ivan.frade@nokia.com>2009-11-05 18:02:03 +0200
commit463caa7134823fcfbf9a562fdda33cc26004f1c7 (patch)
treee49f29495e32c8d3eae07ecca5d39415ccc93896 /tests
parent7bf61a1cf22fba50892e1977af5c92cf932a4471 (diff)
downloadtracker-463caa7134823fcfbf9a562fdda33cc26004f1c7.tar.gz
Functional test for fts:rank
Diffstat (limited to 'tests')
-rw-r--r--tests/functional-tests/03-fts-functions.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/functional-tests/03-fts-functions.py b/tests/functional-tests/03-fts-functions.py
new file mode 100644
index 000000000..e5d69c771
--- /dev/null
+++ b/tests/functional-tests/03-fts-functions.py
@@ -0,0 +1,87 @@
+#!/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 dbus
+import unittest
+import random
+
+TRACKER = 'org.freedesktop.Tracker1'
+TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
+RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
+
+class TestFTSFunctions (unittest.TestCase):
+
+ def setUp (self):
+ bus = dbus.SessionBus ()
+ tracker = bus.get_object (TRACKER, TRACKER_OBJ)
+ self.resources = dbus.Interface (tracker,
+ dbus_interface=RESOURCES_IFACE);
+
+
+ def test_fts_rank (self):
+ """
+ 1. Insert a Contact1 with 'abcdefxyz' as fullname and nickname
+ 2. Insert a Contact2 with 'abcdefxyz' as fullname
+ 3. Query sorting by fts:rank
+ EXPECTED: Contact 1 as first result
+ 4. Remove the created resources
+ """
+ insert_sparql = """
+ INSERT {
+ <contact://test/fts-function/rank/1> a nco:PersonContact ;
+ nco:fullname 'abcdefxyz' ;
+ nco:nickname 'abcdefxyz' .
+
+ <contact://test/fts-function/rank/2> a nco:PersonContact ;
+ nco:fullname 'abcdefxyz' .
+
+ <contact://test/fts-function/rank/3> a nco:PersonContact ;
+ nco:fullname 'abcdefxyz' ;
+ nco:nickname 'abcdefxyz abcdefxyz' .
+ }
+ """
+ self.resources.SparqlUpdate (insert_sparql)
+
+ query = """
+ SELECT ?contact WHERE {
+ ?contact a nco:PersonContact ;
+ fts:match 'abcdefxyz*' .
+ } ORDER BY DESC (fts:rank(?contact))
+ """
+ results = self.resources.SparqlQuery (query)
+
+ self.assertEquals (len(results), 3)
+ self.assertEquals (results[0][0], "contact://test/fts-function/rank/3")
+ self.assertEquals (results[1][0], "contact://test/fts-function/rank/1")
+ self.assertEquals (results[2][0], "contact://test/fts-function/rank/2")
+
+ delete_sparql = """
+ DELETE {
+ <contact://test/fts-function/rank/1> a rdf:Resource .
+ <contact://test/fts-function/rank/2> a rdf:Resource .
+ }
+ """
+
+
+
+
+if __name__ == '__main__':
+ unittest.main()