def testResultTypesOldestActorBug641968(self): events = [ new_event(timestamp=1, actor="boo", subject_uri="tmp/boo"), new_event(timestamp=2, actor="boo", subject_uri="home/boo"), new_event(timestamp=3, actor="bar", subject_uri="tmp/boo"), new_event(timestamp=4, actor="baz", subject_uri="tmp/boo"), ] self.insertEventsAndWait(events) # Get the least recent actors ids = self.findEventIdsAndWait([], num_events=0, result_type=ResultType.OldestActor) events = self.getEventsAndWait(ids) self.assertEqual(list(ids), [1, 3, 4]) # Get the least recent actors for "home/boo" template = Event.new_for_values(subject_uri="home/boo") ids = self.findEventIdsAndWait([template], num_events=0, result_type=ResultType.OldestActor) self.assertEqual(list(ids), [2]) # Let's also try the same with MostRecentActor... Although there # should be no problem here. template = Event.new_for_values(subject_uri="home/boo") ids = self.findEventIdsAndWait([template], num_events=0, result_type=ResultType.OldestActor) self.assertEqual(list(ids), [2])
def testFindStorage(self): events = [ new_event(timestamp=1000, subject_storage="sometext"), new_event(timestamp=2000, subject_storage="anotherplace") ] ids_in = self.insertEventsAndWait(events) template = Event.new_for_values(subject_storage="sometext") results = self.findEventIdsAndWait([template,], num_events=10, result_type=ResultType.MostRecentEvents ) self.assertEquals(1, len(results))
def testFindStorage(self): events = [ new_event(timestamp=1000, subject_storage="sometext"), new_event(timestamp=2000, subject_storage="anotherplace") ] ids_in = self.insertEventsAndWait(events) template = Event.new_for_values(subject_storage="sometext") results = self.findEventIdsAndWait([template,], num_events=10, result_type=ResultType.MostRecentEvents ) self.assertEqual(1, len(results))
def testResultTypesLeastRecentActor2(self): # The same test as before, but this time with fewer events so that # it is actually understandable. events = [ new_event(timestamp=1, actor="gedit", subject_uri="oldFile"), new_event(timestamp=2, actor="banshee", subject_uri="oldMusic"), new_event(timestamp=3, actor="banshee", subject_uri="newMusic"), new_event(timestamp=4, actor="gedit", subject_uri="newFile"), ] self.insertEventsAndWait(events) ids = self.findEventIdsAndWait([], num_events=0, result_type=ResultType.LeastRecentActor) recv_events = self.getEventsAndWait(ids) self.assertEqual([e.timestamp for e in recv_events], ['3', '4'])
def testFindEventIdsWithMultipleSubjects(self): subj1 = Subject.new_for_values(uri="file:///tmp/foo.txt") subj2 = Subject.new_for_values(uri="file:///tmp/loo.txt") event = new_event(subjects=[subj1, subj2]) orig_ids = self.insertEventsAndWait([event]) result_ids = self.findEventIdsAndWait([Event()], num_events=0, result_type=ResultType.LeastRecentEvents) self.assertEquals(orig_ids, list(result_ids))
def testFindEventIdsWithMultipleSubjects(self): subj1 = Subject.new_for_values(uri="file:///tmp/foo.txt") subj2 = Subject.new_for_values(uri="file:///tmp/loo.txt") event = new_event(subjects=[subj1, subj2]) orig_ids = self.insertEventsAndWait([event]) result_ids = self.findEventIdsAndWait([Event()], num_events=0, result_type=ResultType.LeastRecentEvents) self.assertEqual(orig_ids, list(result_ids))
def testGetWithMultipleSubjects(self): subj1 = Subject.new_for_values(uri="file:///tmp/foo.txt") subj2 = Subject.new_for_values(uri="file:///tmp/loo.txt") event = new_event(subjects=[subj1, subj2]) result = self.insertEventsAndWait([event]) events = self.getEventsAndWait(result) self.assertEquals(2, len(events[0].subjects)) self.assertEquals("file:///tmp/foo.txt", events[0].subjects[0].uri) self.assertEquals("file:///tmp/loo.txt", events[0].subjects[1].uri)
def testGetWithMultipleSubjects(self): subj1 = Subject.new_for_values(uri="file:///tmp/foo.txt") subj2 = Subject.new_for_values(uri="file:///tmp/loo.txt") event = new_event(subjects=[subj1, subj2]) result = self.insertEventsAndWait([event]) events = self.getEventsAndWait(result) self.assertEqual(2, len(events[0].subjects)) self.assertEqual("file:///tmp/foo.txt", events[0].subjects[0].uri) self.assertEqual("file:///tmp/loo.txt", events[0].subjects[1].uri)
def testQueryByParent(self): ev = new_event(subject_interpretation=Interpretation.AUDIO) _ids = self.insertEventsAndWait([ev]) tmpl = Event.new_for_values(subject_interpretation=Interpretation.MEDIA) ids = self.findEventIdsAndWait([tmpl], num_events=10, result_type=ResultType.MostRecentEvents) self.assertEquals(1, len(ids)) self.assertEquals(_ids, list(ids))
def testQueryByParent(self): ev = new_event(subject_interpretation=Interpretation.AUDIO) _ids = self.insertEventsAndWait([ev]) tmpl = Event.new_for_values(subject_interpretation=Interpretation.MEDIA) ids = self.findEventIdsAndWait([tmpl], num_events=10, result_type=ResultType.MostRecentEvents) self.assertEqual(1, len(ids)) self.assertEqual(_ids, list(ids))
def _createEventOne(self): ev = new_event( interpretation=Interpretation.ACCESS_EVENT, subject_uri="file://sisisisisisi") ev.manifestation = Manifestation.USER_ACTIVITY if time.timezone < 0 : start_hour = 24 + int(time.timezone / 3600) else: start_hour = int(time.timezone / 3600) - 1 td = datetime.datetime.today() event_date = datetime.datetime(td.year, td.month, td.day, start_hour, 30) timestamp = calendar.timegm(event_date.timetuple()) ev.timestamp = timestamp * 1000 return ev, timestamp