Merge ~twom/launchpad:questions-about-that-storm-porting into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: 85f7f7a4ade02891b652383552457d14b071a226
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:questions-about-that-storm-porting
Merge into: launchpad:master
Diff against target: 278 lines (+48/-36)
10 files modified
lib/lp/answers/model/faq.py (+1/-1)
lib/lp/answers/model/question.py (+5/-2)
lib/lp/bugs/model/bug.py (+1/-1)
lib/lp/coop/answersbugs/tests/test_doc.py (+2/-2)
lib/lp/registry/scripts/closeaccount.py (+4/-3)
lib/lp/registry/tests/test_distribution.py (+2/-2)
lib/lp/registry/tests/test_oopsreferences.py (+5/-5)
lib/lp/registry/tests/test_product.py (+2/-2)
lib/lp/services/database/doc/textsearching.txt (+20/-13)
lib/lp/services/statistics/model/statistics.py (+6/-5)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+394836@code.launchpad.net

Commit message

Fix other references to Question now it's Storm ported

Description of the change

FAQ, Question.get, statistics, and closeaccount all needed more fixes.
Also fix various unicode and SQL lookups in tests.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) wrote :

looks good!

review: Approve
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/answers/model/faq.py b/lib/lp/answers/model/faq.py
2index 70f4648..74b133c 100644
3--- a/lib/lp/answers/model/faq.py
4+++ b/lib/lp/answers/model/faq.py
5@@ -96,7 +96,7 @@ class FAQ(SQLBase):
6 return self.distribution
7
8 def destroySelf(self):
9- if self.related_questions:
10+ if not self.related_questions.is_empty():
11 raise CannotDeleteFAQ(
12 "Cannot delete FAQ: questions must be unlinked first.")
13 super(FAQ, self).destroySelf()
14diff --git a/lib/lp/answers/model/question.py b/lib/lp/answers/model/question.py
15index f2fa7f4..f03ed40 100644
16--- a/lib/lp/answers/model/question.py
17+++ b/lib/lp/answers/model/question.py
18@@ -841,8 +841,11 @@ class QuestionSet:
19
20 def get(self, question_id, default=None):
21 """See `IQuestionSet`."""
22- store = IStore(Question)
23- question = store.get(Question, question_id)
24+ # search views produce strings, not integers
25+ question_id = int(question_id)
26+ question = IStore(Question).find(
27+ Question,
28+ Question.id == question_id).one()
29 return question or default
30
31 def getOpenQuestionCountByPackages(self, packages):
32diff --git a/lib/lp/bugs/model/bug.py b/lib/lp/bugs/model/bug.py
33index 12f9e72..b20d9bc 100644
34--- a/lib/lp/bugs/model/bug.py
35+++ b/lib/lp/bugs/model/bug.py
36@@ -1534,7 +1534,7 @@ class Bug(SQLBase, InformationTypeMixin):
37 @cachedproperty
38 def _question_from_bug(self):
39 for question in self.questions:
40- if (question.ownerID == self.ownerID
41+ if (question.owner_id == self.ownerID
42 and question.datecreated == self.datecreated):
43 return question
44 return None
45diff --git a/lib/lp/coop/answersbugs/tests/test_doc.py b/lib/lp/coop/answersbugs/tests/test_doc.py
46index b1bdc5d..dac74e4 100644
47--- a/lib/lp/coop/answersbugs/tests/test_doc.py
48+++ b/lib/lp/coop/answersbugs/tests/test_doc.py
49@@ -52,8 +52,8 @@ def _createUbuntuBugTaskLinkedToQuestion():
50 ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
51 ubuntu.addAnswerContact(ubuntu_team, ubuntu_team.teamowner)
52 ubuntu_question = ubuntu.newQuestion(
53- sample_person, "Can't install Ubuntu",
54- "I insert the install CD in the CD-ROM drive, but it won't boot.")
55+ sample_person, u"Can't install Ubuntu",
56+ u"I insert the install CD in the CD-ROM drive, but it won't boot.")
57 no_priv = getUtility(IPersonSet).getByEmail('no-priv@canonical.com')
58 params = CreateBugParams(
59 owner=no_priv, title="Installer fails on a Mac PPC",
60diff --git a/lib/lp/registry/scripts/closeaccount.py b/lib/lp/registry/scripts/closeaccount.py
61index 9949b95..208c3e7 100644
62--- a/lib/lp/registry/scripts/closeaccount.py
63+++ b/lib/lp/registry/scripts/closeaccount.py
64@@ -240,9 +240,10 @@ def close_account(username, log):
65 # Reassign questions assigned to the user, and close all their questions
66 # in non-final states since nobody else can.
67 table_notification('Question')
68- store.find(Question, Question.assigneeID == person.id).set(assigneeID=None)
69+ store.find(Question, Question.assignee_id == person.id).set(
70+ assignee_id=None)
71 owned_non_final_questions = store.find(
72- Question, Question.ownerID == person.id,
73+ Question, Question.owner_id == person.id,
74 Question.status.is_in([
75 QuestionStatus.OPEN, QuestionStatus.NEEDSINFO,
76 QuestionStatus.ANSWERED,
77@@ -250,7 +251,7 @@ def close_account(username, log):
78 owned_non_final_questions.set(
79 status=QuestionStatus.SOLVED,
80 whiteboard=(
81- 'Closed by Launchpad due to owner requesting account removal'))
82+ u'Closed by Launchpad due to owner requesting account removal'))
83 skip.add(('question', 'owner'))
84
85 # Remove rows from tables in simple cases in the given order
86diff --git a/lib/lp/registry/tests/test_distribution.py b/lib/lp/registry/tests/test_distribution.py
87index a053738..0b9f712 100644
88--- a/lib/lp/registry/tests/test_distribution.py
89+++ b/lib/lp/registry/tests/test_distribution.py
90@@ -805,7 +805,7 @@ class TestDistributionWebservice(TestCaseWithFactory):
91 with person_logged_in(self.person):
92 distro = self.factory.makeDistribution()
93 self.factory.makeQuestion(
94- title="Crash with %s" % oopsid, target=distro)
95+ title=u"Crash with %s" % oopsid, target=distro)
96 distro_url = api_url(distro)
97
98 now = datetime.datetime.now(tz=pytz.utc)
99@@ -830,7 +830,7 @@ class TestDistributionWebservice(TestCaseWithFactory):
100 # check the filter is tight enough - other contexts should not work.
101 oopsid = "OOPS-abcdef1234"
102 with person_logged_in(self.person):
103- self.factory.makeQuestion(title="Crash with %s" % oopsid)
104+ self.factory.makeQuestion(title=u"Crash with %s" % oopsid)
105 distro = self.factory.makeDistribution()
106 distro_url = api_url(distro)
107 now = datetime.datetime.now(tz=pytz.utc)
108diff --git a/lib/lp/registry/tests/test_oopsreferences.py b/lib/lp/registry/tests/test_oopsreferences.py
109index 8633b9e..54e8514 100644
110--- a/lib/lp/registry/tests/test_oopsreferences.py
111+++ b/lib/lp/registry/tests/test_oopsreferences.py
112@@ -92,7 +92,7 @@ class TestOopsReferences(TestCaseWithFactory):
113
114 def test_oops_in_question_title(self):
115 oopsid = "OOPS-abcdef1234"
116- question = self.factory.makeQuestion(title="Crash with %s" % oopsid)
117+ question = self.factory.makeQuestion(title=u"Crash with %s" % oopsid)
118 self.store.flush()
119 now = datetime.now(tz=utc)
120 day = timedelta(days=1)
121@@ -107,7 +107,7 @@ class TestOopsReferences(TestCaseWithFactory):
122
123 def test_oops_in_question_wrong_context(self):
124 oopsid = "OOPS-abcdef1234"
125- question = self.factory.makeQuestion(title="Crash with %s" % oopsid)
126+ question = self.factory.makeQuestion(title=u"Crash with %s" % oopsid)
127 self.store.flush()
128 now = datetime.now(tz=utc)
129 day = timedelta(days=1)
130@@ -120,7 +120,7 @@ class TestOopsReferences(TestCaseWithFactory):
131 def test_oops_in_question_description(self):
132 oopsid = "OOPS-abcdef1234"
133 question = self.factory.makeQuestion(
134- description="Crash with %s" % oopsid)
135+ description=u"Crash with %s" % oopsid)
136 self.store.flush()
137 now = datetime.now(tz=utc)
138 day = timedelta(days=1)
139@@ -137,7 +137,7 @@ class TestOopsReferences(TestCaseWithFactory):
140 oopsid = "OOPS-abcdef1234"
141 question = self.factory.makeQuestion()
142 with person_logged_in(question.owner):
143- question.whiteboard = "Crash with %s" % oopsid
144+ question.whiteboard = u"Crash with %s" % oopsid
145 self.store.flush()
146 now = datetime.now(tz=utc)
147 day = timedelta(days=1)
148@@ -155,7 +155,7 @@ class TestOopsReferences(TestCaseWithFactory):
149 distro = self.factory.makeDistribution()
150 question = self.factory.makeQuestion(target=distro)
151 with person_logged_in(question.owner):
152- question.whiteboard = "Crash with %s" % oopsid
153+ question.whiteboard = u"Crash with %s" % oopsid
154 self.store.flush()
155 now = datetime.now(tz=utc)
156 day = timedelta(days=1)
157diff --git a/lib/lp/registry/tests/test_product.py b/lib/lp/registry/tests/test_product.py
158index f34be9d..bf64c64 100644
159--- a/lib/lp/registry/tests/test_product.py
160+++ b/lib/lp/registry/tests/test_product.py
161@@ -2145,7 +2145,7 @@ class TestWebService(WebServiceTestCase):
162 # The product layer provides the context restriction, so we need to
163 # check we can access context filtered references - e.g. on question.
164 oopsid = "OOPS-abcdef1234"
165- question = self.factory.makeQuestion(title="Crash with %s" % oopsid)
166+ question = self.factory.makeQuestion(title=u"Crash with %s" % oopsid)
167 product = question.product
168 transaction.commit()
169 ws_product = self.wsObject(product, product.owner)
170@@ -2163,7 +2163,7 @@ class TestWebService(WebServiceTestCase):
171 # The product layer provides the context restriction, so we need to
172 # check the filter is tight enough - other contexts should not work.
173 oopsid = "OOPS-abcdef1234"
174- self.factory.makeQuestion(title="Crash with %s" % oopsid)
175+ self.factory.makeQuestion(title=u"Crash with %s" % oopsid)
176 product = self.factory.makeProduct()
177 transaction.commit()
178 ws_product = self.wsObject(product, product.owner)
179diff --git a/lib/lp/services/database/doc/textsearching.txt b/lib/lp/services/database/doc/textsearching.txt
180index e5feb20..0cb4d67 100644
181--- a/lib/lp/services/database/doc/textsearching.txt
182+++ b/lib/lp/services/database/doc/textsearching.txt
183@@ -689,9 +689,12 @@ rows will be excluded from the final search.
184
185 More than 50% of the questions matches firefox:
186
187- >>> question_count = Question.select().count()
188- >>> firefox_questions = Question.select(
189- ... 'fti @@ ftq(%s)' % quote('firefox')).count()
190+ >>> from lp.services.database.interfaces import IStore
191+ >>> from lp.services.database.stormexpr import fti_search
192+ >>> question_count = IStore(Question).find(Question).count()
193+ >>> firefox_questions = IStore(Question).find(
194+ ... Question,
195+ ... fti_search(Question, "firefox")).count()
196 >>> float(firefox_questions) / question_count > 0.50
197 True
198
199@@ -732,10 +735,11 @@ considered a stop word by tsearch2).
200 >>> from lp.registry.model.product import Product
201 >>> firefox_product = getUtility(IProductSet).getByName('firefox')
202
203- >>> firefox_count = Question.select(
204- ... 'product = %s' % firefox_product.id).count()
205- >>> get_questions = Question.select(
206- ... 'fti @@ ftq(%s)' % quote('get')).count()
207+ >>> firefox_count = IStore(Question).find(
208+ ... Question, Question.product_id == firefox_product.id).count()
209+ >>> get_questions = IStore(Question).find(
210+ ... Question,
211+ ... fti_search(Question, "get")).count()
212 >>> float(get_questions) / firefox_count > 0.50
213 True
214
215@@ -754,7 +758,7 @@ string:
216 When there are no candidate rows, only stemming and stop words removal
217 is done.
218
219- >>> Question.select('product = -1').count()
220+ >>> IStore(Question).find(Question, Question.product_id == -1).count()
221 0
222 >>> nl_phrase_search('firefox is very slow on flickr', Question,
223 ... [Question.product == -1])
224@@ -776,16 +780,19 @@ mozilla-firefox source package.
225 >>> from lp.registry.interfaces.distribution import IDistributionSet
226 >>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
227 >>> firefox_package = ubuntu.getSourcePackage('mozilla-firefox')
228- >>> firefox_package_questions = Question.select(
229- ... 'distribution = %s AND sourcepackagename = %s' % sqlvalues(
230- ... ubuntu, firefox_package.sourcepackagename))
231+ >>> firefox_package_id =firefox_package.sourcepackagename.id
232+ >>> firefox_package_questions = IStore(Question).find(
233+ ... Question,
234+ ... Question.distribution_id == ubuntu.id,
235+ ... Question.sourcepackagename_id == firefox_package_id)
236 >>> firefox_package_questions.count() < 5
237 True
238
239 And more than half of these contain the keyword "firefox" in them:
240
241- >>> firefox_questions = Question.select(
242- ... 'fti @@ ftq(%s)' % quote('firefox')).count()
243+ >>> firefox_questions = IStore(Question).find(
244+ ... Question,
245+ ... fti_search(Question, "firefox"))
246 >>> float(get_questions) / firefox_package_questions.count() > 0.50
247 True
248
249diff --git a/lib/lp/services/statistics/model/statistics.py b/lib/lp/services/statistics/model/statistics.py
250index 7cbb6cb..40c7dec 100644
251--- a/lib/lp/services/statistics/model/statistics.py
252+++ b/lib/lp/services/statistics/model/statistics.py
253@@ -207,19 +207,20 @@ class LaunchpadStatisticSet:
254 ztm.commit()
255
256 def _updateQuestionStatistics(self, ztm):
257- self.update('question_count', Question.select().count())
258+ store = IStore(Question)
259+ self.update('question_count', store.find(Question).count())
260 ztm.commit()
261
262 self.update(
263 'answered_question_count',
264- Question.select(
265- 'status = %s' % sqlvalues(QuestionStatus.ANSWERED)).count())
266+ store.find(
267+ Question, Question.status == QuestionStatus.ANSWERED).count())
268 ztm.commit()
269
270 self.update(
271 'solved_question_count',
272- Question.select(
273- 'status = %s' % sqlvalues(QuestionStatus.SOLVED)).count())
274+ store.find(
275+ Question, Question.status == QuestionStatus.SOLVED).count())
276 ztm.commit()
277
278 cur = cursor()

Subscribers

People subscribed via source and target branches

to status/vote changes: