14
import softwarecenter.paths
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
22
18
class TestPurchase(unittest.TestCase):
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)
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")
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)
85
def test_reinstall_previous_purchase_display(self):
73
class PreviousPurchasesTestCase(unittest.TestCase):
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
94
with patch.object(app, '_login_via_dbus_sso',
95
lambda: app._available_for_me_result(None, [])):
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
91
if (app.available_pane.get_current_page() ==
92
AvailablePane.Pages.LIST):
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
103
if (app.available_pane.get_current_page() ==
104
AvailablePane.Pages.LIST):
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)
111
99
if __name__ == "__main__":