summaryrefslogtreecommitdiffstats
path: root/tests/functional/test_kolabd/test_001_user_sync.py
blob: e8e31bfb27e31f36120baf150bc809d507058d59 (plain)
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
import time
import unittest

import pykolab
from pykolab import wap_client
from pykolab.auth import Auth
from pykolab.imap import IMAP

conf = pykolab.getConf()

class TestKolabDaemon(unittest.TestCase):
    @classmethod
    def setup_class(self, *args, **kw):
        from tests.functional.purge_users import purge_users
        purge_users()

        self.user = {
                'local': 'john.doe',
                'domain': 'example.org'
            }

        from tests.functional.user_add import user_add
        user_add("John", "Doe")

    @classmethod
    def teardown_class(self, *args, **kw):
        from tests.functional.purge_users import purge_users
        purge_users()

    def test_001_user_recipient_policy(self):
        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient("%(local)s@%(domain)s" % (self.user))
        if hasattr(self, 'assertIsInstance'):
            self.assertIsInstance(recipient, str)

        self.assertEqual(recipient, "uid=doe,ou=People,dc=example,dc=org")

        result_before = wap_client.user_info(recipient)

        # Ensure the synchronization is run even without a kolab daemon running.
        auth.synchronize(mode='_paged_search')

        result_after = wap_client.user_info(recipient)
        self.assertEqual(result_after['mail'], 'john.doe@example.org')
        self.assertEqual(result_before['alias'], ['doe@example.org', 'j.doe@example.org', 'john.doe@example.org'])
        self.assertEqual(result_after['alias'], ['doe@example.org', 'j.doe@example.org'])

    def test_002_user_recipient_policy_duplicate(self):
        from tests.functional.user_add import user_add
        user = {
                'local': 'jane.doe',
                'domain': 'example.org'
            }
        user_add("Jane", "Doe")

        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient("%(local)s@%(domain)s" % (user))
        if hasattr(self, 'assertIsInstance'):
            self.assertIsInstance(recipient, str)

        self.assertEqual(recipient, "uid=doe2,ou=People,dc=example,dc=org")

        result_before = wap_client.user_info(recipient)

        # Ensure the synchronization is run even without a kolab daemon running.
        auth.synchronize(mode='_paged_search')

        result_after = wap_client.user_info(recipient)
        self.assertEqual(result_after['mail'], 'jane.doe@example.org')
        self.assertEqual(result_before['alias'], ['doe2@example.org', 'j.doe2@example.org', 'jane.doe@example.org'])
        self.assertEqual(result_after['alias'], ['doe2@example.org', 'j.doe2@example.org'])

    def test_003_user_mailbox_created(self):
        time.sleep(2)
        imap = IMAP()
        imap.connect()

        folders = imap.lm('user/%(local)s@%(domain)s' % (self.user))
        self.assertEqual(len(folders), 1)

    def test_004_user_additional_folders_created(self):
        time.sleep(2)
        imap = IMAP()
        imap.connect()

        exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))

        folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))

        self.assertEqual(len(folders), len(ac_folders.keys()))

    def test_005_user_folders_metadata_set(self):
        imap = IMAP()
        imap.connect()

        exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))

        folders = []
        folders.extend(imap.lm('user/%(local)s@%(domain)s' % (self.user)))
        folders.extend(imap.lm('user/%(local)s/*@%(domain)s' % (self.user)))

        for folder in folders:
            metadata = imap.get_metadata(folder)
            print metadata

            folder_name = '/'.join(folder.split('/')[2:]).split('@')[0]
            if ac_folders.has_key(folder_name):
                if ac_folders[folder_name].has_key('annotations'):
                    for _annotation in ac_folders[folder_name]['annotations'].keys():
                        if _annotation.startswith('/private'):
                            continue

                        _annotation_value = ac_folders[folder_name]['annotations'][_annotation]
                        self.assertTrue(metadata[metadata.keys().pop()].has_key(_annotation))
                        self.assertEqual(_annotation_value, metadata[metadata.keys().pop()][_annotation])

    def test_006_user_subscriptions(self):
        imap = IMAP()
        imap.connect(login=False)
        login = conf.get('cyrus-imap', 'admin_login')
        password = conf.get('cyrus-imap', 'admin_password')
        imap.login_plain(login, password, 'john.doe@example.org')

        folders = imap.lm()
        self.assertTrue("INBOX" in folders)

        #folders = imap.imap.lsub()
        #self.assertTrue("Calendar" in folders)

    def test_011_resource_add(self):
        pass

    def test_012_resource_mailbox_created(self):
        pass

    def test_013_resource_mailbox_annotation(self):
        pass