~ubuntu-clock-dev/ubuntu-clock-app/reboot-packaging

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_clock_app/tests/__init__.py

  • Committer: carla-sella
  • Date: 2014-07-31 16:58:56 UTC
  • mto: (37.1.1 reboot)
  • mto: This revision was merged to the branch mainline in revision 50.
  • Revision ID: carla.sella@gmail.com-20140731165856-o2g4v4z7ivk9864v
Implemented locale.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
#
 
3
# Copyright (C) 2013, 2014 Canonical Ltd
 
4
#
 
5
# This program 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.
 
8
#
 
9
# This program 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.
 
13
#
 
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/>.
 
16
#
 
17
# Authored by: Renato Araujo Oliveira Filho <renato@canonical.com>
 
18
 
 
19
 
 
20
"""clock-app autopilot tests."""
 
21
 
 
22
import os.path
 
23
import os
 
24
import shutil
 
25
import logging
 
26
import locale
 
27
 
 
28
from autopilot import input
 
29
from autopilot.platform import model
 
30
from ubuntuuitoolkit import (
 
31
    base,
 
32
    emulators as toolkit_emulators
 
33
)
 
34
 
 
35
from ubuntu_clock_app import emulators
 
36
 
 
37
logger = logging.getLogger(__name__)
 
38
 
 
39
 
 
40
class ClockAppTestCase(base.UbuntuUIToolkitAppTestCase):
 
41
 
 
42
    """A common test case class that provides several useful methods for
 
43
    calendar-app tests.
 
44
 
 
45
    """
 
46
    local_location = "../../app/ubuntu-clock-app.qml"
 
47
    local_backend_dir = "../../builddir/backend/"
 
48
    installed_location = "/usr/share/ubuntu-clock-app/app/ubuntu-clock-app.qml"
 
49
    installed_backend_dir = "/usr/share/ubuntu-clock-app/builddir/backend/"
 
50
    sqlite_dir = os.path.expanduser(
 
51
        "~/.local/share/com.ubuntu.clock")
 
52
    backup_dir = sqlite_dir + ".backup"
 
53
 
 
54
    def setUp(self):
 
55
        super(ClockAppTestCase, self).setUp()
 
56
        self.pointing_device = input.Pointer(self.input_device_class.create())
 
57
 
 
58
        locale.setlocale(locale.LC_ALL, '')
 
59
 
 
60
        # backup and wipe db's before testing
 
61
        self.temp_move_sqlite_db()
 
62
        self.addCleanup(self.restore_sqlite_db)
 
63
 
 
64
        # turn off the OSK so it doesn't block screen elements
 
65
        if model() != 'Desktop':
 
66
            os.system("stop maliit-server")
 
67
            self.addCleanup(os.system, "start maliit-server")
 
68
 
 
69
        if os.path.exists(self.local_location):
 
70
            self.launch_test_local()
 
71
        elif os.path.exists(self.installed_location):
 
72
            self.launch_test_installed()
 
73
        else:
 
74
            self.launch_test_click()
 
75
 
 
76
    def launch_test_local(self):
 
77
        self.app = self.launch_test_application(
 
78
            base.get_qmlscene_launch_command(),
 
79
            self.local_location,
 
80
            "-I", self.local_backend_dir,
 
81
            app_type='qt',
 
82
            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
 
83
 
 
84
    def launch_test_installed(self):
 
85
        self.app = self.launch_test_application(
 
86
            base.get_qmlscene_launch_command(),
 
87
            self.installed_location,
 
88
            "-I", self.installed_backend_dir,
 
89
            app_type='qt',
 
90
            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
 
91
 
 
92
    def launch_test_click(self):
 
93
        self.app = self.launch_click_package(
 
94
            "com.ubuntu.clock.devel",
 
95
            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
 
96
 
 
97
    def temp_move_sqlite_db(self):
 
98
        try:
 
99
            shutil.rmtree(self.backup_dir)
 
100
        except:
 
101
            pass
 
102
        else:
 
103
            logger.warning("Prexisting backup database found and removed")
 
104
 
 
105
        try:
 
106
            shutil.move(self.sqlite_dir, self.backup_dir)
 
107
        except:
 
108
            logger.warning("No current database found")
 
109
        else:
 
110
            logger.debug("Backed up database")
 
111
 
 
112
    def restore_sqlite_db(self):
 
113
        if os.path.exists(self.backup_dir):
 
114
            if os.path.exists(self.sqlite_dir):
 
115
                try:
 
116
                    shutil.rmtree(self.sqlite_dir)
 
117
                except:
 
118
                    logger.error("Failed to remove test database and restore" /
 
119
                                 "database")
 
120
                    return
 
121
            try:
 
122
                shutil.move(self.backup_dir, self.sqlite_dir)
 
123
            except:
 
124
                logger.error("Failed to restore database")
 
125
 
 
126
    @property
 
127
    def main_view(self):
 
128
        return self.app.wait_select_single(emulators.MainView)