~tiagosh/phone-app/phone-app-mms

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Omer Akram
  • Date: 2013-06-28 18:30:16 UTC
  • mfrom: (680.1.6 phone)
  • Revision ID: tarmac-20130628183016-54sesbkkahrmb7gf
Adds initial packaging for the network connected tests.

Approved by Gustavo Pichorim Boiko, PS Jenkins bot.

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
# Copyright 2012 Canonical
 
3
#
 
4
# This file is part of phone-app.
 
5
#
 
6
# phone-app is free software: you can redistribute it and/or modify it
 
7
# under the terms of the GNU General Public License version 3, as published
 
8
# by the Free Software Foundation.
 
9
 
 
10
"""Phone App call/sms testing."""
 
11
 
 
12
from autopilot.input import Mouse, Touch, Pointer
 
13
from autopilot.matchers import Eventually
 
14
from autopilot.platform import model
 
15
from autopilot.testcase import AutopilotTestCase
 
16
from testtools.matchers import Equals, GreaterThan
 
17
 
 
18
from connected_tests.emulators.call_panel import CallPanel
 
19
from connected_tests.emulators.communication_panel import CommunicationPanel
 
20
 
 
21
import os
 
22
import shutil
 
23
import ConfigParser
 
24
 
 
25
config_file = os.path.expanduser('~/.testnumbers.cfg')
 
26
 
 
27
 
 
28
class PhoneAppTestCase(AutopilotTestCase):
 
29
    """A common test case class that provides several useful methods for
 
30
    Phone App tests.
 
31
 
 
32
    """
 
33
 
 
34
    config = ConfigParser.ConfigParser()
 
35
    config.read(config_file)
 
36
 
 
37
    PHONE_NUMBER = config.get('connected_variables', 'dial_number')
 
38
    SEND_SMS_NUMBER = config.get('connected_variables', 'sms_send_number')
 
39
    RECEIVED_SMS_NUMBER = config.get('connected_variables', 'sms_receive_num')
 
40
    CALL_WAIT = config.getint('connected_variables', 'call_wait_time')
 
41
    CALL_DURATION = config.getint('connected_variables', 'outgoing_call_duration')
 
42
    SEND_SMS_TEXT = config.get('connected_variables', 'sms_send_text')
 
43
    RECEIVED_SMS_TEXT = config.get('connected_variables', 'sms_expect_text')
 
44
    TYPING_DELAY=0.01
 
45
    HOME = os.path.expanduser("~")
 
46
    BACKUP = HOME + "/.local/share/TpLogger/logs/ofono_ofono_account0.backup/"
 
47
    ORIGINAL = HOME + "/.local/share/TpLogger/logs/ofono_ofono_account0"
 
48
    SMS_POLLING_TIME = 5
 
49
 
 
50
    if model() == 'Desktop':
 
51
        scenarios = [('with mouse', dict(input_device_class=Mouse))]
 
52
    else:
 
53
        scenarios = [('with touch', dict(input_device_class=Touch))]
 
54
 
 
55
    local_location = "../../src/phone-app"
 
56
 
 
57
    def setUp(self):
 
58
        self.pointing_device = Pointer(self.input_device_class.create())
 
59
        super(PhoneAppTestCase, self).setUp()
 
60
        self.delete_call_sms_logs()
 
61
 
 
62
        self.addCleanup(self.restore_call_sms_logs)
 
63
 
 
64
        if os.path.exists(self.local_location):
 
65
            self.launch_test_local()
 
66
        else:
 
67
            self.launch_test_installed()
 
68
 
 
69
        main_view = self.get_main_view()
 
70
        self.assertThat(main_view.visible, Eventually(Equals(True)))
 
71
 
 
72
    def launch_test_local(self):
 
73
        self.app = self.launch_test_application(
 
74
            self.local_location,
 
75
            app_type='qt')
 
76
 
 
77
    def launch_test_installed(self):
 
78
        if model() == 'Desktop':
 
79
            self.app = self.launch_test_application(
 
80
                "phone-app",
 
81
                app_type='qt')
 
82
        else:
 
83
            self.app = self.launch_test_application(
 
84
                "phone-app",
 
85
                "--desktop_file_hint=/usr/share/applications/phone-app.desktop",
 
86
                app_type='qt')
 
87
 
 
88
    def get_main_view(self):
 
89
        return self.app.select_single("QQuickView")
 
90
 
 
91
    def get_tabs(self):
 
92
        """Returns the top tabs bar."""
 
93
        return self.app.select_single("NewTabBar")
 
94
 
 
95
    def get_conversations_tab_button(self):
 
96
        return self.app.select_single("AbstractButton", buttonIndex=4)
 
97
 
 
98
    def get_conversations_pane(self):
 
99
        return self.app.select_single(
 
100
            "PageStack", objectName="communicationsStack")
 
101
 
 
102
    def switch_to_conversation_tab(self):
 
103
        tabs_bar = self.get_tabs()
 
104
        conversation_pane = self.get_conversations_pane()
 
105
        self.pointing_device.click_object(tabs_bar)
 
106
 
 
107
        conversations_tab_button = self.get_conversations_tab_button()
 
108
        self.assertThat(conversations_tab_button.opacity,
 
109
                        Eventually(GreaterThan(0.35)))
 
110
        self.pointing_device.click_object(conversations_tab_button)
 
111
 
 
112
        self.assertThat(conversation_pane.isCurrent, Eventually(Equals(True)))
 
113
 
 
114
    def number_to_object_name(self, string):
 
115
 
 
116
        keys = {
 
117
            'buttonOne' : '1',
 
118
            'buttonTwo' : '2',
 
119
            'buttonThree' : '3',
 
120
            'buttonFour' : '4',
 
121
            'buttonFive' : '5',
 
122
            'buttonSix' : '6',
 
123
            'buttonSeven' : '7',
 
124
            'buttonEight' : '8',
 
125
            'buttonNine' : '9',
 
126
            'buttonZero' : '0',
 
127
            'buttonHash' : '#',
 
128
            'buttonAsterisk' : '*'
 
129
        }
 
130
        for key, value in keys.items():
 
131
            if value == string:
 
132
                return key
 
133
 
 
134
    def dial_number(self, number):
 
135
        for keys in str(number):
 
136
            objectName = self.number_to_object_name(keys)
 
137
            button = self.communication_panel.select_single_retry("KeypadButton", objectName=objectName)
 
138
            self.pointing_device.click_object(button)
 
139
 
 
140
    def reveal_toolbar(self):
 
141
        main_view = self.get_main_view()
 
142
        x_line = main_view.x + main_view.width * 0.5
 
143
        start_y = main_view.y + main_view.height - 1
 
144
        stop_y = start_y - 200
 
145
        self.pointing_device.drag(x_line, start_y, x_line, stop_y)
 
146
 
 
147
    def delete_call_sms_logs(self):
 
148
        if os.path.exists(self.ORIGINAL):
 
149
            shutil.move(self.ORIGINAL, self.BACKUP)
 
150
            self.assertThat(
 
151
                lambda: os.path.exists(self.BACKUP), Eventually(Equals(True)))
 
152
        else:
 
153
            pass
 
154
 
 
155
    def restore_call_sms_logs(self):
 
156
        if os.path.exists(self.BACKUP):
 
157
            shutil.rmtree(self.ORIGINAL)
 
158
            self.assertThat(lambda: os.path.exists(self.ORIGINAL), Eventually(Equals(False)))
 
159
            shutil.move(self.BACKUP, self.ORIGINAL)
 
160
            self.assertTrue(lambda: os.path.exists(self.ORIGINAL), Eventually(Equals(True)))
 
161
        else:
 
162
            pass
 
163
            
 
164
    @property
 
165
    def call_panel(self):
 
166
        return CallPanel(self.app)
 
167
 
 
168
    @property
 
169
    def communication_panel(self):
 
170
        return CommunicationPanel(self.app)