Merge lp:~zeitgeist/zeitgeist/bug580364 into lp:zeitgeist/0.1

Proposed by Seif Lotfy
Status: Merged
Merge reported by: Seif Lotfy
Merged at revision: not available
Proposed branch: lp:~zeitgeist/zeitgeist/bug580364
Merge into: lp:zeitgeist/0.1
Diff against target: 73 lines (+25/-20)
2 files modified
_zeitgeist/engine/main.py (+4/-6)
test/engine-test.py (+21/-14)
To merge this branch: bzr merge lp:~zeitgeist/zeitgeist/bug580364
Reviewer Review Type Date Requested Status
Markus Korn Needs Fixing
Mikkel Kamstrup Erlandsen Needs Fixing
Review via email: mp+34141@code.launchpad.net

Description of the change

I fixed bug 580364
now we support searching for storage templates

To post a comment you must log in.
Revision history for this message
Markus Korn (thekorn) wrote :

Sorry, big NACK from me.
It makes no sense to allow this kind of queries right now, as we have no ways to set the storage state implemented. This is why we decided to throw an exception.

review: Disapprove
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Well, I disagree with Markus :-) I think it makes perfect sense to include this - otherwise we have a chicken-and-egg problem.

In theory anyone could set the storage field upon item insertion. It just so happens that the DS we ship is not feature complete. On top of that, 3rd parties could provide their own storage monitor extension which update the storage table correctly (at the very least a networkmanager/connman extension is easy).

Regarding the code:

 1) It looks like testFindStorageNotExistant() is there twice?

 2) Docstrings in the unit tests are not right

 3) Apart from these small things it looks good to me

review: Needs Fixing
Revision history for this message
Markus Korn (thekorn) wrote :

Ok, I cave in, fix the things mentioned by Mikkel, run the testsuite and if everything goes well merge it into lp:zeitgeist (but please don't *bzr pull*)

review: Needs Fixing
Revision history for this message
Seif Lotfy (seif) wrote :

ok done :)

lp:~zeitgeist/zeitgeist/bug580364 updated
1562. By Seif Lotfy

fixed docstrings and removed duplicate test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_zeitgeist/engine/main.py'
2--- _zeitgeist/engine/main.py 2010-08-02 10:13:12 +0000
3+++ _zeitgeist/engine/main.py 2010-08-31 20:50:54 +0000
4@@ -220,12 +220,6 @@
5 subject_templates = [Subject(data) for data in template[1]]
6 else:
7 subject_templates = None
8- # first of all we need to check if the query is supported at all
9- # we do not support searching by storage field for now
10- # see LP: #580364
11- if subject_templates is not None:
12- if any(data[Subject.Storage] for data in subject_templates):
13- raise ValueError("zeitgeist does not support searching by 'storage' field")
14
15 subwhere = WhereClause(WhereClause.AND)
16
17@@ -292,6 +286,10 @@
18 if value:
19 value, negation, wildcard = parse_operators(Subject, getattr(Subject, key.title()), value)
20 subwhere.add_text_condition("subj_%s" %key, value, wildcard, negation)
21+
22+ if subject_template.storage:
23+ subwhere.add_text_condition("subj_storage", subject_template.storage)
24+
25 except KeyError, e:
26 # Value not in DB
27 log.debug("Unknown entity in query: %s" % e)
28
29=== modified file 'test/engine-test.py'
30--- test/engine-test.py 2010-07-28 20:28:48 +0000
31+++ test/engine-test.py 2010-08-31 20:50:54 +0000
32@@ -866,20 +866,27 @@
33 )
34 self.assertEquals(3, len(ids))
35
36- def testBug580364(self):
37- """ for now we raise a ValueError if someone wants to search
38- by the storage field, this might change later on. (LP: #580364)"""
39- events = [
40- Event.new_for_values(timestamp=1000, subject_storage="sometext"),
41- Event.new_for_values(timestamp=2000, subject_storage="anotherplace")
42- ]
43- ids_in = self.engine.insert_events(events)
44- template = Event.new_for_values(subject_storage="xxxx")
45-
46- self.assertRaises(ValueError, self.engine.find_eventids,
47- TimeRange.always(), [template], StorageState.Any, 10,
48- ResultType.MostRecentEvents
49- )
50+ def testFindStorageNotExistant(self):
51+ events = [
52+ Event.new_for_values(timestamp=1000, subject_storage="sometext"),
53+ Event.new_for_values(timestamp=2000, subject_storage="anotherplace")
54+ ]
55+ ids_in = self.engine.insert_events(events)
56+ template = Event.new_for_values(subject_storage="xxx")
57+ results = self.engine.find_eventids(TimeRange.always(), [template],
58+ StorageState.Any, 10, ResultType.MostRecentEvents)
59+ self.assertEquals(0, len(results))
60+
61+ def testFindStorage(self):
62+ events = [
63+ Event.new_for_values(timestamp=1000, subject_storage="sometext"),
64+ Event.new_for_values(timestamp=2000, subject_storage="anotherplace")
65+ ]
66+ ids_in = self.engine.insert_events(events)
67+ template = Event.new_for_values(subject_storage="sometext")
68+ results = self.engine.find_eventids(TimeRange.always(), [template],
69+ StorageState.Any, 10, ResultType.MostRecentEvents)
70+ self.assertEquals(1, len(results))
71
72 def testWildcard(self):
73 import_events("test/data/five_events.js", self.engine)