File: opimd.py

package info (click to toggle)
fso-frameworkd 0.9.5.9%2Bgit20110512-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,988 kB
  • ctags: 5,213
  • sloc: python: 23,770; sh: 160; sql: 4; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 2,351 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/python -N
"""
framework tests

(C) 2008 Guillaume 'Charlie' Chereau <charlie@openmoko.org>
(C) 2008 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
(C) 2008 Openmoko, Inc.
GPLv2 or later
"""

import unittest
import gobject
import threading
import dbus
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)

import test

class PimTests(unittest.TestCase):
    """Some test cases for the pim subsystem"""
    def setUp(self):
        self.bus = dbus.SystemBus()
        # Get the pim interface
        pim_sources = self.bus.get_object('org.freesmartphone.opimd', '/org/freesmartphone/PIM/Sources')
        self.pim_sources = dbus.Interface(pim_sources, 'org.freesmartphone.PIM.Sources')
        pim_contacts = self.bus.get_object('org.freesmartphone.opimd', '/org/freesmartphone/PIM/Contacts')
        self.pim_contacts = dbus.Interface(pim_contacts, 'org.freesmartphone.PIM.Contacts')

    def test_add(self):
        """Try to add a contact and check that a query get this contact"""
        self.pim_sources.InitAllEntries()
        # Add a new contact
        self.pim_contacts.Add({'Name':"gui", 'Phone':"0123456789"})
        # check that the contact is present in the lists
        query_path = self.pim_contacts.Query({'Name':"gui"})
        query = self.bus.get_object('org.freesmartphone.opimd', query_path)
        query = dbus.Interface(query, 'org.freesmartphone.PIM.ContactQuery')
        count = query.GetResultCount()
        assert count >= 1
        for i in range(count):
            res = query.GetResult()
            if res.get('Name', None) == "gui" and res.get('Phone', None) == "0123456789":
                break
        else:
            self.fail("Can't find the added contact")
        
    def test_query(self):
        """Try to make a query on the contacts"""
        self.pim_sources.InitAllEntries()
        query_path = self.pim_contacts.Query({'Name':"gui"})
        query = self.bus.get_object('org.freesmartphone.opimd', query_path)
        query = dbus.Interface(query, 'org.freesmartphone.PIM.ContactQuery')
        count = query.GetResultCount()
        results = query.GetMultipleResults(count)
        
        
if __name__ == '__main__':
    suite = unittest.defaultTestLoader.loadTestsFromTestCase(PimTests)
    result = unittest.TextTestRunner(verbosity=3).run(suite)