1
# Copyright (C) 2014 Canonical Ltd
3
# This file is part of Ubuntu Clock App
5
# Ubuntu Clock App is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License version 3 as
7
# published by the Free Software Foundation.
9
# Ubuntu Clock App is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
"""clock-app autopilot tests."""
25
from autopilot import input
26
from autopilot.platform import model
27
from ubuntuuitoolkit import (
29
emulators as toolkit_emulators
32
from ubuntu_clock_app import emulators
34
logger = logging.getLogger(__name__)
37
class ClockAppTestCase(base.UbuntuUIToolkitAppTestCase):
39
"""A common test case class that provides several useful methods for
43
local_location = "../../app/ubuntu-clock-app.qml"
44
local_backend_dir = "../../builddir/backend/"
45
installed_location = "/usr/share/ubuntu-clock-app/app/ubuntu-clock-app.qml"
46
installed_backend_dir = "/usr/share/ubuntu-clock-app/builddir/backend/"
47
sqlite_dir = os.path.expanduser(
48
"~/.local/share/com.ubuntu.clock")
49
backup_dir = sqlite_dir + ".backup"
52
super(ClockAppTestCase, self).setUp()
53
self.pointing_device = input.Pointer(self.input_device_class.create())
55
self.useFixture(fixtures.EnvironmentVariable('LC_ALL', newvalue='C'))
57
# backup and wipe db's before testing
58
self.temp_move_sqlite_db()
59
self.addCleanup(self.restore_sqlite_db)
61
# turn off the OSK so it doesn't block screen elements
62
if model() != 'Desktop':
63
os.system("stop maliit-server")
64
self.addCleanup(os.system, "start maliit-server")
66
if os.path.exists(self.local_location):
67
self.launch_test_local()
68
elif os.path.exists(self.installed_location):
69
self.launch_test_installed()
71
self.launch_test_click()
73
def launch_test_local(self):
74
self.app = self.launch_test_application(
75
base.get_qmlscene_launch_command(),
77
"-I", self.local_backend_dir,
79
emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
81
def launch_test_installed(self):
82
self.app = self.launch_test_application(
83
base.get_qmlscene_launch_command(),
84
self.installed_location,
85
"-I", self.installed_backend_dir,
87
emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
89
def launch_test_click(self):
90
self.app = self.launch_click_package(
91
"com.ubuntu.clock.devel",
92
emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
94
def temp_move_sqlite_db(self):
96
shutil.rmtree(self.backup_dir)
100
logger.warning("Prexisting backup database found and removed")
103
shutil.move(self.sqlite_dir, self.backup_dir)
105
logger.warning("No current database found")
107
logger.debug("Backed up database")
109
def restore_sqlite_db(self):
110
if os.path.exists(self.backup_dir):
111
if os.path.exists(self.sqlite_dir):
113
shutil.rmtree(self.sqlite_dir)
115
logger.error("Failed to remove test database and restore" /
119
shutil.move(self.backup_dir, self.sqlite_dir)
121
logger.error("Failed to restore database")
125
return self.app.wait_select_single(emulators.MainView)