diff options
author | Thomas Bruederli <bruederli@kolabsys.com> | 2014-03-05 12:44:09 -0500 |
---|---|---|
committer | Thomas Bruederli <bruederli@kolabsys.com> | 2014-03-05 12:44:09 -0500 |
commit | 5e9e21061bfe45f05c4e0f2567f3838ec57e9a19 (patch) | |
tree | ab516b5f4b6e0ce9bedde5acb7cf500369f20369 /tests | |
parent | b3afa468579586b62aee849779c89d0104c3d21e (diff) | |
download | pykolab-5e9e21061bfe45f05c4e0f2567f3838ec57e9a19.tar.gz |
Test owner assignment for resources and mentions in reservation request responses
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/resource_func.py | 5 | ||||
-rw-r--r-- | tests/functional/test_wallace/test_005_resource_invitation.py | 55 | ||||
-rw-r--r-- | tests/functional/user_add.py | 2 | ||||
-rw-r--r-- | tests/unit/test-011-wallace_resources.py | 23 |
4 files changed, 76 insertions, 9 deletions
diff --git a/tests/functional/resource_func.py b/tests/functional/resource_func.py index e3519d1..43aca96 100644 --- a/tests/functional/resource_func.py +++ b/tests/functional/resource_func.py @@ -4,7 +4,7 @@ from pykolab import wap_client conf = pykolab.getConf() -def resource_add(type, cn, members=None): +def resource_add(type, cn, members=None, owner=None): if type == None or type == '': raise Exception @@ -14,7 +14,8 @@ def resource_add(type, cn, members=None): resource_details = { 'cn': cn, 'kolabtargetfolder': "shared/Resources/" + cn + "@example.org", - 'uniquemember': members + 'uniquemember': members, + 'owner': owner } result = wap_client.authenticate(conf.get('ldap', 'bind_dn'), conf.get('ldap', 'bind_pw'), conf.get('kolab', 'primary_domain')) diff --git a/tests/functional/test_wallace/test_005_resource_invitation.py b/tests/functional/test_wallace/test_005_resource_invitation.py index 53ed2ec..8a1d844 100644 --- a/tests/functional/test_wallace/test_005_resource_invitation.py +++ b/tests/functional/test_wallace/test_005_resource_invitation.py @@ -194,11 +194,21 @@ class TestResourceInvitation(unittest.TestCase): 'displayname': 'John Doe', 'mail': 'john.doe@example.org', 'sender': 'John Doe <john.doe@example.org>', - 'mailbox': 'user/john.doe@example.org' + 'mailbox': 'user/john.doe@example.org', + 'dn': 'uid=doe,ou=People,dc=example,dc=org' + } + + self.jane = { + 'displayname': 'Jane Manager', + 'mail': 'jane.manager@example.org', + 'sender': 'Jane Manager <jane.manager@example.org>', + 'mailbox': 'user/jane.manager@example.org', + 'dn': 'uid=manager,ou=People,dc=example,dc=org' } from tests.functional.user_add import user_add user_add("John", "Doe") + user_add("Jane", "Manager") funcs.purge_resources() self.audi = funcs.resource_add("car", "Audi A4") @@ -206,6 +216,10 @@ class TestResourceInvitation(unittest.TestCase): self.boxter = funcs.resource_add("car", "Porsche Boxter S") self.cars = funcs.resource_add("collection", "Company Cars", [ self.audi['dn'], self.passat['dn'], self.boxter['dn'] ]) + self.room1 = funcs.resource_add("confroom", "Room 101", owner=self.jane['dn']) + self.room2 = funcs.resource_add("confroom", "Conference Room B-222") + self.rooms = funcs.resource_add("collection", "Rooms", [ self.room1['dn'], self.room2['dn'] ], self.jane['dn']) + time.sleep(1) from tests.functional.synchronize import synchronize_once synchronize_once() @@ -267,11 +281,14 @@ class TestResourceInvitation(unittest.TestCase): return uid - def check_message_received(self, subject, from_addr=None): + def check_message_received(self, subject, from_addr=None, mailbox=None): + if mailbox is None: + mailbox = self.john['mailbox'] + imap = IMAP() imap.connect() - imap.set_acl(self.john['mailbox'], "cyrus-admin", "lrs") - imap.imap.m.select(self.john['mailbox']) + imap.set_acl(mailbox, "cyrus-admin", "lrs") + imap.imap.m.select(mailbox) found = None retries = 10 @@ -520,3 +537,33 @@ class TestResourceInvitation(unittest.TestCase): self.assertEqual(self.check_message_received("Reservation Request for test was ACCEPTED", self.audi['mail']), None) + + def test_011_owner_info(self): + self.purge_mailbox(self.john['mailbox']) + + self.send_itip_invitation(self.room1['mail'], datetime.datetime(2014,6,19, 16,0,0)) + + accept = self.check_message_received("Reservation Request for test was ACCEPTED", self.room1['mail']) + self.assertIsInstance(accept, email.message.Message) + respose_text = str(accept.get_payload(0)) + self.assertIn(self.jane['mail'], respose_text) + self.assertIn(self.jane['displayname'], respose_text) + + + def TODO_test_012_owner_notification(self): + self.purge_mailbox(self.john['mailbox']) + self.purge_mailbox(self.jane['mailbox']) + + self.send_itip_invitation(self.room1['mail'], datetime.datetime(2014,5,4, 13,0,0)) + + # check notification message sent to resource owner (jane) + notify = self.check_message_received("Reservation Request for test was ACCEPTED", self.room1['mail'], self.jane['mailbox']) + self.assertIsInstance(notify, email.message.Message) + self.assertEqual(notify['From'], self.room1['mail']) + self.assertEqual(notify['Cc'], self.jane['mail']) + + # check notification sent to collection owner (jane) + self.send_itip_invitation(self.rooms['mail'], datetime.datetime(2014,5,4, 12,30,0)) + + notify = self.check_message_received("Reservation Request for test was ACCEPTED", self.room2['mail'], self.jane['mailbox']) + self.assertIsInstance(notify, email.message.Message) diff --git a/tests/functional/user_add.py b/tests/functional/user_add.py index 6af0419..4939f93 100644 --- a/tests/functional/user_add.py +++ b/tests/functional/user_add.py @@ -49,7 +49,7 @@ def user_add(givenname, sn, preferredlanguage='en_US'): attr_details = user_type_info['form_fields'][attribute] if isinstance(attr_details, dict): - if not attr_details.has_key('optional') or attr_details['optional'] == False: + if not attr_details.has_key('optional') or attr_details['optional'] == False or user_details.has_key(attribute): params[attribute] = user_details[attribute] elif isinstance(attr_details, list): params[attribute] = user_details[attribute] diff --git a/tests/unit/test-011-wallace_resources.py b/tests/unit/test-011-wallace_resources.py index 50fdc6b..6198a6f 100644 --- a/tests/unit/test-011-wallace_resources.py +++ b/tests/unit/test-011-wallace_resources.py @@ -245,6 +245,7 @@ class TestWallaceResources(unittest.TestCase): self.patch(pykolab.auth.Auth, "connect", self._mock_nop) self.patch(pykolab.auth.Auth, "disconnect", self._mock_nop) self.patch(pykolab.auth.Auth, "find_resource", self._mock_find_resource) + self.patch(pykolab.auth.Auth, "get_entry_attributes", self._mock_get_entry_attributes) # intercept calls to smtplib.SMTP.sendmail() import smtplib @@ -262,6 +263,10 @@ class TestWallaceResources(unittest.TestCase): entry_dn = "uid=" + prefix + ",dc=" + ",dc=".join(domain.split('.')) return [ entry_dn ]; + def _mock_get_entry_attributes(self, domain, entry, attributes): + (_, uid) = entry.split(',')[0].split('=') + return { 'cn': uid, 'mail': uid + "@example.org", '_attrib': attributes } + def _mock_smtp_init(self, host=None, port=None, local_hostname=None, timeout=0): pass @@ -334,7 +339,21 @@ class TestWallaceResources(unittest.TestCase): self.assertEqual("uid=resource-collection-car,dc=example,dc=org", res[0]); - def test_004_send_response_accept(self): + def test_004_get_resource_owner(self): + owner1 = module_resources.get_resource_owner({ 'owner': "uid=foo,ou=People,cd=example,dc=org" }) + self.assertIsInstance(owner1, dict) + self.assertEqual("foo@example.org", owner1['mail']) + self.assertIn("telephoneNumber", owner1['_attrib']) + + owner2 = module_resources.get_resource_owner({ 'owner': ["uid=john,ou=People,cd=example,dc=org", "uid=jane,ou=People,cd=example,dc=org"] }) + self.assertIsInstance(owner2, dict) + self.assertEqual("john@example.org", owner2['mail']) + + owner3 = module_resources.get_resource_owner({ 'dn': "uid=cars,ou=Resources,cd=example,dc=org" }) + self.assertEqual(owner3, None) + + + def test_005_send_response_accept(self): itip_event = module_resources.itip_events_from_message(message_from_string(itip_non_multipart)) module_resources.send_response("resource-collection-car@example.org", itip_event) @@ -352,7 +371,7 @@ class TestWallaceResources(unittest.TestCase): self.assertEqual(ics_part.get_param('method'), "REPLY") - def test_005_send_response_delegate(self): + def test_006_send_response_delegate(self): # delegate resource-collection-car@example.org => resource-car-audi-a4@example.org itip_event = module_resources.itip_events_from_message(message_from_string(itip_non_multipart))[0] itip_event['xml'].delegate('resource-collection-car@example.org', 'resource-car-audi-a4@example.org') |