← Back to team overview

zeitgeist team mailing list archive

[Branch ~zeitgeist/zeitgeist/bluebird] Rev 265: Add test cases for events with multiple subjects and FindEvents (re DISTINCT)

 

------------------------------------------------------------
revno: 265
committer: Siegfried-Angel Gevatter Pujals <siegfried@xxxxxxxxxxxx>
branch nick: bluebird
timestamp: Sun 2011-09-18 14:54:07 +0200
message:
  Add test cases for events with multiple subjects and FindEvents (re DISTINCT)
modified:
  src/engine.vala
  test/dbus/remote-test.py
  test/dbus/testutils.py


--
lp:~zeitgeist/zeitgeist/bluebird
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird

Your team Zeitgeist Framework Team is subscribed to branch lp:~zeitgeist/zeitgeist/bluebird.
To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'src/engine.vala'
--- src/engine.vala	2011-09-18 12:22:59 +0000
+++ src/engine.vala	2011-09-18 12:54:07 +0000
@@ -206,6 +206,8 @@
         //    return new uint32[0];
 
         string sql;
+        // FIXME: this doesn't make sense (and doesn't help for
+        // FindEventIds). find another fix
         if (distinct)
             sql = "SELECT DISTINCT id FROM event_view ";
         else
@@ -342,7 +344,6 @@
         {
             var id = (uint32) uint64.parse(
                 stmt.column_text (EventViewRows.ID));
-            //if (!(id in event_ids))
             event_ids += id;
         }
         if (rc != Sqlite.DONE)

=== modified file 'test/dbus/remote-test.py'
--- test/dbus/remote-test.py	2011-09-18 12:10:22 +0000
+++ test/dbus/remote-test.py	2011-09-18 12:54:07 +0000
@@ -149,6 +149,27 @@
 						num_events=10)
 		self.assertEquals(1, len(ids))
 
+	def testFindEventsWithMultipleSubjects(self):
+		events = parse_events("test/data/three_events.js")
+		ids = self.insertEventsAndWait(events)
+
+		results = self.findEventsForTemplatesAndWait([], num_events=5)
+		self.assertEquals(3, len(results))
+
+		self.assertEquals(len(results[0].get_subjects()), 2)
+		self.assertEquals(len(results[1].get_subjects()), 1)
+		self.assertEquals(len(results[1].get_subjects()), 1)
+
+	def testFindEventsLimitWhenDuplicates(self):
+		events = parse_events("test/data/three_events.js")
+		ids = self.insertEventsAndWait(events)
+
+		# This test makes sure that we get the requested number of events
+		# when some of them have multiple subjects (so more than one row
+		# with the same event id).
+		results = self.findEventsForTemplatesAndWait([], num_events=3)
+		self.assertEquals(3, len(results))
+
 class ZeitgeistRemoteFindEventIdsTest(testutils.RemoteTestCase):
 	"""
 	Test cases with basic tests for FindEventIds.

=== modified file 'test/dbus/testutils.py'
--- test/dbus/testutils.py	2011-09-07 20:48:27 +0000
+++ test/dbus/testutils.py	2011-09-18 12:54:07 +0000
@@ -252,6 +252,22 @@
 		mainloop.run()
 		return result
 	
+	def findEventsForTemplatesAndWait(self, event_templates, **kwargs):
+		"""
+		Execute ZeitgeistClient.find_events_for_templates in a blocking manner.
+		"""
+		mainloop = self.create_mainloop()
+		result = []
+		
+		def collect_events_and_quit(events):
+			result.extend(events)
+			mainloop.quit()
+		
+		self.client.find_events_for_templates(
+			event_templates, collect_events_and_quit, **kwargs)
+		mainloop.run()
+		return result
+
 	def findEventsForValuesAndWait(self, *args, **kwargs):
 		"""
 		Execute ZeitgeistClient.find_events_for_value in a blocking manner.