summaryrefslogtreecommitdiffstats
path: root/pykolab/tests/zpush/test_000_000.py
blob: ed40ca917c6ae36d3893a8c42124bdfe325367cd (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
# -*- coding: utf-8 -*-
# Copyright 2010 Kolab Systems AG (http://www.kolabsys.com)
#
# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 only
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

import cyruslib

from pykolab.conf import Conf
from pykolab.constants import *
from pykolab.tests.constants import *
from pykolab.translate import _

TEST_FOLDERS = {
        'Calendar': {
                'annotations': {
                        "/vendor/kolab/folder-test": "true",
                        "/vendor/kolab/folder-type": "event.default"
                    },
                'acls': [
                    ],
            },

        'Contacts': {
                'annotations': {
                        "/vendor/kolab/folder-type": "contact.default"
                    },
                'acls': [
                    ],
            },

        'Journal': {
                'annotations': {
                        "/vendor/kolab/folder-test": "true",
                        "/vendor/kolab/folder-type": "journal.default"
                    },
                'acls': [
                    ],
            },
        'Notes': {
                'annotations': {
                        "/vendor/kolab/folder-type": "note.default"
                    },
                'acls': [
                    ],
            },
        'Tasks': {
                'annotations': {
                        "/vendor/kolab/folder-type": "task.default"
                    },
                'acls': [
                    ],
            },
    }

class Test_000_000(object):
    """
        Preparations for the Test 000 series
    """

    def __init__(self, conf=None):
        self.suite_num = "000"
        self.suite_test_num = "000"

        if not conf:
            self.conf = Conf()
            self.conf.finalize_conf()
        else:
            self.conf = conf

        # Remove all mailboxes
        # FIXME: Should come from configuration file and/or prompts
        imap = cyruslib.CYRUS("imap://%s:143" %(self.conf.testing_server))
        imap.login(self.conf.testing_admin_login,self.conf.testing_admin_password)

        # Delete all mailboxes
        for user in self.conf.testing_users:
            for mailbox in imap.lm("user%s%s" %(imap.SEP,"%(givenname)s@%(domain)s" %(user))):
                self.conf.log.debug(_("Deleting mailbox: %s") %(mailbox), level=3)
                try:
                    imap.dm(mailbox)
                except cyruslib.CYRUSError, e:
                    pass

        # Recreate the user top-level mailboxes
        for user in self.conf.testing_users:
            mailbox = "user%s%s" %(imap.SEP,"%(givenname)s@%(domain)s" %(user))
            self.conf.log.debug(_("Creating mailbox: %s") %(mailbox), level=3)
            imap.cm(mailbox)

        imap.logout()

        del imap

        # Have the user themselves:
        # - create the standard folders
        # - set the standard annotations
        # - subscribe
        for user in self.conf.testing_users:
            imap = cyruslib.CYRUS("imap://%s:143" %(self.conf.testing_server))
            try:
                imap.login("%(givenname)s@%(domain)s" %(user), user['password'])
            except:
                self.conf.log.error(_("Authentication failure for %s") %("%(givenname)s@%(domain)s" %(user)), recoverable=True)
                continue

            if self.conf.debuglevel > 3:
                imap.VERBOSE = True

            imap.subscribe("INBOX")

            for mailbox in TEST_FOLDERS.keys():
                imap.cm("INBOX/%s" %(mailbox))
                for annotation in TEST_FOLDERS[mailbox]['annotations'].keys():
                    imap.setannotation("INBOX/%s" %(mailbox),annotation,TEST_FOLDERS[mailbox]['annotations'][annotation])

            imap.subscribe("INBOX/%s" %(mailbox))

            imap.logout()
            del imap