~om26er/address-book-app/abook_navigation_favorites

« back to all changes in this revision

Viewing changes to tests/autopilot/address_book_app/emulators/tests/test_address_book_emulator.py

  • Committer: Allan LeSage
  • Date: 2014-02-18 22:23:49 UTC
  • Revision ID: allan.lesage@canonical.com-20140218222349-vw4z8mqmbwbmx3wk
Add some unit tests for our address_book emulator, removing any speculative functionality ;) .

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- encoding: utf-8 -*-
 
3
#
 
4
#  Copyright 2014 Canonical Ltd.
 
5
#
 
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.
 
9
#
 
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.
 
14
#
 
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/>.
 
17
 
 
18
from mock import patch, MagicMock
 
19
from unittest import TestCase
 
20
 
 
21
from address_book_app.emulators.address_book import AddressBook, dbus
 
22
import address_book_app.emulators.address_book
 
23
 
 
24
 
 
25
class AddressBookEmulatorTestCase(TestCase):
 
26
 
 
27
    def setUp(self):
 
28
        self.address_book_patch = patch.object(
 
29
            AddressBook,
 
30
            '__init__',
 
31
            new=MagicMock(spec=AddressBook,
 
32
                          return_value=None))
 
33
        self.address_book_patch.start()
 
34
        self.address_book = AddressBook()
 
35
        self.interface_patch = patch.object(
 
36
            dbus.Interface,
 
37
            '__init__',
 
38
            new=MagicMock(spec=dbus.Interface,
 
39
                          return_value=None))
 
40
        self.address_book.bus = MagicMock()
 
41
        self.address_book.addr = MagicMock()
 
42
        self.address_book.addr_iface = MagicMock()
 
43
 
 
44
    def tearDown(self):
 
45
        self.address_book_patch.stop()
 
46
 
 
47
    def test_create_contact_just_name(self):
 
48
        vcard = """BEGIN:VCARD
 
49
VERSION:3.0
 
50
N:Lincoln;Abe
 
51
FN:
 
52
TEL;TYPE=HOME,VOICE;PID=1.1:
 
53
END:VCARD
 
54
"""
 
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, '')
 
60
 
 
61
    def test_create_contact_name_and_home_tel(self):
 
62
        vcard = """BEGIN:VCARD
 
63
VERSION:3.0
 
64
N:Lincoln;Abe
 
65
FN:
 
66
TEL;TYPE=HOME,VOICE;PID=1.1:7735847384
 
67
END:VCARD
 
68
"""
 
69
        self.address_book.addr_iface.createContact = MagicMock(
 
70
            return_value='fake-result')
 
71
        self.assertEquals('fake-result',
 
72
                          self.address_book.create_contact(
 
73
                              name='Lincoln;Abe',
 
74
                              tel_home='7735847384'))
 
75
        self.address_book.addr_iface.createContact.assert_called_with(vcard, '')
 
76
 
 
77
    def test_create_contact_name_home_and_work_tel(self):
 
78
        vcard = """BEGIN:VCARD
 
79
VERSION:3.0
 
80
N:Lincoln;Abe
 
81
FN:
 
82
TEL;TYPE=HOME,VOICE;PID=1.1:7735847384
 
83
TEL;TYPE=WORK,VOICE;PID=1.1:3129999999
 
84
END:VCARD
 
85
"""
 
86
        self.address_book.addr_iface.createContact = MagicMock(
 
87
            return_value='fake-result')
 
88
        self.assertEquals('fake-result',
 
89
                          self.address_book.create_contact(
 
90
                              name='Lincoln;Abe',
 
91
                              tel_home='7735847384',
 
92
                              tel_work='3129999999'))
 
93
        self.address_book.addr_iface.createContact.assert_called_with(vcard, '')