/usr/lib/python2.7/dist-packages/ubuntu_system_settings/tests/__init__.py is in ubuntu-system-settings-autopilot 0.1+14.04.20140411-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright 2013 Canonical
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
""" Tests for Ubuntu System Settings """
from __future__ import absolute_import
from ubuntu_system_settings import helpers
from autopilot.input import Mouse, Touch, Pointer
from autopilot.platform import model
from autopilot.matchers import Eventually
from testtools.matchers import Equals, NotEquals, GreaterThan
from ubuntuuitoolkit.base import UbuntuUIToolkitAppTestCase
from ubuntuuitoolkit import emulators as toolkit_emulators
import dbus
import dbusmock
import subprocess
from time import sleep
class UbuntuSystemSettingsTestCase(UbuntuUIToolkitAppTestCase):
""" Base class for Ubuntu System Settings """
if model() == 'Desktop':
scenarios = [('with mouse', dict(input_device_class=Mouse))]
else:
scenarios = [('with touch', dict(input_device_class=Touch))]
def setUp(self, panel=None):
super(UbuntuSystemSettingsTestCase, self).setUp()
self.app = helpers.launch_system_settings(self, panel=panel)
self.assertThat(self.main_view.visible, Eventually(Equals(True)))
@property
def main_view(self):
""" Return main view """
return self.app.select_single("QQuickView")
@property
def pointer(self):
""" Return pointer """
return Pointer(self.input_device_class.create())
def scroll_to(self, obj):
self.app.select_single(toolkit_emulators.Toolbar).close()
page = self.main_view.select_single(objectName='systemSettingsPage')
page_right = page.globalRect[0] + page.globalRect[2]
page_bottom = page.globalRect[1] + page.globalRect[3]
page_center_x = int(page_right / 2)
page_center_y = int(page_bottom / 2)
while obj.globalRect[1] + obj.height > page_bottom:
self.pointer.drag(page_center_x, page_center_y,
page_center_x, page_center_y - obj.height * 2)
# avoid a flick
sleep(0.5)
def scroll_to_and_click(self, obj):
self.scroll_to(obj)
self.pointer.click_object(obj)
class UbuntuSystemSettingsUpowerTestCase(UbuntuSystemSettingsTestCase,
dbusmock.DBusTestCase):
@classmethod
def setUpClass(klass):
klass.start_system_bus()
klass.dbus_con = klass.get_dbus(True)
# Add a mock Upower environment so we get consistent results
(klass.p_mock, klass.obj_upower) = klass.spawn_server_template(
'upower', {'OnBattery': True}, stdout=subprocess.PIPE)
klass.dbusmock = dbus.Interface(klass.obj_upower, dbusmock.MOCK_IFACE)
def setUp(self, panel=None):
self.obj_upower.Reset()
super(UbuntuSystemSettingsUpowerTestCase, self).setUp()
def add_mock_battery(self):
""" Make sure we have a battery """
self.dbusmock.AddDischargingBattery(
'mock_BATTERY', 'Battery', 50.0, 10
)
class UbuntuSystemSettingsBatteryTestCase(UbuntuSystemSettingsUpowerTestCase):
""" Base class for tests which rely on the presence of a battery """
def setUp(self):
super(UbuntuSystemSettingsBatteryTestCase, self).setUp()
self.add_mock_battery()
self.app = helpers.launch_system_settings(self)
self.assertThat(self.main_view.visible, Eventually(Equals(True)))
class UbuntuSystemSettingsOfonoTestCase(UbuntuSystemSettingsTestCase,
dbusmock.DBusTestCase):
""" Class for cellular tests which sets up an Ofono mock """
@classmethod
def setUpClass(klass):
klass.start_system_bus()
klass.dbus_con = klass.get_dbus(True)
# Add a mock Ofono environment so we get consistent results
(klass.p_mock, klass.obj_ofono) = klass.spawn_server_template(
'ofono', stdout=subprocess.PIPE)
klass.dbusmock = dbus.Interface(klass.obj_ofono, dbusmock.MOCK_IFACE)
def setUp(self, panel=None):
self.obj_ofono.Reset()
# Add an available carrier
self.dbusmock.AddObject(
'/ril_0/operator/op2',
'org.ofono.NetworkOperator',
{
'Name': 'my.cool.telco',
'Status': 'available',
'MobileCountryCode': '777',
'MobileNetworkCode': '22',
'Technologies': ['gsm'],
},
[
('GetProperties', '', 'a{sv}',
'ret = self.GetAll("org.ofono.NetworkOperator")'),
('Register', '', '', ''),
]
)
# Add a forbidden carrier
self.dbusmock.AddObject(
'/ril_0/operator/op3',
'org.ofono.NetworkOperator',
{
'Name': 'my.bad.telco',
'Status': 'forbidden',
'MobileCountryCode': '777',
'MobileNetworkCode': '22',
'Technologies': ['gsm'],
},
[
('GetProperties', '', 'a{sv}',
'ret = self.GetAll("org.ofono.NetworkOperator")'),
('Register', '', '', ''),
]
)
super(UbuntuSystemSettingsOfonoTestCase, self).setUp('cellular')
@property
def cellular_page(self):
""" Returns 'About' page """
return self.main_view.select_single(objectName='cellularPage')
@property
def choose_page(self):
return self.main_view.select_single(objectName="chooseCarrierPage")
class AboutBaseTestCase(UbuntuSystemSettingsTestCase):
""" Base class for About this phone tests """
def setUp(self):
""" Go to About page """
super(AboutBaseTestCase, self).setUp('about')
self.assertThat(self.about_page.active, Eventually(Equals(True)))
@property
def about_page(self):
""" Returns 'About' page """
return self.main_view.select_single(objectName='aboutPage')
class StorageBaseTestCase(AboutBaseTestCase):
""" Base class for Storage page tests """
def setUp(self):
""" Go to Storage Page """
super(StorageBaseTestCase, self).setUp()
# Click on 'Storage' option
button = self.about_page.select_single(
'Standard', objectName='storageItem'
)
self.scroll_to_and_click(button)
self.assertThat(self.storage_page.active, Eventually(Equals(True)))
def assert_space_item(self, object_name, text):
""" Checks whether an space item exists and returns a value """
item = self.storage_page.select_single(objectName=object_name)
self.assertThat(item, NotEquals(None))
label = item.label # Label
self.assertThat(label, Equals(text))
# Get item's label
size_label = item.select_single(objectName='sizeLabel')
self.assertThat(size_label, NotEquals(None))
values = size_label.text.split(' ') # Format: "00.0 (bytes|MB|GB)"
self.assertThat(len(values), GreaterThan(1))
def get_storage_space_used_by_category(self, objectName):
return self.main_view.wait_select_single(
'StorageItem', objectName=objectName
).value
@property
def storage_page(self):
""" Return 'Storage' page """
return self.main_view.select_single(
'Storage', objectName='storagePage'
)
class LicenseBaseTestCase(AboutBaseTestCase):
""" Base class for Licenses page tests """
def setUp(self):
""" Go to License Page """
super(LicenseBaseTestCase, self).setUp()
# Click on 'Software licenses' option
button = self.main_view.select_single(
'Standard', objectName='licenseItem'
)
self.scroll_to_and_click(button)
@property
def licenses_page(self):
""" Return 'License' page """
return self.main_view.wait_select_single(
'ItemPage', objectName='licensesPage'
)
class SystemUpdatesBaseTestCase(UbuntuSystemSettingsTestCase):
""" Base class for SystemUpdates page tests """
def setUp(self):
""" Go to SystemUpdates Page """
super(SystemUpdatesBaseTestCase, self).setUp()
# Click on 'System Updates' option
button = self.main_view.select_single(
objectName='entryComponent-system-update')
self.assertThat(button, NotEquals(None))
self.scroll_to_and_click(button)
@property
def updates_page(self):
""" Return 'System Update' page """
return self.main_view.select_single(objectName='systemUpdatesPage')
|