40
45
@skipUnless(ofono.is_sim_inserted(ignore_phonesim=True), 'No SIM inserted')
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()
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(
50
58
toolkit_emulators.UbuntuUIToolkitEmulatorBase)
59
self.addCleanup(self.ensure_application_closed, 'messaging-app')
60
return proxy.wait_select_single(messaging_emulators.MainView)
52
62
def _create_temporary_contact(self):
67
77
self.addCleanup(self.addressbook_dbus.delete_contact, [contact_uid])
69
79
def _get_notifications_list(self):
80
"""Return a list of notifications currently being displayed."""
70
81
return self.unity_proxy.select_single(
72
83
objectName='notificationList'
86
def _receive_message_and_get_notification(self, to, from_, message,
87
media_url=None, timeout=60):
89
Receive a message from Telephony service and return notification.
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.
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
101
notifications_list = self._get_notifications_list()
103
sent = self.telephony.send_mms(to, from_, message, media_url)
105
sent = self.telephony.send_sms(to, from_, message)
107
self.assertTrue(sent, 'The message was not sent succesfully by the '
108
'telephony service.')
110
return notifications_list.get_current_notification(timeout)
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)
75
120
def test_receive_sms_from_contact(self):
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.
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(),
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"))
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)))
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(),
138
timeout=TIMEOUT_5_MIN)
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)))
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"))
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)
160
def test_receive_mms_from_contact(self):
162
Prerequisite: A contact in the address book with the number you
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
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(),
182
timeout=TIMEOUT_5_MIN)
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)))
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"))
198
messaging_app = self._get_messaging_app_main_view()
199
self.assertThat(messaging_app.get_header().title,
200
Eventually(Equals(CONTACT_NAME)))
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)