~kamstrup/zeitgeist/query-expansion

1233.1.4 by "Mikkel Kamstrup Erlandsen"
Blacklisting DBus interface actually working, and two test cases are running.
1
#!/usr/bin/python
2
# -.- coding: utf-8 -.-
3
4
# Update python path to use local zeitgeist module
5
import sys
6
import os
7
import unittest
8
import dbus
9
10
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
1307.1.1 by Siegfried-Angel Gevatter Pujals
Add a get_extension method to client.ZeitgeistDBusInterface to easily access interfaces
11
from zeitgeist.client import ZeitgeistDBusInterface
1233.1.4 by "Mikkel Kamstrup Erlandsen"
Blacklisting DBus interface actually working, and two test cases are running.
12
from zeitgeist.datamodel import *
13
from testutils import RemoteTestCase
14
15
class BlacklistTest(RemoteTestCase):
16
	
17
	def __init__(self, methodName):
18
		super(BlacklistTest, self).__init__(methodName)
19
		self.blacklist = None
20
	
21
	def setUp(self):
22
		# We set up the connection lazily in order to wait for the
23
		# engine to come up
24
		super(BlacklistTest, self).setUp()
25
		obj = dbus.SessionBus().get_object("org.gnome.zeitgeist.Engine",
1307.1.1 by Siegfried-Angel Gevatter Pujals
Add a get_extension method to client.ZeitgeistDBusInterface to easily access interfaces
26
			"/org/gnome/zeitgeist/blacklist")
1233.1.4 by "Mikkel Kamstrup Erlandsen"
Blacklisting DBus interface actually working, and two test cases are running.
27
		self.blacklist = dbus.Interface(obj, "org.gnome.zeitgeist.Blacklist")
28
	
29
	def testClear(self):
30
		self.blacklist.SetBlacklist([])
31
		empty = self.blacklist.GetBlacklist()
32
		self.assertEquals(empty, [])
33
		
34
	def testSetOne(self):
1322.1.103 by Mikkel Kamstrup Erlandsen
Change symbol names from CamelCase to CAMEL_CASE. This improves backwards compa of the API. The conversion is done at compile time
35
		orig = Event.new_for_values(interpretation=Interpretation.ACCESS_EVENT,
1233.1.4 by "Mikkel Kamstrup Erlandsen"
Blacklisting DBus interface actually working, and two test cases are running.
36
		                            subject_uri="http://nothingtoseehere.gov")
37
		self.blacklist.SetBlacklist([orig])
38
		result = map(Event, self.blacklist.GetBlacklist())
39
		
40
		self.assertEquals(len(result), 1)
41
		result = result[0]
42
		self.assertEquals(result.manifestation, "")
1322.1.103 by Mikkel Kamstrup Erlandsen
Change symbol names from CamelCase to CAMEL_CASE. This improves backwards compa of the API. The conversion is done at compile time
43
		self.assertEquals(result.interpretation, Interpretation.ACCESS_EVENT)
1233.1.4 by "Mikkel Kamstrup Erlandsen"
Blacklisting DBus interface actually working, and two test cases are running.
44
		self.assertEquals(len(result.subjects), 1)
45
		self.assertEquals(result.subjects[0].uri, "http://nothingtoseehere.gov")
46
		self.assertEquals(result.subjects[0].interpretation, "")
1233.1.11 by "Mikkel Kamstrup Erlandsen"
Add a test to the blacklist extension to check that events are indeed filtered/let through correctly
47
	
48
	def testApplyBlacklist(self):
49
		self.testSetOne()
50
		ev = Event()
1322.1.103 by Mikkel Kamstrup Erlandsen
Change symbol names from CamelCase to CAMEL_CASE. This improves backwards compa of the API. The conversion is done at compile time
51
		ev.interpretation = Interpretation.ACCESS_EVENT
52
		ev.manifestation = Manifestation.USER_ACTIVITY
1233.1.11 by "Mikkel Kamstrup Erlandsen"
Add a test to the blacklist extension to check that events are indeed filtered/let through correctly
53
		ev.actor = "app.//foo.desktop"
54
		subj = ev.append_subject()
55
		subj.uri = "http://nothingtoseehere.gov"
56
		inserted_ids = self.insertEventsAndWait([ev])
57
		self.assertEquals(1, len(inserted_ids))
58
		self.assertEquals(0, inserted_ids[0])
1233.1.4 by "Mikkel Kamstrup Erlandsen"
Blacklisting DBus interface actually working, and two test cases are running.
59
		
1233.1.11 by "Mikkel Kamstrup Erlandsen"
Add a test to the blacklist extension to check that events are indeed filtered/let through correctly
60
		# Now change the event to pass the blacklist
61
		subj.uri = "htpp://totallyvaliduri.com"
62
		inserted_ids = self.insertEventsAndWait([ev])
63
		self.assertEquals(1, len(inserted_ids))
64
		self.assertTrue(0 != inserted_ids[0])
1251 by Siegfried-Angel Gevatter Pujals
Merge with lp:~kamstrup/zeitgeist/blacklist
65
1307.1.1 by Siegfried-Angel Gevatter Pujals
Add a get_extension method to client.ZeitgeistDBusInterface to easily access interfaces
66
	def testBlacklistUsingClientDBusInterface(self):
67
		"""
68
		Ensure that get_extension() from client.py method works correctly.
69
		"""
70
		
71
		del self.blacklist
72
		iface = ZeitgeistDBusInterface()
73
		blacklist = iface.get_extension("Blacklist", "blacklist")
74
		blacklist.SetBlacklist([])
75
		empty = blacklist.GetBlacklist()
76
		self.assertEquals(empty, [])
77
1233.1.4 by "Mikkel Kamstrup Erlandsen"
Blacklisting DBus interface actually working, and two test cases are running.
78
if __name__ == "__main__":
79
	unittest.main()