~dobey/ubuntu/oneiric/ubuntuone-control-panel/release-113

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/gui/qt/tests/test_account.py

  • Committer: Sebastien Bacher
  • Date: 2011-07-25 13:17:38 UTC
  • mfrom: (25.1.2 ubuntuone-control-panel)
  • Revision ID: seb128@ubuntu.com-20110725131738-yuevatnd859d1phs
Tags: 1.1.1-0ubuntu1
releasing version 1.1.1-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Author: Alejandro J. Cura <alecu@canonical.com>
 
4
#
 
5
# Copyright 2011 Canonical Ltd.
 
6
#
 
7
# This program is free software: you can redistribute it and/or modify it
 
8
# under the terms of the GNU General Public License version 3, as published
 
9
# by the Free Software Foundation.
 
10
#
 
11
# This program is distributed in the hope that it will be useful, but
 
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
14
# PURPOSE.  See the GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License along
 
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
"""Tests for the account tab."""
 
20
 
 
21
from twisted.internet import defer
 
22
 
 
23
from ubuntuone.controlpanel.gui import qt
 
24
from ubuntuone.controlpanel.gui.qt import account as gui
 
25
from ubuntuone.controlpanel.gui.qt.tests import (
 
26
    SAMPLE_ACCOUNT_INFO, SAMPLE_EMAIL, SAMPLE_NAME, SAMPLE_PLAN,
 
27
)
 
28
from ubuntuone.controlpanel.gui.qt.tests.test_ubuntuonebin import (
 
29
    UbuntuOneBinTestCase,
 
30
)
 
31
 
 
32
 
 
33
class AccountPanelTestCase(UbuntuOneBinTestCase):
 
34
    """Test the qt control panel."""
 
35
 
 
36
    innerclass_ui = gui.account_ui
 
37
    innerclass_name = "Ui_Form"
 
38
    class_ui = gui.AccountPanel
 
39
 
 
40
    @defer.inlineCallbacks
 
41
    def setUp(self):
 
42
        yield super(AccountPanelTestCase, self).setUp()
 
43
        self.ui.backend.next_result = SAMPLE_ACCOUNT_INFO
 
44
 
 
45
    def test_is_processing_while_asking_info(self):
 
46
        """The ui is processing while the contents are loaded."""
 
47
        def check():
 
48
            """The ui must be is_processing."""
 
49
            self.assertTrue(self.ui.is_processing, 'ui must be processing')
 
50
            return SAMPLE_ACCOUNT_INFO
 
51
 
 
52
        self.patch(self.ui.backend, 'account_info', check)
 
53
 
 
54
        return self.ui.load()  # trigger the info request
 
55
 
 
56
    def test_is_not_processing_after_info_ready(self):
 
57
        """The ui is not processing when contents are load."""
 
58
        self.ui.process_info(SAMPLE_ACCOUNT_INFO)
 
59
 
 
60
        self.assertFalse(self.ui.is_processing)
 
61
 
 
62
    @defer.inlineCallbacks
 
63
    def test_info_is_requested_on_load(self):
 
64
        """The info is requested to the backend."""
 
65
        yield self.ui.load()
 
66
        self.assert_backend_called('account_info')
 
67
 
 
68
    def test_process_info(self):
 
69
        """The info is processed when ready."""
 
70
        self.ui.process_info(SAMPLE_ACCOUNT_INFO)
 
71
        self.assertEqual(self.ui.ui.name_label.text(), SAMPLE_NAME)
 
72
        self.assertEqual(self.ui.ui.email_label.text(), SAMPLE_EMAIL)
 
73
        self.assertEqual(self.ui.ui.services_description_label.text(),
 
74
                         SAMPLE_PLAN)
 
75
 
 
76
    def test_edit_account_button(self):
 
77
        """When clicking the edit account button, the proper url is opened."""
 
78
        self.patch(qt, 'uri_hook', self._set_called)
 
79
        self.ui.ui.edit_profile_button.click()
 
80
 
 
81
        self.assertEqual(self._called, ((gui.EDIT_PROFILE_LINK,), {}))
 
82
 
 
83
    def test_edit_services_button(self):
 
84
        """When clicking the mobile plan button, the proper url is opened."""
 
85
        self.patch(qt, 'uri_hook', self._set_called)
 
86
        self.ui.ui.edit_services_button.click()
 
87
 
 
88
        self.assertEqual(self._called, ((gui.EDIT_ACCOUNT_LINK,), {}))