881
899
self.test_on_volumes_info_ready_with_no_volumes()
902
class DeviceTestCase(ControlPanelMixinTestCase):
903
"""The test suite for the device widget."""
906
ui_filename = 'device.ui'
908
def assert_device_equal(self, device, expected):
909
"""Assert that the device has the values from expected."""
910
self.assertEqual(device.device_id.get_text(),
911
expected['device_id'])
912
self.assertEqual(device.device_name.get_text(),
913
expected['device_name'])
914
self.assertEqual(device.device_type.get_icon_name()[0],
915
expected['device_type'].lower())
916
self.assertEqual(device.configurable,
917
bool(expected['configurable']))
918
self.assertEqual(device.limit_bandwidth.get_active(),
919
bool(expected['limit_bandwidth']))
921
value = int(expected['max_upload_speed']) // gui.KILOBYTES
922
self.assertEqual(device.max_upload_speed.get_value_as_int(), value)
923
value = int(expected['max_download_speed']) // gui.KILOBYTES
924
self.assertEqual(device.max_download_speed.get_value_as_int(), value)
926
def assert_device_settings_changed(self):
927
"""Changing throttling settings updates the backend properly."""
928
expected = self.ui.__dict__
929
self.assert_backend_called('change_device_settings',
930
(self.ui.device_id.get_text(), expected))
931
self.assertEqual(self.ui.warning_label.get_text(), '')
933
def modify_settings(self):
934
"""Modify settings so values actually change."""
935
new_val = not self.ui.limit_bandwidth.get_active()
936
self.ui.limit_bandwidth.set_active(new_val)
938
new_val = self.ui.max_upload_speed.get_value_as_int() + 1
939
self.ui.max_upload_speed.set_value(new_val)
941
new_val = self.ui.max_download_speed.get_value_as_int() + 1
942
self.ui.max_download_speed.set_value(new_val)
944
def test_is_a_vbox(self):
945
"""Inherits from VBox."""
946
self.assertIsInstance(self.ui, gui.gtk.VBox)
948
def test_inner_widget_is_packed(self):
949
"""The 'itself' vbox is packed into the widget."""
950
self.assertIn(self.ui.itself, self.ui.get_children())
952
def test_is_visible(self):
954
self.assertTrue(self.ui.get_visible())
956
def test_is_sensitive(self):
958
self.assertTrue(self.ui.get_sensitive())
960
def test_warning_label_is_cleared(self):
961
"""The warning label is cleared."""
962
self.assertEqual(self.ui.warning_label.get_text(), '')
964
def test_device_id_is_hidden(self):
965
"""The device id label is hidden."""
966
self.assertFalse(self.ui.device_id.get_visible())
968
def test_default_values(self):
969
"""Default values are correct."""
970
self.assertEqual(self.ui.device_id.get_text(), '')
971
self.assertEqual(self.ui.device_name.get_text(), '')
972
self.assertEqual(self.ui.device_type.get_icon_name()[0],
973
gui.DEVICE_TYPE_COMPUTER.lower())
974
self.assertEqual(self.ui.configurable, False)
975
self.assertEqual(self.ui.limit_bandwidth.get_active(), False)
976
self.assertEqual(self.ui.max_upload_speed.get_value_as_int(), 0)
977
self.assertEqual(self.ui.max_download_speed.get_value_as_int(), 0)
979
def test_init_does_not_call_backend(self):
980
"""When updating, the backend is not called."""
981
self.assertEqual(self.ui.backend._called, {})
983
def test_update_device_id(self):
984
"""A device can be updated from a dict."""
985
value = '741-822-963'
986
self.ui.update(device_id=value)
987
self.assertEqual(value, self.ui.device_id.get_text())
989
def test_update_device_name(self):
990
"""A device can be updated from a dict."""
991
value = 'The death star'
992
self.ui.update(device_name=value)
993
self.assertEqual(value, self.ui.device_name.get_text())
995
def test_update_unicode_device_name(self):
996
"""A device can be updated from a dict."""
997
value = u'Ñoño Ñandú'
998
self.ui.update(device_name=value)
999
self.assertEqual(value, self.ui.device_name.get_text())
1001
def test_update_device_type_computer(self):
1002
"""A device can be updated from a dict."""
1003
dtype = gui.DEVICE_TYPE_COMPUTER
1004
self.ui.update(device_type=dtype)
1005
self.assertEqual((dtype.lower(), gui.gtk.ICON_SIZE_BUTTON),
1006
self.ui.device_type.get_icon_name())
1008
def test_update_device_type_phone(self):
1009
"""A device can be updated from a dict."""
1010
dtype = gui.DEVICE_TYPE_PHONE
1011
self.ui.update(device_type=dtype)
1012
self.assertEqual((dtype.lower(), gui.gtk.ICON_SIZE_BUTTON),
1013
self.ui.device_type.get_icon_name())
1015
def test_update_configurable(self):
1016
"""A device can be updated from a dict."""
1017
self.ui.update(configurable='')
1018
self.assertFalse(self.ui.configurable)
1019
self.assertFalse(self.ui.throttling.get_visible())
1021
def test_update_non_configurable(self):
1022
"""A device can be updated from a dict."""
1023
self.ui.update(configurable='True')
1024
self.assertTrue(self.ui.configurable)
1025
self.assertTrue(self.ui.throttling.get_visible())
1027
def test_update_limit_bandwidth(self):
1028
"""A device can be updated from a dict."""
1029
self.ui.update(limit_bandwidth='')
1030
self.assertFalse(self.ui.limit_bandwidth.get_active())
1032
self.ui.update(limit_bandwidth='True')
1033
self.assertTrue(self.ui.limit_bandwidth.get_active())
1035
def test_update_upload_speed(self):
1036
"""A device can be updated from a dict."""
1038
self.ui.update(max_upload_speed=value)
1039
self.assertEqual(int(value) // gui.KILOBYTES,
1040
self.ui.max_upload_speed.get_value_as_int())
1042
def test_update_download_speed(self):
1043
"""A device can be updated from a dict."""
1045
self.ui.update(max_download_speed=value)
1046
self.assertEqual(int(value) // gui.KILOBYTES,
1047
self.ui.max_download_speed.get_value_as_int())
1049
def test_update_does_not_call_backend(self):
1050
"""When updating, the backend is not called."""
1051
self.ui.update(**FAKE_DEVICE_INFO)
1052
self.assertEqual(self.ui.backend._called, {})
1053
self.assert_device_equal(self.ui, FAKE_DEVICE_INFO)
1055
def test_on_limit_bandwidth_toggled(self):
1056
"""When toggling limit_bandwidth, backend is updated."""
1057
self.ui.limit_bandwidth.toggled()
1058
self.assert_device_settings_changed()
1060
def test_on_max_upload_speed_value_changed(self):
1061
"""When setting max_upload_speed, backend is updated."""
1062
self.ui.max_upload_speed.set_value(25)
1063
self.assert_device_settings_changed()
1065
def test_on_max_download_speed_value_changed(self):
1066
"""When setting max_download_speed, backend is updated."""
1067
self.ui.max_download_speed.set_value(52)
1068
self.assert_device_settings_changed()
1070
def test_backend_signals(self):
1071
"""The proper signals are connected to the backend."""
1072
self.assertEqual(self.ui.backend._signals['DeviceSettingsChanged'],
1073
[self.ui.on_device_settings_changed])
1074
self.assertEqual(self.ui.backend._signals['DeviceSettingsChangeError'],
1075
[self.ui.on_device_settings_change_error])
1077
def test_on_device_settings_changed(self):
1078
"""When settings were changed for this device, enable it."""
1079
self.modify_settings()
1080
did = self.ui.device_id.get_text()
1081
self.ui.on_device_settings_changed(device_id=did)
1083
self.assertTrue(self.ui.get_sensitive())
1084
self.assertEqual(self.ui.warning_label.get_text(), '')
1085
self.assertEqual(self.ui.__dict__, self.ui._last_settings)
1087
def test_on_device_settings_change_after_error(self):
1088
"""Change success after error."""
1089
self.modify_settings()
1090
did = self.ui.device_id.get_text()
1091
self.ui.on_device_settings_change_error(device_id=did) # change failed
1093
self.test_on_device_settings_changed()
1095
def test_on_device_settings_changed_different_id(self):
1096
"""When settings were changed for other device, nothing changes."""
1097
self.modify_settings()
1098
self.ui.on_device_settings_changed(device_id='yadda')
1100
self.assertEqual(self.ui.warning_label.get_text(), '')
1102
def test_on_device_settings_change_error(self):
1103
"""When settings were not changed for this device, notify the user.
1105
Also, confirm that old values were restored.
1108
self.ui.update(**FAKE_DEVICE_INFO) # use known values
1110
self.modify_settings()
1112
did = self.ui.device_id.get_text()
1113
self.ui.on_device_settings_change_error(device_id=did) # change failed
1115
self.assertTrue(self.ui.get_sensitive())
1116
self.assert_warning_correct(self.ui.warning_label,
1117
self.ui.DEVICE_CHANGE_ERROR)
1118
self.assert_device_equal(self.ui, FAKE_DEVICE_INFO) # restored info
1120
def test_on_device_settings_change_error_after_success(self):
1121
"""Change error after success."""
1122
self.modify_settings()
1123
did = self.ui.device_id.get_text()
1124
self.ui.on_device_settings_changed(device_id=did)
1126
self.test_on_device_settings_change_error()
1128
def test_on_device_settings_change_error_different_id(self):
1129
"""When settings were not changed for other device, do nothing."""
1130
self.modify_settings()
1131
self.ui.on_device_settings_change_error(device_id='yudo')
1132
self.assertEqual(self.ui.warning_label.get_text(), '')
884
1135
class DevicesTestCase(ControlPanelMixinTestCase):
885
1136
"""The test suite for the devices panel."""
899
1150
"""Is visible."""
900
1151
self.assertTrue(self.ui.get_visible())
1153
def test_backend_signals(self):
1154
"""The proper signals are connected to the backend."""
1155
self.assertEqual(self.ui.backend._signals['DevicesInfoReady'],
1156
[self.ui.on_devices_info_ready])
1157
self.assertEqual(self.ui.backend._signals['DevicesInfoError'],
1158
[self.ui.on_devices_info_error])
1160
def test_devices_info_is_requested(self):
1161
"""The devices info is requested to the backend."""
1162
self.assert_backend_called('devices_info', ())
1164
def test_on_devices_info_ready(self):
1165
"""The devices info is processed when ready."""
1166
self.ui.on_devices_info_ready(FAKE_DEVICES_INFO)
1168
children = self.ui.devices.get_children()
1169
self.assertEqual(len(children), len(FAKE_DEVICES_INFO))
1171
for child, device in zip(children, FAKE_DEVICES_INFO):
1172
self.assertIsInstance(child, gui.Device)
1174
self.assertEqual(device['device_id'],
1175
child.device_id.get_text())
1176
self.assertEqual(device['device_name'],
1177
child.device_name.get_text())
1178
self.assertEqual(device['device_type'].lower(),
1179
child.device_type.get_icon_name()[0])
1180
self.assertEqual(bool(device['configurable']),
1183
if bool(device['configurable']):
1184
self.assertEqual(bool(device['limit_bandwidth']),
1185
child.limit_bandwidth.get_active())
1186
value = int(device['max_upload_speed']) // gui.KILOBYTES
1187
self.assertEqual(value,
1188
child.max_upload_speed.get_value_as_int())
1189
value = int(device['max_download_speed']) // gui.KILOBYTES
1190
self.assertEqual(value,
1191
child.max_download_speed.get_value_as_int())
1193
def test_on_devices_info_error(self):
1194
"""The devices info couldn't be retrieved."""
1195
self.ui.on_devices_info_error()
903
1198
class ApplicationsTestCase(ControlPanelMixinTestCase):
904
1199
"""The test suite for the applications panel."""