~rpadovani/ubuntu-calculator-app/improveDate150105

« back to all changes in this revision

Viewing changes to app/tests/autopilot/ubuntu_calculator_app/tests/__init__.py

  • Committer: Riccardo Padovani
  • Date: 2014-12-20 23:29:00 UTC
  • mfrom: (41.1.1 reboot)
  • Revision ID: rpadovani@ubuntu.com-20141220232900-trr5f7g09w6w94d5
Ported autopilot suite from old app.

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
"""Calculator app autopilot tests."""
 
18
 
 
19
import os
 
20
import shutil
 
21
import logging
 
22
 
 
23
import ubuntu_calculator_app
 
24
 
 
25
from autopilot.testcase import AutopilotTestCase
 
26
from autopilot import logging as autopilot_logging
 
27
 
 
28
import ubuntuuitoolkit
 
29
from ubuntuuitoolkit import base
 
30
 
 
31
logger = logging.getLogger(__name__)
 
32
 
 
33
 
 
34
class CalculatorAppTestCase(AutopilotTestCase):
 
35
    """A common test case class that provides several useful methods for
 
36
    the ubuntu-calculator-app tests.
 
37
 
 
38
    """
 
39
 
 
40
    local_location = os.path.dirname(os.path.dirname(os.getcwd()))
 
41
 
 
42
    local_location_qml = os.path.join(local_location,
 
43
                                      'ubuntu-calculator-app.qml')
 
44
 
 
45
    installed_location_qml = os.path.join('/usr/share/ubuntu-calculator-app/',
 
46
                                          'ubuntu-calculator-app.qml')
 
47
 
 
48
    def get_launcher_and_type(self):
 
49
        if os.path.exists(self.local_location_qml):
 
50
            launcher = self.launch_test_local
 
51
            test_type = 'local'
 
52
        elif os.path.exists(self.installed_location_qml):
 
53
            launcher = self.launch_test_installed
 
54
            test_type = 'deb'
 
55
        else:
 
56
            launcher = self.launch_test_click
 
57
            test_type = 'click'
 
58
        return launcher, test_type
 
59
 
 
60
    def setUp(self):
 
61
        super(CalculatorAppTestCase, self).setUp()
 
62
        self.clear_calculator_database()
 
63
        self.launcher, self.test_type = self.get_launcher_and_type()
 
64
 
 
65
        # Unset the current locale to ensure locale-specific data
 
66
        # (day and month names, first day of the week, …) doesn’t get
 
67
        # in the way of test expectations.
 
68
        self.patch_environment('LC_ALL', 'C')
 
69
        self.app = ubuntu_calculator_app.CalculatorApp(self.launcher(),
 
70
                                                       self.test_type)
 
71
 
 
72
    @autopilot_logging.log_action(logger.info)
 
73
    def launch_test_local(self):
 
74
        return self.launch_test_application(
 
75
            base.get_qmlscene_launch_command(),
 
76
            self.local_location_qml,
 
77
            app_type='qt',
 
78
            emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
 
79
 
 
80
    @autopilot_logging.log_action(logger.info)
 
81
    def launch_test_installed(self):
 
82
        return self.launch_test_application(
 
83
            base.get_qmlscene_launch_command(),
 
84
            self.installed_location_qml,
 
85
            app_type='qt',
 
86
            emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
 
87
 
 
88
    @autopilot_logging.log_action(logger.info)
 
89
    def launch_test_click(self):
 
90
        return self.launch_click_package(
 
91
            "com.ubuntu.calculator",
 
92
            emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
 
93
 
 
94
    def clear_calculator_database(self):
 
95
        calculator_database_path = os.path.join(
 
96
            os.path.expanduser('~'),
 
97
            '.local',
 
98
            'share',
 
99
            'com.ubuntu.calculator'
 
100
        )
 
101
 
 
102
        if os.path.exists(calculator_database_path):
 
103
            shutil.rmtree(calculator_database_path)
 
104
            lambda: os.path.exists(calculator_database_path).wait_for(False)