~nik90/ubuntu/precise/software-center/add_keywords

« back to all changes in this revision

Viewing changes to test/gtk3/test_appdetailsview.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt, Michael Vogt, Brendan Donegan, Gary Lasker
  • Date: 2012-02-03 18:34:43 UTC
  • Revision ID: package-import@ubuntu.com-20120203183443-1r39x52ozrb1revz
Tags: 5.1.8
[ Michael Vogt ]
* softwarecenter/db/update.py:
  - trivial fix to skip unreadable app-install-data files
* lp:~mvo/software-center/device-profiles:
  - implement the hardware-requirements display in
    the detailsview
* lp:~mvo/software-center/arb-partner-channels:
  - add support for extras.ubuntu.com and archive.canonical.com
    channel detection and adding via software-center-agent
* data/software-center.menu.in:
  - do not show "X-Publishing" in education because the
    software-center-agent will send "X-Publishing;Education" for
    compatibility with the old clients
* lp:~mvo/software-center/fix-cachedir-for-public-api:
  - add missing cachedir argument
* lp:~mvo/software-center/region-support:
  - add support for a region tag and display a warning to
    the user if an application is not suitable for their
    region

[ Brendan Donegan ]
* lp:~brendan-donegan/software-center/test_utils_get_nice_date_string:
  - add a test function in test_utils.py which covers all of
    get_nice_date_string

[ Gary Lasker ]
* lp:~gary-lasker/software-center/launcher-integration-lp761851:
  - update to the Unity launcher integration implementation to
    support the revamped functionality on the Unity side (LP: #761851) 
* lp:~gary-lasker/software-center/recommends-ui-lobby:
  - initial recommends UI implementation, limited to non-personalized
    recommends currently
* lp:~gary-lasker/software-center/appdetailsview-button-focus-fix:
  - make sure the action button in the applications details view
    always gets the initial focus (LP: #925613)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
3
import unittest
 
4
 
4
5
from gi.repository import Gtk, GObject
 
6
from gettext import gettext as _
5
7
 
6
8
from testutils import setup_test_env
7
9
setup_test_env()
10
12
 
11
13
from softwarecenter.db.application import Application
12
14
from softwarecenter.testutils import get_mock_app_from_real_app, do_events
 
15
from softwarecenter.ui.gtk3.widgets.labels import HardwareRequirementsBox
13
16
from softwarecenter.ui.gtk3.views.appdetailsview import get_test_window_appdetails
14
17
from softwarecenter.enums import PkgStates
 
18
from softwarecenter.region import REGION_WARNING_STRING
15
19
 
16
20
from test.test_database import make_purchased_app_details
17
21
 
 
22
 
 
23
 
18
24
# window destory timeout
19
25
TIMEOUT=100
20
26
 
45
51
        do_events()
46
52
        self.assertTrue(self.view.videoplayer.get_property("visible"))
47
53
    
48
 
    def test_page(self):
 
54
    def test_page_pkgstatusbar(self):
49
55
        # show app 
50
 
        app = Application("", "software-center")
 
56
        app = Application("", "abiword")
51
57
        self.view.show_app(app)
52
58
        do_events()
 
59
        
 
60
        # check that the action bar is given initial focus in the view
 
61
        self.assertTrue(self.view.pkg_statusbar.button.is_focus())
53
62
 
54
63
        # create mock app
55
64
        mock_app = get_mock_app_from_real_app(app)
57
66
        mock_details = mock_app.get_details(None)
58
67
        mock_details.purchase_date = "2011-11-20 17:45:01"
59
68
        mock_details._error_not_found = "error not found"
 
69
        mock_details.price = "1.00"
 
70
        mock_details.pkgname = "abiword"
60
71
        self.view.app_details = mock_details
61
72
 
 
73
        # the states and what labels we expect in the pkgstatusbar
 
74
        # first string is status text, second is button text
 
75
        pkg_states_to_labels = {
 
76
            PkgStates.INSTALLED : ("Purchased on 2011-11-20", "Remove"),
 
77
            PkgStates.UNINSTALLED : ('Free', 'Install'),
 
78
            PkgStates.NEEDS_PURCHASE : ('US$ 1.00', u'Buy\u2026'),
 
79
            PkgStates.PURCHASED_BUT_REPO_MUST_BE_ENABLED : ('Purchased on 2011-11-20', 'Install'),
 
80
        }
 
81
 
62
82
        # show a app through the various states
63
83
        for var in vars(PkgStates):
64
84
            # FIXME: this just ensures we are not crashing, also
70
90
            self.view.app = None
71
91
            # show it
72
92
            self.view.show_app(mock_app)
 
93
            if state in pkg_states_to_labels:
 
94
                label, button_label = pkg_states_to_labels[state]
 
95
                self.assertEqual(
 
96
                    self.view.pkg_statusbar.get_label(), 
 
97
                    label.decode("utf-8"))
 
98
                self.assertEqual(
 
99
                    self.view.pkg_statusbar.get_button_label().decode("utf-8"),
 
100
                    button_label)
73
101
 
74
102
    def test_app_icon_loading(self):
75
103
        # get icon
87
115
        # FIXME: ensure that the icon is really downloaded
88
116
        #self.assertTrue(os.path.exists(mock_details.cached_icon_file_path))
89
117
        #os.unlink(mock_details.cached_icon_file_path)
90
 
        
 
118
 
91
119
    def test_add_where_is_it(self):
92
120
        app = Application("", "software-center")
93
121
        self.view.show_app(app)
201
229
        self.view._submit_reviews_done_callback(None, 0)
202
230
 
203
231
        self.assertTrue(button.is_sensitive())
 
232
        
 
233
 
 
234
class HardwareRequirementsTestCase(unittest.TestCase):
 
235
    
 
236
    @classmethod
 
237
    def setUpClass(cls):
 
238
        # Set these as class attributes as we don't modify either
 
239
        # during the tests.
 
240
        from softwarecenter.testutils import get_test_db
 
241
        cls.db = get_test_db()
 
242
        cls.win = get_test_window_appdetails()
 
243
        cls.view = cls.win.get_data("view")
 
244
 
 
245
    @classmethod
 
246
    def tearDownClass(cls):
 
247
        GObject.timeout_add(TIMEOUT, lambda: cls.win.destroy())
 
248
        Gtk.main()
 
249
 
 
250
    def setUp(self):
 
251
        app = Application("", "software-center")
 
252
        self.app_mock = get_mock_app_from_real_app(app)
 
253
        self.app_mock.details.pkg_state = PkgStates.UNINSTALLED
 
254
 
 
255
    def test_show_hardware_requirements(self):
 
256
        self.app_mock.details.hardware_requirements = { 
 
257
            'hardware::video:opengl' : 'yes',
 
258
            'hardware::gps' : 'no',
 
259
            }
 
260
        self.app_mock.details.hardware_requirements_satisfied = False
 
261
        self.view.show_app(self.app_mock)
 
262
        do_events()
 
263
        # ensure we have the data
 
264
        self.assertTrue(
 
265
            self.view.hardware_info.value_label.get_property("visible"))
 
266
        self.assertEqual(
 
267
            type(HardwareRequirementsBox()),
 
268
            type(self.view.hardware_info.value_label))
 
269
        self.assertEqual(
 
270
            self.view.hardware_info.key, _("Also requires"))
 
271
        # ensure that the button is correct
 
272
        self.assertEqual(
 
273
            self.view.pkg_statusbar.button.get_label(), "Install Anyway")
 
274
        # and again for purchase
 
275
        self.app_mock.details.pkg_state = PkgStates.NEEDS_PURCHASE
 
276
        self.view.show_app(self.app_mock)
 
277
        self.assertEqual(
 
278
            self.view.pkg_statusbar.button.get_label(), 
 
279
            _(u"Buy Anyway\u2026").encode("utf-8"))
 
280
        # check if the warning bar is displayed
 
281
        self.assertTrue(self.view.pkg_warningbar.get_property("visible"))
 
282
        self.assertEqual(self.view.pkg_warningbar.label.get_text(),
 
283
                         _('This software requires a GPS, '
 
284
                           'but the computer does not have one.'))
 
285
 
 
286
    def test_no_show_hardware_requirements(self):
 
287
        self.app_mock.details.hardware_requirements = {}
 
288
        self.app_mock.details.hardware_requirements_satisfied = True
 
289
        self.view.show_app(self.app_mock)
 
290
        do_events()
 
291
        # ensure we do not show anything if there are no HW requirements
 
292
        self.assertFalse(
 
293
            self.view.hardware_info.get_property("visible"))
 
294
        # ensure that the button is correct
 
295
        self.assertEqual(
 
296
            self.view.pkg_statusbar.button.get_label(), _("Install"))
 
297
        # and again for purchase
 
298
        self.app_mock.details.pkg_state = PkgStates.NEEDS_PURCHASE
 
299
        self.view.show_app(self.app_mock)
 
300
        self.assertEqual(
 
301
            self.view.pkg_statusbar.button.get_label(), 
 
302
            _(u'Buy\u2026').encode("utf-8"))
 
303
        # check if the warning bar is invisible
 
304
        self.assertFalse(self.view.pkg_warningbar.get_property("visible"))
 
305
 
 
306
class RegionRequirementsTestCase(unittest.TestCase):
 
307
    
 
308
    @classmethod
 
309
    def setUpClass(cls):
 
310
        # Set these as class attributes as we don't modify either
 
311
        # during the tests.
 
312
        from softwarecenter.testutils import get_test_db
 
313
        cls.db = get_test_db()
 
314
        cls.win = get_test_window_appdetails()
 
315
        cls.view = cls.win.get_data("view")
 
316
 
 
317
    @classmethod
 
318
    def tearDownClass(cls):
 
319
        GObject.timeout_add(TIMEOUT, lambda: cls.win.destroy())
 
320
        Gtk.main()
 
321
 
 
322
    def setUp(self):
 
323
        app = Application("", "software-center")
 
324
        self.app_mock = get_mock_app_from_real_app(app)
 
325
        self.app_mock.details.pkg_state = PkgStates.UNINSTALLED
 
326
 
 
327
    def test_show_region_requirements(self):
 
328
        self.app_mock.details.region_requirements_satisfied = False
 
329
        self.view.show_app(self.app_mock)
 
330
        do_events()
 
331
        # ensure that the button is correct
 
332
        self.assertEqual(
 
333
            self.view.pkg_statusbar.button.get_label(), "Install Anyway")
 
334
        # and again for purchase
 
335
        self.app_mock.details.pkg_state = PkgStates.NEEDS_PURCHASE
 
336
        self.view.show_app(self.app_mock)
 
337
        self.assertEqual(
 
338
            self.view.pkg_statusbar.button.get_label(), 
 
339
            _(u"Buy Anyway\u2026").encode("utf-8"))
 
340
        # check if the warning bar is displayed
 
341
        self.assertTrue(self.view.pkg_warningbar.get_property("visible"))
 
342
        self.assertEqual(self.view.pkg_warningbar.label.get_text(),
 
343
                         REGION_WARNING_STRING)
204
344
 
205
345
 
206
346
class PurchasedAppDetailsStatusBarTestCase(unittest.TestCase):