2
# -*- encoding: utf-8 -*-
4
# Copyright 2014 Canonical Ltd.
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU Lesser General Public License as published by
8
# the Free Software Foundation; version 3.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU Lesser General Public License for more details.
15
# You should have received a copy of the GNU Lesser General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
from mock import patch, MagicMock
19
from unittest import TestCase
21
from address_book_app.emulators.address_book import AddressBook, dbus
22
import address_book_app.emulators.address_book
25
class AddressBookEmulatorTestCase(TestCase):
28
self.address_book_patch = patch.object(
31
new=MagicMock(spec=AddressBook,
33
self.address_book_patch.start()
34
self.address_book = AddressBook()
35
self.interface_patch = patch.object(
38
new=MagicMock(spec=dbus.Interface,
40
self.address_book.bus = MagicMock()
41
self.address_book.addr = MagicMock()
42
self.address_book.addr_iface = MagicMock()
45
self.address_book_patch.stop()
47
def test_create_contact_just_name(self):
48
vcard = """BEGIN:VCARD
52
TEL;TYPE=HOME,VOICE;PID=1.1:
55
self.address_book.addr_iface.createContact = MagicMock(
56
return_value='fake-abe-lincoln')
57
self.assertEquals('fake-abe-lincoln',
58
self.address_book.create_contact(name='Lincoln;Abe'))
59
self.address_book.addr_iface.createContact.assert_called_with(vcard, '')
61
def test_create_contact_name_and_home_tel(self):
62
vcard = """BEGIN:VCARD
66
TEL;TYPE=HOME,VOICE;PID=1.1:7735847384
69
self.address_book.addr_iface.createContact = MagicMock(
70
return_value='fake-result')
71
self.assertEquals('fake-result',
72
self.address_book.create_contact(
74
tel_home='7735847384'))
75
self.address_book.addr_iface.createContact.assert_called_with(vcard, '')
77
def test_create_contact_name_home_and_work_tel(self):
78
vcard = """BEGIN:VCARD
82
TEL;TYPE=HOME,VOICE;PID=1.1:7735847384
83
TEL;TYPE=WORK,VOICE;PID=1.1:3129999999
86
self.address_book.addr_iface.createContact = MagicMock(
87
return_value='fake-result')
88
self.assertEquals('fake-result',
89
self.address_book.create_contact(
91
tel_home='7735847384',
92
tel_work='3129999999'))
93
self.address_book.addr_iface.createContact.assert_called_with(vcard, '')