~canonical-platform-qa/ubuntu-system-tests/dont_update_unity8

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/tests/test_messaging.py

  • Committer: Tarmac
  • Author(s): Richard Huddie
  • Date: 2015-06-19 09:58:59 UTC
  • mfrom: (124.1.20 ubuntu-system-tests)
  • Revision ID: tarmac-20150619095859-q4smj1zxox5wifc1
Add a new test case to receive an MMS message containing an image attachment.

Approved by PS Jenkins bot, Sergio Cazzolato, Brendan Donegan.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
from ubuntu_system_tests.helpers.addressbook import dbus_service
29
29
from ubuntu_system_tests.helpers import autopilot as autopilot_helpers
 
30
from ubuntu_system_tests.helpers import messaging as messaging_helpers  # NOQA
 
31
from ubuntu_system_tests.helpers import file_system
30
32
from ubuntu_system_tests.helpers import ofono
 
33
from ubuntu_system_tests.helpers import web
31
34
from ubuntu_system_tests.helpers.telephony import Telephony
32
35
from ubuntu_system_tests.helpers.unity8 import notifications  # NOQA
 
36
 
33
37
from ubuntu_system_tests.tests import base
34
38
 
35
39
CONTACT_NAME = 'Fulano de Tal'
 
40
TIMEOUT_5_MIN = 300
36
41
 
37
42
 
38
43
class MessagingTestCase(base.BaseTelephonyTestCase):
40
45
    @skipUnless(ofono.is_sim_inserted(ignore_phonesim=True), 'No SIM inserted')
41
46
    def setUp(self):
42
47
        super().setUp()
43
 
        self.unity_proxy = self.launch_unity()
44
 
        self.unity_proxy.unlock()
 
48
        self.unity_proxy = self.restart_unity()
 
49
        credentials = {'AccountSid': self.get_telephony_service_account_id(),
 
50
                       'AuthToken': self.get_telephony_service_auth_token()}
 
51
        self.telephony = Telephony(credentials)
 
52
        self._create_temporary_contact()
45
53
 
46
 
    def _get_messaging_app_proxy(self):
 
54
    def _get_messaging_app_main_view(self):
47
55
        """Return messaging app proxy object from existing process."""
48
 
        return autopilot_helpers.get_proxy_object_for_existing_process(
 
56
        proxy = autopilot_helpers.get_proxy_object_for_existing_process(
49
57
            'messaging-app',
50
58
            toolkit_emulators.UbuntuUIToolkitEmulatorBase)
 
59
        self.addCleanup(self.ensure_application_closed, 'messaging-app')
 
60
        return proxy.wait_select_single(messaging_emulators.MainView)
51
61
 
52
62
    def _create_temporary_contact(self):
53
63
        """
67
77
        self.addCleanup(self.addressbook_dbus.delete_contact, [contact_uid])
68
78
 
69
79
    def _get_notifications_list(self):
 
80
        """Return a list of notifications currently being displayed."""
70
81
        return self.unity_proxy.select_single(
71
82
            'Notifications',
72
83
            objectName='notificationList'
73
84
        )
74
85
 
 
86
    def _receive_message_and_get_notification(self, to, from_, message,
 
87
                                              media_url=None, timeout=60):
 
88
        """
 
89
        Receive a message from Telephony service and return notification.
 
90
 
 
91
        If media_url is None then an SMS will be sent, if media_url is
 
92
        specified the content will be attached to an MMS message.
 
93
 
 
94
        :param to: Phone number of recipient
 
95
        :param from_: Phone number of sender
 
96
        :param message: Body of the message to send
 
97
        :param media_url: Url of file to attach to message
 
98
        :param timeout: Timeout period to wait for notification in seconds
 
99
        :return: Notification message
 
100
        """
 
101
        notifications_list = self._get_notifications_list()
 
102
        if media_url:
 
103
            sent = self.telephony.send_mms(to, from_, message, media_url)
 
104
        else:
 
105
            sent = self.telephony.send_sms(to, from_, message)
 
106
 
 
107
        self.assertTrue(sent, 'The message was not sent succesfully by the '
 
108
                              'telephony service.')
 
109
 
 
110
        return notifications_list.get_current_notification(timeout)
 
111
 
 
112
    def _delete_message(self, messaging_app, message_body):
 
113
        """Delete specified message from messages view."""
 
114
        messages = messaging_app.get_messages_page()
 
115
        messages_before = messages.get_messages_count()
 
116
        messaging_app.delete_message(message_body)
 
117
        messages_after = messages.get_messages_count()
 
118
        self.assertEqual(messages_after, messages_before - 1)
 
119
 
75
120
    def test_receive_sms_from_contact(self):
76
121
        """
77
122
        Prerequisite: A contact in the address book with the number you
85
130
             messages received by that sender. The message
86
131
             just sent should appear at the bottom.
87
132
        """
88
 
        self._create_temporary_contact()
89
 
        # Get the notifications list first as we don't want to
90
 
        # waste precious time waiting for this call to return
91
 
        notifications_list = self._get_notifications_list()
92
 
        credentials = {'AccountSid': self.get_telephony_service_account_id(),
93
 
                       'AuthToken': self.get_telephony_service_auth_token()}
94
 
        tel = Telephony(credentials)
95
 
        # We use a UUID as the message body so that we know the message
96
 
        # that is received is the same one we sent.
97
 
        message_body = str(uuid.uuid1())
98
 
        sent = tel.send_sms(self.get_device_phone_number(),
99
 
                            self.get_telephony_service_number(),
100
 
                            message_body)
101
 
        self.assertTrue(sent, 'The SMS was not sent succesfully by the '
102
 
                              'telephony service.')
103
 
        # Tap on indicator when it appears and check the contents are
104
 
        # correct - message body is displayed and contact name is shown
105
 
        sms_notification = notifications_list.get_current_notification()
106
 
        self.assertThat(sms_notification.summary,
107
 
                        Eventually(Equals('Message from {contact}'.format(
108
 
                                          contact='Fulano de Tal'))))
109
 
        self.assertThat(sms_notification.body,
110
 
                        Eventually(Equals(message_body)))
111
 
        # Open the messaging app by tapping on the notification.
112
 
        # Due to launchpad.net/bugs/1457629 the following tap_on() method can
113
 
        # fail due to CPO inheritance problems in Autopilot.
114
 
        # A workaround is to select and press the object directly in the test.
115
 
        # This should be removed as soon as the Autopilot CPO bug is fixed.
116
 
        # sms_notification.tap_on()
117
 
        sms_notification.pointing_device.click_object(
118
 
            sms_notification.select_single(objectName="interactiveArea"))
119
 
 
120
 
        messaging_app = self._get_messaging_app_proxy()
121
 
        self.addCleanup(self.ensure_application_closed, 'messaging-app')
122
 
        main_view = messaging_app.select_single(messaging_emulators.MainView)
123
 
        # Confirm that the message is displayed and the header title
124
 
        # is the name of the contact
125
 
        main_view.get_message(message_body)
126
 
        self.assertThat(main_view.get_header().title,
127
 
                        Eventually(Equals(CONTACT_NAME)))
128
 
        # Delete the message
129
 
        main_view.delete_message(message_body)
 
133
        message_body = str(uuid.uuid1())
 
134
        notification = self._receive_message_and_get_notification(
 
135
            self.get_device_phone_number(),
 
136
            self.get_telephony_service_number(),
 
137
            message_body,
 
138
            timeout=TIMEOUT_5_MIN)
 
139
 
 
140
        self.assertThat(notification.summary,
 
141
                        Eventually(Equals('Message from {contact}'.format(
 
142
                                          contact=CONTACT_NAME))))
 
143
        self.assertThat(notification.body, Eventually(Equals(message_body)))
 
144
 
 
145
        # Open the messaging app by tapping on the notification.
 
146
        # Due to launchpad.net/bugs/1457629 the following tap_on() method can
 
147
        # fail due to CPO inheritance problems in Autopilot.
 
148
        # A workaround is to select and press the object directly in the test.
 
149
        # This should be removed as soon as the Autopilot CPO bug is fixed.
 
150
        # notification.tap_on()
 
151
        notification.pointing_device.click_object(
 
152
            notification.select_single(objectName="interactiveArea"))
 
153
 
 
154
        messaging_app = self._get_messaging_app_main_view()
 
155
        messaging_app.get_message(message_body)
 
156
        self.assertThat(messaging_app.get_header().title,
 
157
                        Eventually(Equals(CONTACT_NAME)))
 
158
        self._delete_message(messaging_app, message_body)
 
159
 
 
160
    def test_receive_mms_from_contact(self):
 
161
        """
 
162
        Prerequisite: A contact in the address book with the number you
 
163
        are sending from
 
164
        1. From another device send an MMS to the phone number of a SIM
 
165
           card that is in the SUT
 
166
           - A notification appears containing the senders
 
167
             name and the message content.
 
168
        2. Tap on the message notification before it disappears
 
169
           - The messaging application is opened showing all
 
170
             messages received by that sender. The message
 
171
             just sent should appear at the bottom.
 
172
           - An image should be contained within the message
 
173
        """
 
174
        message_body = str(uuid.uuid1())
 
175
        media_url = 'http://people.canonical.com/~platform-qa/mms-ubuntu.jpg'
 
176
        mms_media_file = web.download_file(media_url)
 
177
        notification = self._receive_message_and_get_notification(
 
178
            self.get_device_phone_number(),
 
179
            self.get_telephony_service_number(),
 
180
            message_body,
 
181
            media_url=media_url,
 
182
            timeout=TIMEOUT_5_MIN)
 
183
 
 
184
        self.assertThat(notification.summary,
 
185
                        Eventually(Equals('Message from {contact}'.format(
 
186
                                          contact=CONTACT_NAME))))
 
187
        self.assertThat(notification.body, Eventually(Equals(message_body)))
 
188
 
 
189
        # Open the messaging app by tapping on the notification.
 
190
        # Due to launchpad.net/bugs/1457629 the following tap_on() method can
 
191
        # fail due to CPO inheritance problems in Autopilot.
 
192
        # A workaround is to select and press the object directly in the test.
 
193
        # This should be removed as soon as the Autopilot CPO bug is fixed.
 
194
        # notification.tap_on()
 
195
        notification.pointing_device.click_object(
 
196
            notification.select_single(objectName="interactiveArea"))
 
197
 
 
198
        messaging_app = self._get_messaging_app_main_view()
 
199
        self.assertThat(messaging_app.get_header().title,
 
200
                        Eventually(Equals(CONTACT_NAME)))
 
201
 
 
202
        mms_message = messaging_app.get_message(message_body)
 
203
        photo_path = mms_message.get_mms_content_file_path()
 
204
        self.assertTrue(file_system.compare_files(mms_media_file, photo_path))
 
205
        self._delete_message(messaging_app, message_body)