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())
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)
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')
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)
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)
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())
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)
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)
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())
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())
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())
129
def test_load_public_files(self):
130
"""Test if the list of public files is loaded properly."""
132
{'path': '/home/file1', 'public_url': 'http:ubuntuone.com/asd123'},
133
{'path': '/home/file2', 'public_url': 'http:ubuntuone.com/qwe456'},
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)
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)
159
class ActionsButtonsTestCase(BaseTestCase):
160
"""Test the Actions Buttons."""
163
"""Test the open method."""
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)
170
file_path = QtCore.QUrl(u'file://%s' % path)
171
self.assertEqual(file_path, fake_desktop_service.opened_url)
174
"""Test that the link is copied into the clipboard.."""
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)
181
clip = QtGui.QApplication.instance().clipboard()
182
self.assertEqual(link, clip.text())
185
class EnhancedLineEditTestCase(BaseTestCase):
186
"""Test the EnhancedLineEdit."""
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, ), {}))