summaryrefslogtreecommitdiffstats
path: root/tests/functional/test_wallace/test_005_resource_add.py
blob: fc7f3ed2f506770ca91bb7150afebf18cf7d241a (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
import time
import pykolab

from pykolab import wap_client
from pykolab.auth import Auth
from pykolab.imap import IMAP
from wallace import module_resources
from twisted.trial import unittest

import tests.functional.resource_func as funcs

conf = pykolab.getConf()

class TestResourceAdd(unittest.TestCase):

    @classmethod
    def setUp(self):
        from tests.functional.purge_users import purge_users
        #purge_users()

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

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

        funcs.purge_resources()
        self.audi = funcs.resource_add("car", "Audi A4")
        self.passat = funcs.resource_add("car", "VW Passat")
        self.boxter = funcs.resource_add("car", "Porsche Boxter S", kolabinvitationpolicy='ACT_ACCEPT_AND_NOTIFY')
        self.cars = funcs.resource_add("collection", "Company Cars", [ self.audi['dn'], self.passat['dn'], self.boxter['dn'] ], kolabinvitationpolicy='ACT_ACCEPT')

        from tests.functional.synchronize import synchronize_once
        synchronize_once()

    @classmethod
    def tearDown(self):
        from tests.functional.purge_users import purge_users
        #funcs.purge_resources()
        #purge_users()

    def test_001_resource_created(self):
        resource = module_resources.resource_record_from_email_address(self.audi['mail'])
        self.assertEqual(len(resource), 1)
        self.assertEqual(resource[0], self.audi['dn'])

        collection = module_resources.resource_record_from_email_address(self.cars['mail'])
        self.assertEqual(len(collection), 1)
        self.assertEqual(collection[0], self.cars['dn'])

    def test_002_resource_collection(self):
        auth = Auth()
        auth.connect()
        attrs = auth.get_entry_attributes(None, self.cars['dn'], ['*'])
        self.assertIn('groupofuniquenames', attrs['objectclass'])
        self.assertEqual(len(attrs['uniquemember']), 3)
        self.assertEqual(attrs['kolabinvitationpolicy'], 'ACT_ACCEPT')

    def test_003_get_resource_records(self):
        resource_dns = module_resources.resource_record_from_email_address(self.cars['mail'])
        self.assertEqual(resource_dns[0], self.cars['dn'])

        resources = module_resources.get_resource_records(resource_dns)
        self.assertEqual(len(resources), 4)

        # check for (inherited) kolabinvitationpolicy values (bitmasks)
        self.assertEqual(resources[self.cars['dn']]['kolabinvitationpolicy'], [module_resources.ACT_ACCEPT])
        self.assertEqual(resources[self.audi['dn']]['kolabinvitationpolicy'], [module_resources.ACT_ACCEPT])
        self.assertEqual(resources[self.boxter['dn']]['kolabinvitationpolicy'], [module_resources.ACT_ACCEPT_AND_NOTIFY])