Merge lp:~gary-lasker/software-center/lobby-recommends-fixes into lp:software-center

Proposed by Gary Lasker
Status: Merged
Merged at revision: 2800
Proposed branch: lp:~gary-lasker/software-center/lobby-recommends-fixes
Merge into: lp:software-center
Diff against target: 178 lines (+75/-14)
4 files modified
softwarecenter/testutils.py (+1/-1)
softwarecenter/ui/gtk3/widgets/recommendations.py (+29/-7)
test/gtk3/test_catview.py (+15/-6)
test/gtk3/test_recommendations_widgets.py (+30/-0)
To merge this branch: bzr merge lp:~gary-lasker/software-center/lobby-recommends-fixes
Reviewer Review Type Date Requested Status
software-store-developers Pending
Review via email: mp+95296@code.launchpad.net

Description of the change

This branch fixes the problem where after the user opts in to the recommendations service, the opt-in panel is incorrectly displayed again. With this fix, the recommendations are displayed properly after they are downloaded from the server.

The branch also enables the "More" button to that can be used to display the list view for the recommendations.

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Thanks, this works fine, but its lacking a test. I added one (two actually) in lp:~mvo/software-center/lobby-recommends-fixes

2801. By Gary Lasker on 2012-03-01

merge from lp:~mvo/software-center/lobby-recommends-fixes, thanks mvo

Revision history for this message
Gary Lasker (gary-lasker) wrote :

Thanks Michael! I've merged your branch into mine if you'd like to re-review.

One comment is that I noticed you changed my hide() of the opt-in panel to use a destroy() instead. I didn't see it as a big deal to to use a simple hide() because it will only ever be made when opt-in is being offered, so the widgets are hidden only during the session where the user actually opt-in and the view switches to the recommendations. Once opted-in, the opt-in panel is never made again. But, I think either should be fine.

Thanks again!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'softwarecenter/testutils.py'
--- softwarecenter/testutils.py 2012-02-15 16:55:32 +0000
+++ softwarecenter/testutils.py 2012-03-01 15:51:20 +0000
@@ -194,7 +194,7 @@
194def make_recommender_agent_recommend_me_dict():194def make_recommender_agent_recommend_me_dict():
195 # best to have a list of likely not-installed items195 # best to have a list of likely not-installed items
196 app_dict = {196 app_dict = {
197 u'recommendations': [197 u'data': [
198 {198 {
199 u'package_name': u'clementine'199 u'package_name': u'clementine'
200 }, 200 },
201201
=== modified file 'softwarecenter/ui/gtk3/widgets/recommendations.py'
--- softwarecenter/ui/gtk3/widgets/recommendations.py 2012-02-29 19:58:05 +0000
+++ softwarecenter/ui/gtk3/widgets/recommendations.py 2012-03-01 15:51:20 +0000
@@ -80,19 +80,20 @@
80 80
81 # if we already have a recommender UUID, then the user is already81 # if we already have a recommender UUID, then the user is already
82 # opted-in to the recommender service82 # opted-in to the recommender service
83 self.recommended_for_you_content = None
83 if self.recommender_agent.recommender_uuid:84 if self.recommender_agent.recommender_uuid:
84 self._update_recommended_for_you_content()85 self._update_recommended_for_you_content()
85 else:86 else:
86 self._show_opt_in_view()87 self._show_opt_in_view()
87 88
88 self.add(self.recommended_for_you_content)
89
90 def _show_opt_in_view(self):89 def _show_opt_in_view(self):
91 # opt in box90 # opt in box
92 vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, StockEms.MEDIUM)91 vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, StockEms.MEDIUM)
93 vbox.set_border_width(StockEms.LARGE)92 vbox.set_border_width(StockEms.LARGE)
94 self.opt_in_vbox = vbox # for tests93 self.opt_in_vbox = vbox # for tests
95 self.recommended_for_you_content = vbox # hook it up to the rest94 self.recommended_for_you_content = vbox # hook it up to the rest
95
96 self.add(self.recommended_for_you_content)
9697
97 # opt in button98 # opt in button
98 button = Gtk.Button(_("Turn On Recommendations"))99 button = Gtk.Button(_("Turn On Recommendations"))
@@ -146,7 +147,14 @@
146 self._hide_recommended_for_you_panel()147 self._hide_recommended_for_you_panel()
147 148
148 def _update_recommended_for_you_content(self):149 def _update_recommended_for_you_content(self):
150 # destroy the old content to ensure we don't see it twice
151 # (also removes the opt-in panel if it was there)
152 if self.recommended_for_you_content:
153 self.recommended_for_you_content.destroy()
154 # add the new stuff
155 self.header_implements_more_button()
149 self.recommended_for_you_content = FlowableGrid()156 self.recommended_for_you_content = FlowableGrid()
157 self.add(self.recommended_for_you_content)
150 self.spinner_notebook.show_spinner(_("Receiving recommendations…"))158 self.spinner_notebook.show_spinner(_("Receiving recommendations…"))
151 # get the recommendations from the recommender agent159 # get the recommendations from the recommender agent
152 self.recommended_for_you_cat = RecommendedForYouCategory()160 self.recommended_for_you_cat = RecommendedForYouCategory()
@@ -160,7 +168,6 @@
160 docs = cat.get_documents(self.catview.db)168 docs = cat.get_documents(self.catview.db)
161 # display the recommendedations169 # display the recommendedations
162 if len(docs) > 0:170 if len(docs) > 0:
163 self.header_implements_more_button()
164 self.catview._add_tiles_to_flowgrid(docs,171 self.catview._add_tiles_to_flowgrid(docs,
165 self.recommended_for_you_content, 8)172 self.recommended_for_you_content, 8)
166 self.recommended_for_you_content.show_all()173 self.recommended_for_you_content.show_all()
@@ -234,14 +241,29 @@
234 self.hide()241 self.hide()
235 242
236243
237244# test helpers
238def get_test_window_recommendations_panel_lobby():245def get_test_window():
239 import softwarecenter.log246 import softwarecenter.log
240 softwarecenter.log.root.setLevel(level=logging.DEBUG)247 softwarecenter.log.root.setLevel(level=logging.DEBUG)
241 fmt = logging.Formatter("%(name)s - %(message)s", None)248 fmt = logging.Formatter("%(name)s - %(message)s", None)
242 softwarecenter.log.handler.setFormatter(fmt)249 softwarecenter.log.handler.setFormatter(fmt)
243 250
244 view = RecommendationsPanelLobby()251
252 # this is *way* to complicated we should *not* need a CatView
253 # here! see FIXME in RecommendationsPanel.__init__()
254 from softwarecenter.ui.gtk3.views.catview_gtk import CategoriesViewGtk
255 from softwarecenter.testutils import (
256 get_test_db, get_test_pkg_info, get_test_gtk3_icon_cache)
257 cache = get_test_pkg_info()
258 db = get_test_db()
259 icons = get_test_gtk3_icon_cache()
260 catview = CategoriesViewGtk(softwarecenter.paths.datadir,
261 softwarecenter.paths.APP_INSTALL_PATH,
262 cache,
263 db,
264 icons)
265
266 view = RecommendationsPanelLobby(catview)
245267
246 win = Gtk.Window()268 win = Gtk.Window()
247 win.connect("destroy", lambda x: Gtk.main_quit())269 win.connect("destroy", lambda x: Gtk.main_quit())
@@ -254,5 +276,5 @@
254 276
255277
256if __name__ == "__main__":278if __name__ == "__main__":
257 win = get_test_window_recommendations_panel_lobby()279 win = get_test_window()
258 Gtk.main()280 Gtk.main()
259281
=== modified file 'test/gtk3/test_catview.py'
--- test/gtk3/test_catview.py 2012-02-28 21:27:59 +0000
+++ test/gtk3/test_catview.py 2012-03-01 15:51:20 +0000
@@ -1,4 +1,4 @@
1from gi.repository import Gtk1from gi.repository import Gtk, GObject
2import time2import time
3import unittest3import unittest
4from mock import patch4from mock import patch
@@ -128,9 +128,18 @@
128 from softwarecenter.ui.gtk3.widgets.containers import FramedHeaderBox128 from softwarecenter.ui.gtk3.widgets.containers import FramedHeaderBox
129 self.assertTrue(rec_panel.spinner_notebook.get_current_page() == FramedHeaderBox.SPINNER)129 self.assertTrue(rec_panel.spinner_notebook.get_current_page() == FramedHeaderBox.SPINNER)
130 self.assertTrue(rec_panel.opt_in_vbox.get_property("visible"))130 self.assertTrue(rec_panel.opt_in_vbox.get_property("visible"))
131 self.assertTrue(rec_panel.spinner.spinner_label)131 # now pretent that we got data and ensure its displayed
132 win.destroy()132 rec_panel._update_recommended_for_you_content()
133 133 rec_panel.recommended_for_you_cat._recommend_me_result(
134 None, make_recommender_agent_recommend_me_dict())
135 self._p()
136 self.assertTrue(rec_panel.recommended_for_you_content.get_property("visible"))
137 self.assertFalse(rec_panel.opt_in_vbox.get_property("visible"))
138 # exit after brief timeout
139 TIMEOUT=100
140 GObject.timeout_add(TIMEOUT, lambda: win.destroy())
141 Gtk.main()
142
134 # patch out the agent query method to avoid making the actual server call143 # patch out the agent query method to avoid making the actual server call
135 @patch('softwarecenter.backend.recagent.RecommenderAgent'144 @patch('softwarecenter.backend.recagent.RecommenderAgent'
136 '.post_submit_profile')145 '.post_submit_profile')
@@ -179,6 +188,6 @@
179188
180189
181if __name__ == "__main__":190if __name__ == "__main__":
182 import logging191 #import logging
183 logging.basicConfig(level=logging.DEBUG)192 #logging.basicConfig(level=logging.DEBUG)
184 unittest.main()193 unittest.main()
185194
=== added file 'test/gtk3/test_recommendations_widgets.py'
--- test/gtk3/test_recommendations_widgets.py 1970-01-01 00:00:00 +0000
+++ test/gtk3/test_recommendations_widgets.py 2012-03-01 15:51:20 +0000
@@ -0,0 +1,30 @@
1#!/usr/bin/python
2
3from gi.repository import Gtk, GObject
4import unittest
5
6from testutils import setup_test_env
7setup_test_env()
8
9from softwarecenter.ui.gtk3.widgets.recommendations import get_test_window
10
11# window destory timeout
12TIMEOUT=100
13
14# FIXME: the code from test_catview that tests the lobby widget should
15# move here as it should be fine to test it in isolation
16
17class TestRecommendationsWidgets(unittest.TestCase):
18
19 def test_recommendations_widgets(self):
20 win = get_test_window()
21 win.show_all()
22 GObject.timeout_add(TIMEOUT, lambda: win.destroy())
23 Gtk.main()
24
25
26
27if __name__ == "__main__":
28 #import logging
29 #logging.basicConfig(level=logging.DEBUG)
30 unittest.main()

Subscribers

People subscribed via source and target branches