~ubuntu-branches/ubuntu/raring/software-center/raring-proposed

« back to all changes in this revision

Viewing changes to tests/gtk3/test_purchase.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2012-10-11 15:33:05 UTC
  • mfrom: (195.1.18 quantal)
  • Revision ID: package-import@ubuntu.com-20121011153305-fm5ln7if3rpzts4n
Tags: 5.4.1.1
* lp:~mvo/software-center/reinstall-previous-purchase-token-fix:
  - fix reinstall previous purchases that have a system-wide
    license key LP: #1065481
* lp:~mvo/software-center/lp1060106:
  - Add missing gettext init for utils/update-software-center-agent
    (LP: #1060106)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
from mock import Mock, patch
4
4
 
5
 
from gi.repository import Soup, WebKit
6
 
 
7
5
from tests.utils import (
8
6
    do_events_with_sleep,
9
7
    get_mock_options,
11
9
)
12
10
setup_test_env()
13
11
 
14
 
import softwarecenter.paths
15
 
 
16
12
from softwarecenter.ui.gtk3.views import purchaseview
17
13
from softwarecenter.ui.gtk3.app import SoftwareCenterAppGtk3
18
14
from softwarecenter.ui.gtk3.panes.availablepane import AvailablePane
21
17
 
22
18
class TestPurchase(unittest.TestCase):
23
19
 
24
 
    def test_have_cookie_jar(self):
25
 
        # ensure we have a cookie jar available
26
 
        session = WebKit.get_default_session()
27
 
        cookie_jars = [feature 
28
 
                for feature in  session.get_features(Soup.SessionFeature)
29
 
                if isinstance(feature, Soup.CookieJar)]
30
 
        self.assertEqual(len(cookie_jars), 1)
31
 
 
32
20
    def test_purchase_view_log_cleaner(self):
33
21
        win = get_test_window_purchaseview()
34
22
        self.addCleanup(win.destroy)
59
47
        view = win.get_data("view")
60
48
        # install the mock
61
49
        mock_config = Mock()
62
 
        mock_config.has_option.return_value = False
63
 
        mock_config.getboolean.return_value = False
 
50
        mock_config.user_accepted_tos = False
64
51
        view.config = mock_config
65
52
        func = "softwarecenter.ui.gtk3.views.purchaseview.show_accept_tos_dialog"
66
53
        with patch(func) as mock_func:
82
69
        do_events_with_sleep()
83
70
        self.assertTrue(signal_mock.called)
84
71
 
85
 
    def test_reinstall_previous_purchase_display(self):
 
72
 
 
73
class PreviousPurchasesTestCase(unittest.TestCase):
 
74
 
 
75
    @patch("softwarecenter.backend.ubuntusso.UbuntuSSO"
 
76
           ".find_oauth_token_sync")
 
77
    def test_reinstall_previous_purchase_display(self, mock_find_token):
 
78
        mock_find_token.return_value = { 'not': 'important' }
86
79
        mock_options = get_mock_options()
87
 
        xapiandb = "/var/cache/software-center/"
88
 
        app = SoftwareCenterAppGtk3(
89
 
            softwarecenter.paths.datadir, xapiandb, mock_options)
 
80
        app = SoftwareCenterAppGtk3(mock_options)
90
81
        self.addCleanup(app.destroy)
91
82
        # real app opens cache async
92
83
        app.cache.open()
93
 
        # no real sso
94
 
        with patch.object(app, '_login_via_dbus_sso',
95
 
                          lambda: app._available_for_me_result(None, [])):
96
 
            # show it
97
 
            app.window_main.show_all()
98
 
            app.available_pane.init_view()
 
84
        # .. and now pretend we clicked on the menu item
 
85
        app.window_main.show_all()
 
86
        app.available_pane.init_view()
 
87
        do_events_with_sleep()
 
88
        app.on_menuitem_reinstall_purchases_activate(None)
 
89
        # it can take a bit until the sso client is ready
 
90
        for i in range(10):
 
91
            if (app.available_pane.get_current_page() ==
 
92
                AvailablePane.Pages.LIST):
 
93
                break
99
94
            do_events_with_sleep()
100
 
            app.on_menuitem_reinstall_purchases_activate(None)
101
 
            # it can take a bit until the sso client is ready
102
 
            for i in range(100):
103
 
                if (app.available_pane.get_current_page() ==
104
 
                    AvailablePane.Pages.LIST):
105
 
                    break
106
 
                do_events_with_sleep()
107
 
            self.assertEqual(app.available_pane.get_current_page(),
108
 
                             AvailablePane.Pages.LIST)
 
95
        self.assertEqual(app.available_pane.get_current_page(),
 
96
                         AvailablePane.Pages.LIST)
109
97
 
110
98
 
111
99
if __name__ == "__main__":