/usr/lib/python2.7/dist-packages/address_book_app/tests/test_add_contact.py is in address-book-app-autopilot 0.2+14.04.20140408.3-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright 2013, 2014 Canonical
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
"""Tests for the Addressbook App"""
from __future__ import absolute_import
from testtools.matchers import Equals
from autopilot.matchers import Eventually
from autopilot.introspection import dbus
from address_book_app.tests import AddressBookAppTestCase
from address_book_app.emulators import main_window
class TestAddContact(AddressBookAppTestCase):
""" Tests the Add contact """
def test_go_to_add_contact(self):
"""Test to launch the add contact screen using emulator method"""
self.assertRaises(
dbus.StateNotFoundError, self.main_window.get_contact_edit_page)
contact_editor = self.main_window.go_to_add_contact()
self.assertTrue(contact_editor.visible)
self.assertIsInstance(contact_editor, main_window.ContactEditor)
def test_add_and_cancel_contact(self):
list_page = self.main_window.get_contact_list_page()
# execute add new contact
self.main_window.open_toolbar().click_button("Add")
edit_page = self.main_window.get_contact_edit_page()
# Check if the contact list disapear and contact editor appears
self.assertThat(list_page.visible, Eventually(Equals(False)))
self.assertThat(edit_page.visible, Eventually(Equals(True)))
# cancel new contact without save
self.main_window.cancel()
# Check if the contact list is visible again
self.assertThat(list_page.visible, Eventually(Equals(True)))
# Check if the contact list still empty
list_view = self.main_window.get_contact_list_view()
self.assertThat(list_view.count, Eventually(Equals(0)))
def test_add_contact_without_name(self):
# execute add new contact
self.main_window.open_toolbar().click_button("Add")
edit_page = self.main_window.get_contact_edit_page()
# Try to save a empty contact
acceptButton = self.main_window.get_button("accept")
# Save button must be disabled
self.assertThat(acceptButton.enabled, Eventually(Equals(False)))
firstNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="firstName")
lastNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="lastName")
# fill fistName field
self.type_on_field(firstNameField, "Fulano")
# Save button must be enabled
self.assertThat(acceptButton.enabled, Eventually(Equals(True)))
# clear firstName field
self.clear_text_on_field(firstNameField)
# Save button must be disabled
self.assertThat(acceptButton.enabled, Eventually(Equals(False)))
# fill lastName field
self.type_on_field(lastNameField, "de Tal")
# Save button must be enabled
self.assertThat(acceptButton.enabled, Eventually(Equals(True)))
# clear lastName field
self.clear_text_on_field(lastNameField)
# Save button must be disabled
self.assertThat(acceptButton.enabled, Eventually(Equals(False)))
# Clicking on disabled button should do nothing
self.pointing_device.click_object(acceptButton)
# Check if the contact editor still visbile
list_page = self.main_window.get_contact_list_page()
self.assertThat(list_page.visible, Eventually(Equals(False)))
self.assertThat(edit_page.visible, Eventually(Equals(True)))
# Check if the contact list still empty
list_view = self.main_window.get_contact_list_view()
self.assertThat(list_view.count, Eventually(Equals(0)))
def test_add_contact_with_full_name(self):
# execute add new contact
self.main_window.open_toolbar().click_button("Add")
firstNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="firstName")
lastNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="lastName")
# fill fistName field
self.type_on_field(firstNameField, "Fulano")
# fill lastName field
self.type_on_field(lastNameField, "de Tal")
# Save contact
self.main_window.save()
# Check if the contact list is visible again
list_page = self.main_window.get_contact_list_page()
self.assertThat(list_page.visible, Eventually(Equals(True)))
# Check if contact was added
list_view = self.main_window.get_contact_list_view()
self.assertThat(list_view.count, Eventually(Equals(1)))
def test_add_contact_with_first_name(self):
# execute add new contact
self.main_window.open_toolbar().click_button("Add")
firstNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="firstName")
# fill fistName field
self.type_on_field(firstNameField, "Fulano")
# Save contact
self.main_window.save()
# Check if contact was added
list_view = self.main_window.get_contact_list_view()
self.assertThat(list_view.count, Eventually(Equals(1)))
def test_add_contact_with_last_name(self):
# execute add new contact
self.main_window.open_toolbar().click_button("Add")
lastNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="lastName")
# fill fistName field
self.type_on_field(lastNameField, "de Tal")
# Save contact
self.main_window.save()
# Check if contact was added
list_view = self.main_window.get_contact_list_view()
self.assertThat(list_view.count, Eventually(Equals(1)))
def test_add_contact_with_name_and_phone(self):
# execute add new contact
self.main_window.open_toolbar().click_button("Add")
# fill name
firstNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="firstName")
lastNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="lastName")
self.type_on_field(firstNameField, "Fulano")
self.type_on_field(lastNameField, "de Tal")
# fill phone number
phone_number_0 = self.main_window.wait_select_single(
"TextInputDetail",
objectName="phoneNumber_0")
self.type_on_field(phone_number_0, "55 81 8777 7755")
# Save contact
self.main_window.save()
# Check if contact was added
list_view = self.main_window.get_contact_list_view()
self.assertThat(list_view.count, Eventually(Equals(1)))
def test_add_full_contact(self):
# execute add new contact
self.main_window.open_toolbar().click_button("Add")
# fill name
firstNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="firstName")
lastNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="lastName")
self.type_on_field(firstNameField, "Sherlock")
self.type_on_field(lastNameField, "Holmes")
# fill phone number
phone_number_0 = self.main_window.wait_select_single(
"TextInputDetail",
objectName="phoneNumber_0")
self.type_on_field(phone_number_0, "81 8777 7755")
# fill email
email_0 = self.main_window.wait_select_single(
"TextInputDetail",
objectName="emailAddress_0")
self.type_on_field(email_0, "holmes.sherlock.uk")
# fill im
im_0 = self.main_window.wait_select_single(
"TextInputDetail",
objectName="imUri_0")
self.type_on_field(im_0, "sh.im.com.br")
# fill address
street_0 = self.main_window.wait_select_single(
"TextInputDetail",
objectName="streetAddress_0")
self.type_on_field(street_0, "221B Baker Street")
locality_0 = self.main_window.wait_select_single(
"TextInputDetail",
objectName="localityAddress_0")
self.type_on_field(locality_0, "West End")
region_0 = self.main_window.wait_select_single(
"TextInputDetail",
objectName="regionAddress_0")
self.type_on_field(region_0, "London")
postcode_0 = self.main_window.wait_select_single(
"TextInputDetail",
objectName="postcodeAddress_0")
self.type_on_field(postcode_0, "7777")
country_0 = self.main_window.wait_select_single(
"TextInputDetail",
objectName="countryAddress_0")
self.type_on_field(country_0, "united kingdom")
# Save contact
self.main_window.save()
# Check if contact was added
list_view = self.main_window.get_contact_list_view()
self.assertThat(list_view.count, Eventually(Equals(1)))
def test_email_label_save(self):
# execute add new contact
self.main_window.open_toolbar().click_button("Add")
# fill name
firstNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="firstName")
lastNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="lastName")
self.type_on_field(firstNameField, "Sherlock")
self.type_on_field(lastNameField, "Holmes")
# Home
self.set_email_address(0, "home@email.com", 0)
# Work
self.set_email_address(1, "work@email.com", 1)
# Other
self.set_email_address(2, "other@email.com", 2)
# Save contact
self.main_window.save()
contacts = self.main_window.select_many("ContactDelegate")
self.pointing_device.click_object(contacts[0])
# check if contacts was saved with the correct labels
view_page = self.main_window.get_contact_view_page()
self.assertThat(view_page.visible, Eventually(Equals(True)))
# check if we have 3 emails"""
email_group = view_page.select_single(
"ContactDetailGroupWithTypeView",
objectName="emails")
self.assertThat(email_group.detailsCount, Eventually(Equals(3)))
emails = {"home@email.com" : "Home",
"work@email.com" : "Work",
"other@email.com" : "Other"}
# Check if they have the correct label
for idx in range(3):
email_type = view_page.select_single(
"Label",
objectName="type_email_" + str(idx))
email_label = view_page.select_single(
"Label",
objectName="label_emailAddress_" + str(idx) + ".0")
self.assertThat(emails[email_label.text], Equals(email_type.text))
del emails[email_label.text]
self.assertThat(len(emails), Equals(0))
def test_phone_label_save(self):
# execute add new contact
self.main_window.open_toolbar().click_button("Add")
# fill name
firstNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="firstName")
lastNameField = self.main_window.wait_select_single(
"TextInputDetail",
objectName="lastName")
self.type_on_field(firstNameField, "Sherlock")
self.type_on_field(lastNameField, "Holmes")
# Home
self.set_phone_number(0, "00 0000 0000", 0)
# Work
self.set_phone_number(1, "11 1111 1111", 1)
# Mobile
self.set_phone_number(2, "22 2222 2222", 2)
# Work Mobile
self.set_phone_number(3, "33 3333 3333", 3)
# Other
self.set_phone_number(4, "44 4444 4444", 4)
# Save contact
self.main_window.save()
contacts = self.main_window.select_many("ContactDelegate")
self.pointing_device.click_object(contacts[0])
# check if contacts was saved with the correct labels
view_page = self.main_window.get_contact_view_page()
self.assertThat(view_page.visible, Eventually(Equals(True)))
# check if we have five phones"""
phone_group = view_page.select_single(
"ContactDetailGroupWithTypeView",
objectName="phones")
self.assertThat(phone_group.detailsCount, Eventually(Equals(5)))
phones = {"00 0000 0000" : "Home",
"11 1111 1111" : "Work",
"22 2222 2222" : "Mobile",
"33 3333 3333" : "Work Mobile",
"44 4444 4444" : "Other"}
# Check if they have the correct label
for idx in range(5):
phone_type = view_page.select_single(
"Label",
objectName="type_phoneNumber_" + str(idx))
phone_label = view_page.select_single(
"Label",
objectName="label_phoneNumber_" + str(idx) + ".0")
self.assertThat(phones[phone_label.text], Equals(phone_type.text))
del phones[phone_label.text]
self.assertThat(len(phones), Equals(0))
|