2
# -.- coding: utf-8 -.-
6
# Copyright © 2011 Stefano Candori <stefano.candori@gmail.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Lesser General Public License as published by
10
# the Free Software Foundation, either version 2.1 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Lesser General Public License for more details.
18
# You should have received a copy of the GNU Lesser General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
# Update python path to use local zeitgeist module
31
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
32
from zeitgeist.client import ZeitgeistDBusInterface
33
from zeitgeist.datamodel import *
34
from testutils import RemoteTestCase, import_events
37
# EXPLANATION OF THE TEST:
38
# The test checks if the histogram extension works well despite the
39
# ***timezone's hell***.
40
# For example the extension, for an user in the GMT+2 timezone, should count
41
# an event inserted on the 2011/12/24 at 1:30 AM as belonging to the day 24.
42
# The problem is that in the engine the events are inserted as UTC-relative:
43
# for the example our event is inserted for the day 2011/12/23 at 23:30 UTC.
44
# The Histogram extension must revert this when collecting data, and this test
47
# ******************************************************************************
49
# In the test we create an event in the "borderline" time for the timezone and
50
# then we insert it in the engine as UCT-relative. After, we retrieve the data
51
# from the extension and finally we check that the event belong to the right day
54
class HistogramTest(RemoteTestCase):
56
def __init__(self, methodName):
57
super(HistogramTest, self).__init__(methodName)
61
# lazy import to get a chance to use the private bus
64
# We set up the connection lazily in order to wait for the
66
super(HistogramTest, self).setUp()
67
obj = dbus.SessionBus().get_object("org.gnome.zeitgeist.Engine",
68
"/org/gnome/zeitgeist/journal/activity")
69
self.histogram = dbus.Interface(obj, "org.gnome.zeitgeist.Histogram")
71
def _createEventOne(self):
72
ev = Event.new_for_values(interpretation=Interpretation.ACCESS_EVENT,
73
subject_uri="file://sisisisisisi")
74
ev.manifestation = Manifestation.USER_ACTIVITY
76
if time.timezone < 0 :
77
start_hour = 24 + int(time.timezone / 3600)
79
start_hour = int(time.timezone / 3600) - 1
81
td = datetime.datetime.today()
82
event_date = datetime.datetime(td.year, td.month, td.day, start_hour, 30)
83
timestamp = calendar.timegm(event_date.timetuple())
85
ev.timestamp = timestamp * 1000
89
def testGetHistogramData(self):
90
ev, ev_timestamp = self._createEventOne();
92
inserted_ids = self.insertEventsAndWait([ev])
93
self.assertEquals(1, len(inserted_ids))
95
h_data = self.histogram.GetHistogramData()
96
self.assertEquals(1, len(h_data))
98
h_day_timestamp = h_data[0][0]
100
#Check if the inserted event belong to the right day!
101
day_ev = datetime.date.fromtimestamp(ev_timestamp)
102
start_day = datetime.date.fromtimestamp(h_day_timestamp)
103
self.assertEquals(day_ev.day , start_day.day)
105
if __name__ == "__main__":