~ubuntu-branches/ubuntu/quantal/ubuntuone-control-panel/quantal

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2012-08-29 14:55:29 UTC
  • mfrom: (1.1.37)
  • Revision ID: package-import@ubuntu.com-20120829145529-14mpq0u1ql7dx67l
Tags: 3.99.90-0ubuntu1
* New upstream release.
  - Adding functionality to the Share Links Tab.
  - Fixed saving/restoring the speed throttling (LP: #1040899)
  - Other fixes for darwin port.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU General Public License along
15
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
 
"""Tests for the account tab."""
 
17
"""Tests for the Share Links tab."""
 
18
 
 
19
import os
 
20
 
 
21
from PyQt4 import QtGui, QtCore
18
22
 
19
23
from ubuntuone.controlpanel.gui import (
20
24
    SEARCH_FILES,
21
25
    SHARED_FILES,
22
26
)
 
27
from ubuntuone.controlpanel.gui.tests import USER_HOME
23
28
from ubuntuone.controlpanel.gui.qt import share_links as gui
24
 
from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase
25
 
 
 
29
from ubuntuone.controlpanel.gui.qt.tests import (
 
30
    BaseTestCase,
 
31
    FakeDesktopService,
 
32
)
 
33
 
 
34
 
 
35
# pylint: disable=W0212
26
36
 
27
37
class ShareLinksTestCase(BaseTestCase):
28
38
    """Test the qt control panel."""
35
45
        """Check that the strings are properly setted."""
36
46
        self.assertEqual(self.ui.ui.search_files_lbl.text(), SEARCH_FILES)
37
47
        self.assertEqual(self.ui.ui.shared_group.title(), SHARED_FILES)
 
48
        self.assertIsInstance(self.ui._enhanced_line, gui.EnhancedLineEdit)
 
49
        self.assertEqual(self.ui._enhanced_line.btn_operation.text(), '')
 
50
        self.assertFalse(self.ui._enhanced_line.btn_operation.isVisible())
 
51
 
 
52
    def test_share_file(self):
 
53
        """Check that the state of the widgets on share_file."""
 
54
        path = '/home/user/Ubuntu One/file1.txt'
 
55
        self.ui.share_file(path)
 
56
        self.assertTrue(self.ui.is_processing)
 
57
        widget = self.ui.ui.hbox_share_file.takeAt(0).widget()
 
58
        self.assertIsInstance(widget, gui.ShareFileWidget)
 
59
        self.assertEqual(widget.ui.lbl_filename.text(),
 
60
            os.path.basename(path))
 
61
        self.assertEqual(widget.ui.lbl_path.text(), path)
 
62
 
 
63
    def test_share_file_actions(self):
 
64
        """Check the behaviour of share_file buttons."""
 
65
        path = '/home/user/Ubuntu One/file1.txt'
 
66
        self.ui.share_file(path)
 
67
        widget = self.ui.ui.hbox_share_file.takeAt(0).widget()
 
68
        self.ui.ui.line_copy_link.setText('link')
 
69
        self.assertEqual(self.ui.ui.line_copy_link.text(), 'link')
 
70
        widget.linkDisabled.emit()
 
71
        self.assertNotEqual(self.ui.ui.line_copy_link.text(), 'link')
 
72
 
 
73
    def test_file_shared(self):
 
74
        """Check the behavior of the widgets after the file is shared."""
 
75
        info = {'public_url': 'http://ubuntuone.com/asd123'}
 
76
        self.ui._file_shared(info)
 
77
        self.assertEqual(self.ui.ui.line_copy_link.text(), info['public_url'])
 
78
        self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1)
 
79
        self.assertFalse(self.ui.is_processing)
 
80
 
 
81
    def test_open_in_browser(self):
 
82
        """Test the execution of open_in_browser."""
 
83
        fake_desktop_service = FakeDesktopService()
 
84
        self.patch(QtGui, "QDesktopServices", fake_desktop_service)
 
85
        url = 'http://ubuntuone.com/asd123'
 
86
        self.ui.ui.line_copy_link.setText(url)
 
87
        self.ui._open_in_browser()
 
88
        expected = QtCore.QUrl(url)
 
89
        self.assertEqual(expected, fake_desktop_service.opened_url)
 
90
 
 
91
    def test_copy_link_from_line(self):
 
92
        """Test the execution of copy_link_from_line."""
 
93
        url = 'http://ubuntuone.com/asd123'
 
94
        self.ui.ui.line_copy_link.setText(url)
 
95
        self.ui._copy_link_from_line()
 
96
        clip = QtGui.QApplication.instance().clipboard()
 
97
        self.assertEqual(url, clip.text())
 
98
 
 
99
    def test_move_to_main_list(self):
 
100
        """Test that the stacked widget shows the proper index."""
 
101
        self.ui._move_to_main_list()
 
102
        self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 0)
 
103
 
 
104
    def test_get_public_files(self):
 
105
        """Test that the proper actions are executed on files requested.."""
 
106
        self.ui.get_public_files()
 
107
        self.assertTrue(self.ui.is_processing)
 
108
        self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 0)
 
109
        self.assertEqual(self.ui.home_dir, USER_HOME)
 
110
 
 
111
    def test_line_close_btn(self):
 
112
        """Check that the popup is hidden."""
 
113
        self.ui.ui.line_search.popup.show()
 
114
        self.addCleanup(self.ui.ui.line_search.popup.hide)
 
115
        self.ui._line_close_btn()
 
116
        self.assertFalse(self.ui.ui.line_search.popup.isVisible())
 
117
 
 
118
    def test_hide_line_btn_close_hide(self):
 
119
        """Check the state of the inline button."""
 
120
        self.ui._enhanced_line.btn_operation.show()
 
121
        self.ui.ui.line_search.popup.popupHidden.emit()
 
122
        self.assertFalse(self.ui._enhanced_line.btn_operation.isVisible())
 
123
 
 
124
    def test_hide_line_btn_close_show(self):
 
125
        """Check the state of the inline button."""
 
126
        self.ui.ui.line_search.popup.popupShown.emit()
 
127
        self.assertTrue(self.ui._enhanced_line.btn_operation.isVisible())
 
128
 
 
129
    def test_load_public_files(self):
 
130
        """Test if the list of public files is loaded properly."""
 
131
        publicfiles = [
 
132
            {'path': '/home/file1', 'public_url': 'http:ubuntuone.com/asd123'},
 
133
            {'path': '/home/file2', 'public_url': 'http:ubuntuone.com/qwe456'},
 
134
        ]
 
135
        self.ui._load_public_files(publicfiles)
 
136
        item = self.ui.ui.tree_shared_files.topLevelItem(0)
 
137
        self.assertEqual(item.text(0), os.path.basename('/home/file1'))
 
138
        self.assertEqual(item.toolTip(0), '/home/file1')
 
139
        label = self.ui.ui.tree_shared_files.itemWidget(item, 1)
 
140
        link = ('<a href="%s"><span style="font-size: 12px;'
 
141
                'color: #dd4814";>%s</span></a>'
 
142
                % ('http:ubuntuone.com/asd123', 'http:ubuntuone.com/asd123'))
 
143
        self.assertEqual(link, label.text())
 
144
        actions = self.ui.ui.tree_shared_files.itemWidget(item, 2)
 
145
        self.assertIsInstance(actions, gui.ActionsButtons)
 
146
 
 
147
        item = self.ui.ui.tree_shared_files.topLevelItem(1)
 
148
        self.assertEqual(item.text(0), os.path.basename('/home/file2'))
 
149
        self.assertEqual(item.toolTip(0), '/home/file2')
 
150
        label = self.ui.ui.tree_shared_files.itemWidget(item, 1)
 
151
        link = ('<a href="%s"><span style="font-size: 12px;'
 
152
                'color: #dd4814";>%s</span></a>'
 
153
                % ('http:ubuntuone.com/qwe456', 'http:ubuntuone.com/qwe456'))
 
154
        self.assertEqual(link, label.text())
 
155
        actions = self.ui.ui.tree_shared_files.itemWidget(item, 2)
 
156
        self.assertIsInstance(actions, gui.ActionsButtons)
 
157
 
 
158
 
 
159
class ActionsButtonsTestCase(BaseTestCase):
 
160
    """Test the Actions Buttons."""
 
161
 
 
162
    def test_open(self):
 
163
        """Test the open method."""
 
164
        path = '/home/file1'
 
165
        link = 'http://ubuntuone.com/asd123'
 
166
        actions = gui.ActionsButtons(path, link)
 
167
        fake_desktop_service = FakeDesktopService()
 
168
        self.patch(QtGui, "QDesktopServices", fake_desktop_service)
 
169
        actions.open()
 
170
        file_path = QtCore.QUrl(u'file://%s' % path)
 
171
        self.assertEqual(file_path, fake_desktop_service.opened_url)
 
172
 
 
173
    def test_copy(self):
 
174
        """Test that the link is copied into the clipboard.."""
 
175
        path = '/home/file1'
 
176
        link = 'http://ubuntuone.com/asd123'
 
177
        actions = gui.ActionsButtons(path, link)
 
178
        fake_desktop_service = FakeDesktopService()
 
179
        self.patch(QtGui, "QDesktopServices", fake_desktop_service)
 
180
        actions.copy()
 
181
        clip = QtGui.QApplication.instance().clipboard()
 
182
        self.assertEqual(link, clip.text())
 
183
 
 
184
 
 
185
class EnhancedLineEditTestCase(BaseTestCase):
 
186
    """Test the EnhancedLineEdit."""
 
187
 
 
188
    def test_initialize(self):
 
189
        """Test initialization."""
 
190
        line = QtGui.QLineEdit()
 
191
        enhanced = gui.EnhancedLineEdit(line, self._set_called, 'text')
 
192
        self.assertEqual(line.layout().count(), 2)
 
193
        self.assertFalse(self._called)
 
194
        enhanced.btn_operation.click()
 
195
        self.assertEqual(self._called, ((False, ), {}))