Merge lp:~elachuni/software-center/check-edit-labels into lp:software-center

Proposed by Anthony Lenton on 2012-01-16
Status: Merged
Merged at revision: 2657
Proposed branch: lp:~elachuni/software-center/check-edit-labels
Merge into: lp:software-center
Diff against target: 487 lines (+241/-182)
3 files modified
softwarecenter/rnr_helpers.py (+1/-181)
test/test_reviews.py (+22/-1)
utils/submit_review_gtk3.py (+218/-0)
To merge this branch: bzr merge lp:~elachuni/software-center/check-edit-labels
Reviewer Review Type Date Requested Status
Michael Vogt 2012-01-16 Approve on 2012-01-17
Review via email: mp+88781@code.launchpad.net

Description of the change

This branch contains a test to ensure that LP bug #880255 has been fixed.

While I was there, I moved all of the review-related helper apps into a module under softwarecenter, so that they can be tested directly.

I'm not sure this is the best approach to test these helper apps, but at least for this bug in particular it was easiest. I'll try to submit a subsequent MP with a couple more meaningful tests.

To post a comment you must log in.
Michael Vogt (mvo) wrote :

Thanks! This branch is great and immediately helps with making the code better layouted. I took the liberty to move rnr_helper.py into softwarecenter.backend.reviews but otherwise its unchanged.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'utils/submit_review_gtk3.py' => 'softwarecenter/rnr_helpers.py'
2--- utils/submit_review_gtk3.py 2012-01-09 15:53:01 +0000
3+++ softwarecenter/rnr_helpers.py 2012-01-16 21:50:53 +0000
4@@ -1,4 +1,3 @@
5-#!/usr/bin/python
6 # -*- coding: utf-8 -*-
7
8 # Copyright (C) 2009 Canonical
9@@ -23,9 +22,7 @@
10
11 import datetime
12 import gettext
13-import locale
14 import logging
15-import logging.handlers
16 import os
17 import json
18 import sys
19@@ -48,13 +45,12 @@
20
21
22 from gettext import gettext as _
23-from optparse import OptionParser
24
25 from softwarecenter.backend.ubuntusso import get_ubuntu_sso_backend
26
27 import piston_mini_client
28
29-from softwarecenter.paths import SOFTWARE_CENTER_CONFIG_DIR, SOFTWARE_CENTER_CACHE_DIR
30+from softwarecenter.paths import SOFTWARE_CENTER_CONFIG_DIR
31 from softwarecenter.enums import Icons
32 from softwarecenter.config import get_config
33 from softwarecenter.distro import get_distro, get_current_arch
34@@ -71,9 +67,6 @@
35 from softwarecenter.backend.piston.rnrclient import RatingsAndReviewsAPI
36 from softwarecenter.backend.piston.rnrclient_pristine import ReviewRequest
37
38-#import httplib2
39-#httplib2.debuglevel = 1
40-
41 # get current distro and set default server root
42 distro = get_distro()
43 SERVER_ROOT=distro.REVIEWS_SERVER
44@@ -1342,176 +1335,3 @@
45
46 def _change_status(self, type, message):
47 pass
48-
49-if __name__ == "__main__":
50- try:
51- locale.setlocale(locale.LC_ALL, "")
52- except:
53- logging.exception("setlocale failed, resetting to C")
54- locale.setlocale(locale.LC_ALL, "C")
55-
56- gettext.bindtextdomain("software-center", "/usr/share/locale")
57- gettext.textdomain("software-center")
58-
59- if os.path.exists("./data/ui/gtk3/submit_review.ui"):
60- default_datadir = "./data"
61- else:
62- default_datadir = "/usr/share/software-center/"
63-
64- # common options for optparse go here
65- parser = OptionParser()
66- parser.add_option("", "--datadir", default=default_datadir)
67-
68- logfile_path = os.path.join(SOFTWARE_CENTER_CACHE_DIR, "reviews-helper.log")
69- logfile_handler = logging.handlers.RotatingFileHandler(logfile_path,
70- maxBytes=100*1000,
71- backupCount=5)
72- logfile_handler.setLevel(logging.INFO)
73- logging.getLogger().addHandler(logfile_handler)
74-
75- # run review personality
76- if "submit_review" in sys.argv[0]:
77- # check options
78- parser.add_option("-a", "--appname")
79- parser.add_option("-p", "--pkgname")
80- parser.add_option("-i", "--iconname")
81- parser.add_option("-V", "--version")
82- parser.add_option("-O", "--origin")
83- parser.add_option("", "--parent-xid")
84- parser.add_option("", "--test", action="store_true", default=False)
85- parser.add_option("", "--debug",
86- action="store_true", default=False)
87- (options, args) = parser.parse_args()
88-
89- if options.test:
90- options.pkgname = options.pkgname or 'apt'
91- options.appname = options.appname or 'Apt'
92- options.iconname = options.iconname or 'folder'
93- options.version = options.version or '1.0'
94- options.origin = options.origin or 'Ubuntu'
95- options.parent_xid = options.parent_xid or '1'
96-
97- if not (options.pkgname and options.version):
98- parser.error(_("Missing arguments"))
99-
100- if options.debug:
101- logging.basicConfig(level=logging.DEBUG)
102-
103- # personality
104- logging.debug("submit_review mode")
105-
106- # initialize and run
107- theapp = Application(options.appname, options.pkgname)
108- review_app = SubmitReviewsApp(datadir=options.datadir,
109- app=theapp,
110- parent_xid=options.parent_xid,
111- iconname=options.iconname,
112- origin=options.origin,
113- version=options.version)
114- review_app.run()
115-
116-
117- # run "report" personality
118- if "report_review" in sys.argv[0]:
119- # check options
120- parser.add_option("", "--review-id")
121- parser.add_option("", "--parent-xid")
122- parser.add_option("", "--debug",
123- action="store_true", default=False)
124- (options, args) = parser.parse_args()
125-
126- if not (options.review_id):
127- parser.error(_("Missing review-id arguments"))
128-
129- if options.debug:
130- logging.basicConfig(level=logging.DEBUG)
131-
132- # personality
133- logging.debug("report_abuse mode")
134-
135- # initialize and run
136- report_app = ReportReviewApp(datadir=options.datadir,
137- review_id=options.review_id,
138- parent_xid=options.parent_xid)
139- report_app.run()
140-
141- if "submit_usefulness" in sys.argv[0]:
142- # check options
143- parser.add_option("", "--review-id")
144- parser.add_option("", "--parent-xid")
145- parser.add_option("", "--is-useful")
146- parser.add_option("", "--debug",
147- action="store_true", default=False)
148- (options, args) = parser.parse_args()
149-
150- if not (options.review_id):
151- parser.error(_("Missing review-id arguments"))
152-
153- if options.debug:
154- logging.basicConfig(level=logging.DEBUG)
155-
156- # personality
157- logging.debug("report_abuse mode")
158-
159- # initialize and run
160- usefulness_app = SubmitUsefulnessApp(datadir=options.datadir,
161- review_id=options.review_id,
162- parent_xid=options.parent_xid,
163- is_useful=int(options.is_useful))
164- usefulness_app.run()
165-
166- if "delete_review" in sys.argv[0]:
167- #check options
168- parser.add_option("", "--review-id")
169- parser.add_option("", "--parent-xid")
170- parser.add_option("", "--debug",
171- action="store_true", default=False)
172- (options, args) = parser.parse_args()
173-
174- if not (options.review_id):
175- parser.error(_("Missing review-id argument"))
176-
177- if options.debug:
178- logging.basicConfig(level=logging.DEBUG)
179-
180- logging.debug("delete review mode")
181-
182- delete_app = DeleteReviewApp(datadir=options.datadir,
183- review_id=options.review_id,
184- parent_xid=options.parent_xid)
185- delete_app.run()
186-
187- if "modify_review" in sys.argv[0]:
188- # check options
189- parser.add_option("", "--review-id")
190- parser.add_option("-i", "--iconname")
191- parser.add_option("", "--parent-xid")
192- parser.add_option("", "--debug",
193- action="store_true", default=False)
194- (options, args) = parser.parse_args()
195-
196- if not (options.review_id):
197- parser.error(_("Missing review-id argument"))
198-
199- if options.debug:
200- logging.basicConfig(level=logging.DEBUG)
201-
202- # personality
203- logging.debug("modify_review mode")
204-
205- # initialize and run
206- modify_app = SubmitReviewsApp(datadir=options.datadir,
207- app=None,
208- parent_xid=options.parent_xid,
209- iconname=options.iconname,
210- origin=None,
211- version=None,
212- action="modify",
213- review_id=options.review_id
214- )
215-
216- modify_app.run()
217-
218-
219- # main
220- Gtk.main()
221
222=== modified file 'test/test_reviews.py'
223--- test/test_reviews.py 2012-01-16 14:42:49 +0000
224+++ test/test_reviews.py 2012-01-16 21:50:53 +0000
225@@ -7,9 +7,12 @@
226
227 from testutils import setup_test_env
228 setup_test_env()
229+from gettext import gettext as _
230+
231 from softwarecenter.backend.reviews.rnr import (
232 ReviewLoaderSpawningRNRClient as ReviewLoader)
233 from softwarecenter.testutils import get_test_pkg_info, get_test_db
234+from softwarecenter.rnr_helpers import SubmitReviewsApp
235
236
237 class TestReviewLoader(unittest.TestCase):
238@@ -39,7 +42,25 @@
239 top_cat = review_loader.get_top_rated_apps(
240 quantity=8, category="Internet")
241 self.assertEqual(len(top_cat), 8)
242-
243+
244+ def test_edit_review_screen_has_right_labels(self):
245+ """Check that LP #880255 stays fixed. """
246+ loader = ReviewLoader(self.cache, self.db)
247+
248+ review_app = SubmitReviewsApp(datadir="../data", app=None,
249+ parent_xid='', iconname='accessories-calculator', origin=None,
250+ version=None, action='modify', review_id=10000)
251+ review_app.run()
252+
253+ self._p()
254+ review_app.login_successful('foobar')
255+ self._p()
256+ self.assertEqual(_('Rating:'), review_app.rating_label.get_label())
257+ self.assertEqual(_('Summary:'),
258+ review_app.review_summary_label.get_label())
259+ self.assertEqual(_('Review by: %s') % 'foobar',
260+ review_app.review_label.get_label())
261+ review_app.submit_window.unrealize()
262
263 def _p(self):
264 main_loop = GObject.main_context_default()
265
266=== added file 'utils/submit_review_gtk3.py'
267--- utils/submit_review_gtk3.py 1970-01-01 00:00:00 +0000
268+++ utils/submit_review_gtk3.py 2012-01-16 21:50:53 +0000
269@@ -0,0 +1,218 @@
270+#!/usr/bin/python
271+# -*- coding: utf-8 -*-
272+
273+# Copyright (C) 2009 Canonical
274+#
275+# Authors:
276+# Michael Vogt
277+#
278+# This program is free software; you can redistribute it and/or modify it under
279+# the terms of the GNU General Public License as published by the Free Software
280+# Foundation; version 3.
281+#
282+# This program is distributed in the hope that it will be useful, but WITHOUT
283+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
284+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
285+# details.
286+#
287+# You should have received a copy of the GNU General Public License along with
288+# this program; if not, write to the Free Software Foundation, Inc.,
289+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
290+
291+from gi.repository import Gtk
292+
293+import gettext
294+import locale
295+import logging
296+import logging.handlers
297+import os
298+import sys
299+
300+from gettext import gettext as _
301+from optparse import OptionParser
302+
303+from softwarecenter.paths import SOFTWARE_CENTER_CACHE_DIR
304+from softwarecenter.db.database import Application
305+
306+from softwarecenter.rnr_helpers import (
307+ DeleteReviewApp,
308+ ReportReviewApp,
309+ SubmitReviewsApp,
310+ SubmitUsefulnessApp,
311+ )
312+
313+#import httplib2
314+#httplib2.debuglevel = 1
315+
316+
317+if __name__ == "__main__":
318+ try:
319+ locale.setlocale(locale.LC_ALL, "")
320+ except:
321+ logging.exception("setlocale failed, resetting to C")
322+ locale.setlocale(locale.LC_ALL, "C")
323+
324+ gettext.bindtextdomain("software-center", "/usr/share/locale")
325+ gettext.textdomain("software-center")
326+
327+ if os.path.exists("./data/ui/gtk3/submit_review.ui"):
328+ default_datadir = "./data"
329+ else:
330+ default_datadir = "/usr/share/software-center/"
331+
332+ # common options for optparse go here
333+ parser = OptionParser()
334+ parser.add_option("", "--datadir", default=default_datadir)
335+
336+ logfile_path = os.path.join(SOFTWARE_CENTER_CACHE_DIR, "reviews-helper.log")
337+ logfile_handler = logging.handlers.RotatingFileHandler(logfile_path,
338+ maxBytes=100*1000,
339+ backupCount=5)
340+ logfile_handler.setLevel(logging.INFO)
341+ logging.getLogger().addHandler(logfile_handler)
342+
343+ # run review personality
344+ if "submit_review" in sys.argv[0]:
345+ # check options
346+ parser.add_option("-a", "--appname")
347+ parser.add_option("-p", "--pkgname")
348+ parser.add_option("-i", "--iconname")
349+ parser.add_option("-V", "--version")
350+ parser.add_option("-O", "--origin")
351+ parser.add_option("", "--parent-xid")
352+ parser.add_option("", "--test", action="store_true", default=False)
353+ parser.add_option("", "--debug",
354+ action="store_true", default=False)
355+ (options, args) = parser.parse_args()
356+
357+ if options.test:
358+ options.pkgname = options.pkgname or 'apt'
359+ options.appname = options.appname or 'Apt'
360+ options.iconname = options.iconname or 'folder'
361+ options.version = options.version or '1.0'
362+ options.origin = options.origin or 'Ubuntu'
363+ options.parent_xid = options.parent_xid or '1'
364+
365+ if not (options.pkgname and options.version):
366+ parser.error(_("Missing arguments"))
367+
368+ if options.debug:
369+ logging.basicConfig(level=logging.DEBUG)
370+
371+ # personality
372+ logging.debug("submit_review mode")
373+
374+ # initialize and run
375+ theapp = Application(options.appname, options.pkgname)
376+ review_app = SubmitReviewsApp(datadir=options.datadir,
377+ app=theapp,
378+ parent_xid=options.parent_xid,
379+ iconname=options.iconname,
380+ origin=options.origin,
381+ version=options.version)
382+ review_app.run()
383+
384+
385+ # run "report" personality
386+ if "report_review" in sys.argv[0]:
387+ # check options
388+ parser.add_option("", "--review-id")
389+ parser.add_option("", "--parent-xid")
390+ parser.add_option("", "--debug",
391+ action="store_true", default=False)
392+ (options, args) = parser.parse_args()
393+
394+ if not (options.review_id):
395+ parser.error(_("Missing review-id arguments"))
396+
397+ if options.debug:
398+ logging.basicConfig(level=logging.DEBUG)
399+
400+ # personality
401+ logging.debug("report_abuse mode")
402+
403+ # initialize and run
404+ report_app = ReportReviewApp(datadir=options.datadir,
405+ review_id=options.review_id,
406+ parent_xid=options.parent_xid)
407+ report_app.run()
408+
409+ if "submit_usefulness" in sys.argv[0]:
410+ # check options
411+ parser.add_option("", "--review-id")
412+ parser.add_option("", "--parent-xid")
413+ parser.add_option("", "--is-useful")
414+ parser.add_option("", "--debug",
415+ action="store_true", default=False)
416+ (options, args) = parser.parse_args()
417+
418+ if not (options.review_id):
419+ parser.error(_("Missing review-id arguments"))
420+
421+ if options.debug:
422+ logging.basicConfig(level=logging.DEBUG)
423+
424+ # personality
425+ logging.debug("report_abuse mode")
426+
427+ # initialize and run
428+ usefulness_app = SubmitUsefulnessApp(datadir=options.datadir,
429+ review_id=options.review_id,
430+ parent_xid=options.parent_xid,
431+ is_useful=int(options.is_useful))
432+ usefulness_app.run()
433+
434+ if "delete_review" in sys.argv[0]:
435+ #check options
436+ parser.add_option("", "--review-id")
437+ parser.add_option("", "--parent-xid")
438+ parser.add_option("", "--debug",
439+ action="store_true", default=False)
440+ (options, args) = parser.parse_args()
441+
442+ if not (options.review_id):
443+ parser.error(_("Missing review-id argument"))
444+
445+ if options.debug:
446+ logging.basicConfig(level=logging.DEBUG)
447+
448+ logging.debug("delete review mode")
449+
450+ delete_app = DeleteReviewApp(datadir=options.datadir,
451+ review_id=options.review_id,
452+ parent_xid=options.parent_xid)
453+ delete_app.run()
454+
455+ if "modify_review" in sys.argv[0]:
456+ # check options
457+ parser.add_option("", "--review-id")
458+ parser.add_option("-i", "--iconname")
459+ parser.add_option("", "--parent-xid")
460+ parser.add_option("", "--debug",
461+ action="store_true", default=False)
462+ (options, args) = parser.parse_args()
463+
464+ if not (options.review_id):
465+ parser.error(_("Missing review-id argument"))
466+
467+ if options.debug:
468+ logging.basicConfig(level=logging.DEBUG)
469+
470+ # personality
471+ logging.debug("modify_review mode")
472+
473+ # initialize and run
474+ modify_app = SubmitReviewsApp(datadir=options.datadir,
475+ app=None,
476+ parent_xid=options.parent_xid,
477+ iconname=options.iconname,
478+ origin=None,
479+ version=None,
480+ action="modify",
481+ review_id=options.review_id
482+ )
483+
484+ modify_app.run()
485+
486+ # main
487+ Gtk.main()