Logo Search packages:      
Sourcecode: zeitgeist-extensions version File versions  Download package

_tests.py

# -.- coding: utf-8 -.-

# Zeitgeist FTS Extension Test Harness
#
# Copyright © 2010 Canonical Ltd
#
# This program 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 3 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author:
#         Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
#

import os, sys
if not os.getenv("ZEITGEIST_FTS_TESTS"):
      print >> sys.stderr, " ** Please only run the Zeitgeist FTS test via the test.sh script"
      raise SystemExit(1)

import dbus
from zeitgeist.client import ZeitgeistDBusInterface
from zeitgeist.datamodel import Event, Subject, TimeRange, ResultType, Interpretation, Manifestation

_bus = dbus.SessionBus()
_fts = _bus.get_object('org.gnome.zeitgeist.Engine',
                      '/org/gnome/zeitgeist/index/activity')
fts = dbus.Interface(_fts, 'org.gnome.zeitgeist.Index')
client = ZeitgeistDBusInterface()
result_type_relevancy=100

ev1 = Event.new_for_values(actor="application://firefox.desktop",
                           subject_interpretation=Interpretation.RASTER_IMAGE,
                           subject_manifestation=Manifestation.REMOTE_DATA_OBJECT,
                           subject_uri="http://example.com/image.jpg",
                           subject_text="text")
ev2 = Event.new_for_values(actor="application://firefox.desktop",
                           subject_interpretation=Interpretation.WEBSITE,
                           subject_manifestation=Manifestation.REMOTE_DATA_OBJECT,
                           subject_uri="http://example.com/I%20Love%Wikis", # %20 is white space
                           subject_text=u"Example.com Wiki Page. Kanji is awesome 漢字")
ids = client.InsertEvents([ev1, ev2])

# Searching, unfiltered, for 'text' should give us our single event
results, count = fts.Search('text', TimeRange.always(), [],
                            0, 10, result_type_relevancy)
results = map(Event, results)
assert len(results) == 1, "Expected 1 result. Found %s" % len(results)
assert len(results[0].subjects) == 1, "Expected 1 subject. Found %s" % len(results[0].subjects)
assert results[0].subjects[0].interpretation == Interpretation.RASTER_IMAGE, results[0].interpretation
assert results[0].subjects[0].uri == "http://example.com/image.jpg", results[0].subjects[0].uri
assert count == 1, "Expected Search() method to return a count of 1. Found %s" % count

# Searching for 'text' but filtering on DOCUMENTs should give 0 results
template = Event.new_for_values(subject_interpretation=Interpretation.DOCUMENT)
results, count = fts.Search('text', TimeRange.always(), [template],
                            0, 10, result_type_relevancy)
results = map(Event, results)
assert len(results) == 0, len(results)
assert count == 0, count

# Searching for 'text' and filtering on IMAGEs should still give 1 result
template = Event.new_for_values(subject_interpretation=Interpretation.IMAGE)
results, count = fts.Search('text', TimeRange.always(), [template],
                            0, 10, result_type_relevancy)
results = map(Event, results)
assert len(results) == 1, len(results)
assert len(results[0].subjects) == 1, len(results[0].subjects)
assert results[0].subjects[0].interpretation == Interpretation.RASTER_IMAGE, results[0].interpretation
assert results[0].subjects[0].uri == "http://example.com/image.jpg", results[0].subjects[0].uri
assert count == 1, count

# Check that negation works
template = Event.new_for_values(subject_interpretation="!"+Interpretation.IMAGE)
results, count = fts.Search('text', TimeRange.always(), [template],
                            0, 10, result_type_relevancy)
results = map(Event, results)
assert len(results) == 0, len(results)

# Check%20that%20URL%20escaping%20works
results, count = fts.Search('love', TimeRange.always(), [],
                            0, 10, result_type_relevancy)
results = map(Event, results)
assert len(results) == 1, "Expected 1 result, found %s" % len(results)
assert len(results[0].subjects) == 1, len(results[0].subjects)
assert results[0].subjects[0].interpretation == Interpretation.WEBSITE, results[0].interpretation
assert results[0].subjects[0].uri == "http://example.com/I%20Love%Wikis", results[0].subjects[0].uri

# Check that CJK support is in place
results, count = fts.Search(u"漢*", TimeRange.always(), [],
                            0, 10, result_type_relevancy)
results = map(Event, results)
assert len(results) == 1, "Expected 1 result, found %s" % len(results)
assert len(results[0].subjects) == 1, len(results[0].subjects)
assert results[0].subjects[0].interpretation == Interpretation.WEBSITE, results[0].interpretation
assert u"漢字" in results[0].subjects[0].text, results[0].subjects[0].uri




Generated by  Doxygen 1.6.0   Back to index