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

Proposed by Gary Lasker on 2012-03-01
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 2012-03-01 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.
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

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
1=== modified file 'softwarecenter/testutils.py'
2--- softwarecenter/testutils.py 2012-02-15 16:55:32 +0000
3+++ softwarecenter/testutils.py 2012-03-01 15:51:20 +0000
4@@ -194,7 +194,7 @@
5 def make_recommender_agent_recommend_me_dict():
6 # best to have a list of likely not-installed items
7 app_dict = {
8- u'recommendations': [
9+ u'data': [
10 {
11 u'package_name': u'clementine'
12 },
13
14=== modified file 'softwarecenter/ui/gtk3/widgets/recommendations.py'
15--- softwarecenter/ui/gtk3/widgets/recommendations.py 2012-02-29 19:58:05 +0000
16+++ softwarecenter/ui/gtk3/widgets/recommendations.py 2012-03-01 15:51:20 +0000
17@@ -80,19 +80,20 @@
18
19 # if we already have a recommender UUID, then the user is already
20 # opted-in to the recommender service
21+ self.recommended_for_you_content = None
22 if self.recommender_agent.recommender_uuid:
23 self._update_recommended_for_you_content()
24 else:
25 self._show_opt_in_view()
26
27- self.add(self.recommended_for_you_content)
28-
29 def _show_opt_in_view(self):
30 # opt in box
31 vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, StockEms.MEDIUM)
32 vbox.set_border_width(StockEms.LARGE)
33 self.opt_in_vbox = vbox # for tests
34 self.recommended_for_you_content = vbox # hook it up to the rest
35+
36+ self.add(self.recommended_for_you_content)
37
38 # opt in button
39 button = Gtk.Button(_("Turn On Recommendations"))
40@@ -146,7 +147,14 @@
41 self._hide_recommended_for_you_panel()
42
43 def _update_recommended_for_you_content(self):
44+ # destroy the old content to ensure we don't see it twice
45+ # (also removes the opt-in panel if it was there)
46+ if self.recommended_for_you_content:
47+ self.recommended_for_you_content.destroy()
48+ # add the new stuff
49+ self.header_implements_more_button()
50 self.recommended_for_you_content = FlowableGrid()
51+ self.add(self.recommended_for_you_content)
52 self.spinner_notebook.show_spinner(_("Receiving recommendations…"))
53 # get the recommendations from the recommender agent
54 self.recommended_for_you_cat = RecommendedForYouCategory()
55@@ -160,7 +168,6 @@
56 docs = cat.get_documents(self.catview.db)
57 # display the recommendedations
58 if len(docs) > 0:
59- self.header_implements_more_button()
60 self.catview._add_tiles_to_flowgrid(docs,
61 self.recommended_for_you_content, 8)
62 self.recommended_for_you_content.show_all()
63@@ -234,14 +241,29 @@
64 self.hide()
65
66
67-
68-def get_test_window_recommendations_panel_lobby():
69+# test helpers
70+def get_test_window():
71 import softwarecenter.log
72 softwarecenter.log.root.setLevel(level=logging.DEBUG)
73 fmt = logging.Formatter("%(name)s - %(message)s", None)
74 softwarecenter.log.handler.setFormatter(fmt)
75
76- view = RecommendationsPanelLobby()
77+
78+ # this is *way* to complicated we should *not* need a CatView
79+ # here! see FIXME in RecommendationsPanel.__init__()
80+ from softwarecenter.ui.gtk3.views.catview_gtk import CategoriesViewGtk
81+ from softwarecenter.testutils import (
82+ get_test_db, get_test_pkg_info, get_test_gtk3_icon_cache)
83+ cache = get_test_pkg_info()
84+ db = get_test_db()
85+ icons = get_test_gtk3_icon_cache()
86+ catview = CategoriesViewGtk(softwarecenter.paths.datadir,
87+ softwarecenter.paths.APP_INSTALL_PATH,
88+ cache,
89+ db,
90+ icons)
91+
92+ view = RecommendationsPanelLobby(catview)
93
94 win = Gtk.Window()
95 win.connect("destroy", lambda x: Gtk.main_quit())
96@@ -254,5 +276,5 @@
97
98
99 if __name__ == "__main__":
100- win = get_test_window_recommendations_panel_lobby()
101+ win = get_test_window()
102 Gtk.main()
103
104=== modified file 'test/gtk3/test_catview.py'
105--- test/gtk3/test_catview.py 2012-02-28 21:27:59 +0000
106+++ test/gtk3/test_catview.py 2012-03-01 15:51:20 +0000
107@@ -1,4 +1,4 @@
108-from gi.repository import Gtk
109+from gi.repository import Gtk, GObject
110 import time
111 import unittest
112 from mock import patch
113@@ -128,9 +128,18 @@
114 from softwarecenter.ui.gtk3.widgets.containers import FramedHeaderBox
115 self.assertTrue(rec_panel.spinner_notebook.get_current_page() == FramedHeaderBox.SPINNER)
116 self.assertTrue(rec_panel.opt_in_vbox.get_property("visible"))
117- self.assertTrue(rec_panel.spinner.spinner_label)
118- win.destroy()
119-
120+ # now pretent that we got data and ensure its displayed
121+ rec_panel._update_recommended_for_you_content()
122+ rec_panel.recommended_for_you_cat._recommend_me_result(
123+ None, make_recommender_agent_recommend_me_dict())
124+ self._p()
125+ self.assertTrue(rec_panel.recommended_for_you_content.get_property("visible"))
126+ self.assertFalse(rec_panel.opt_in_vbox.get_property("visible"))
127+ # exit after brief timeout
128+ TIMEOUT=100
129+ GObject.timeout_add(TIMEOUT, lambda: win.destroy())
130+ Gtk.main()
131+
132 # patch out the agent query method to avoid making the actual server call
133 @patch('softwarecenter.backend.recagent.RecommenderAgent'
134 '.post_submit_profile')
135@@ -179,6 +188,6 @@
136
137
138 if __name__ == "__main__":
139- import logging
140- logging.basicConfig(level=logging.DEBUG)
141+ #import logging
142+ #logging.basicConfig(level=logging.DEBUG)
143 unittest.main()
144
145=== added file 'test/gtk3/test_recommendations_widgets.py'
146--- test/gtk3/test_recommendations_widgets.py 1970-01-01 00:00:00 +0000
147+++ test/gtk3/test_recommendations_widgets.py 2012-03-01 15:51:20 +0000
148@@ -0,0 +1,30 @@
149+#!/usr/bin/python
150+
151+from gi.repository import Gtk, GObject
152+import unittest
153+
154+from testutils import setup_test_env
155+setup_test_env()
156+
157+from softwarecenter.ui.gtk3.widgets.recommendations import get_test_window
158+
159+# window destory timeout
160+TIMEOUT=100
161+
162+# FIXME: the code from test_catview that tests the lobby widget should
163+# move here as it should be fine to test it in isolation
164+
165+class TestRecommendationsWidgets(unittest.TestCase):
166+
167+ def test_recommendations_widgets(self):
168+ win = get_test_window()
169+ win.show_all()
170+ GObject.timeout_add(TIMEOUT, lambda: win.destroy())
171+ Gtk.main()
172+
173+
174+
175+if __name__ == "__main__":
176+ #import logging
177+ #logging.basicConfig(level=logging.DEBUG)
178+ unittest.main()

Subscribers

People subscribed via source and target branches