2 commits - tests/functional tests/unit wallace/module_resources.py
Thomas Brüderli
bruederli at kolabsys.com
Tue Mar 25 10:37:52 CET 2014
tests/functional/test_wallace/test_005_resource_invitation.py | 12 ++
tests/unit/test-011-wallace_resources.py | 41 +++++++++-
wallace/module_resources.py | 30 +++++--
3 files changed, 74 insertions(+), 9 deletions(-)
New commits:
commit 3d3b77f78c11151e174184335dfc1c6bd05bfa29
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Mar 19 19:46:34 2014 -0400
Get resource owner information from parent collection if not set directly
diff --git a/tests/functional/test_wallace/test_005_resource_invitation.py b/tests/functional/test_wallace/test_005_resource_invitation.py
index 8a1d844..aad5fd5 100644
--- a/tests/functional/test_wallace/test_005_resource_invitation.py
+++ b/tests/functional/test_wallace/test_005_resource_invitation.py
@@ -550,6 +550,18 @@ class TestResourceInvitation(unittest.TestCase):
self.assertIn(self.jane['displayname'], respose_text)
+ def test_011_owner_info_from_collection(self):
+ self.purge_mailbox(self.john['mailbox'])
+
+ self.send_itip_invitation(self.room2['mail'], datetime.datetime(2014,6,19, 16,0,0))
+
+ accept = self.check_message_received("Reservation Request for test was ACCEPTED", self.room2['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'])
diff --git a/tests/unit/test-011-wallace_resources.py b/tests/unit/test-011-wallace_resources.py
index 8b01874..62bfd27 100644
--- a/tests/unit/test-011-wallace_resources.py
+++ b/tests/unit/test-011-wallace_resources.py
@@ -247,6 +247,7 @@ class TestWallaceResources(unittest.TestCase):
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)
+ self.patch(pykolab.auth.Auth, "search_entry_by_attribute", self._mock_search_entry_by_attribute)
# intercept calls to smtplib.SMTP.sendmail()
import smtplib
@@ -268,6 +269,12 @@ class TestWallaceResources(unittest.TestCase):
(_, uid) = entry.split(',')[0].split('=')
return { 'cn': uid, 'mail': uid + "@example.org", '_attrib': attributes }
+ def _mock_search_entry_by_attribute(self, attr, value, **kw):
+ results = []
+ if value == "cn=Room 101,ou=Resources,dc=example,dc=org":
+ results.append({ 'dn': 'cn=Rooms,ou=Resources,dc=example,dc=org', attr: value, 'owner': 'uid=doe,ou=People,dc=example,dc=org' })
+ return results
+
def _mock_smtp_init(self, host=None, port=None, local_hostname=None, timeout=0):
pass
@@ -353,6 +360,9 @@ class TestWallaceResources(unittest.TestCase):
owner3 = module_resources.get_resource_owner({ 'dn': "uid=cars,ou=Resources,cd=example,dc=org" })
self.assertEqual(owner3, None)
+ owner4 = module_resources.get_resource_owner({ 'dn': "cn=Room 101,ou=Resources,dc=example,dc=org" })
+ self.assertEqual("doe at example.org", owner4['mail'])
+
def test_005_send_response_accept(self):
itip_event = module_resources.itip_events_from_message(message_from_string(itip_non_multipart))
diff --git a/wallace/module_resources.py b/wallace/module_resources.py
index d861614..ede976e 100644
--- a/wallace/module_resources.py
+++ b/wallace/module_resources.py
@@ -221,6 +221,7 @@ def execute(*args, **kw):
# If it is, expand to individual resources
# If it is not, ...
resource_attrs = auth.get_entry_attributes(None, resource_dn, ['*'])
+ resource_attrs['dn'] = resource_dn
if not 'kolabsharedfolder' in [x.lower() for x in resource_attrs['objectclass']]:
if resource_attrs.has_key('uniquemember'):
resources[resource_dn] = resource_attrs
@@ -232,6 +233,7 @@ def execute(*args, **kw):
)
if 'kolabsharedfolder' in [x.lower() for x in resource_attrs['objectclass']]:
+ resource_attrs['dn'] = uniquemember
resources[uniquemember] = resource_attrs
resources[uniquemember]['memberof'] = resource_dn
if not resource_attrs.has_key('owner') and resources[resource_dn].has_key('owner'):
@@ -872,18 +874,30 @@ def get_resource_owner(resource):
auth = Auth()
auth.connect()
+ owners = []
+
if resource.has_key('owner'):
if not isinstance(resource['owner'], list):
- resource['owner'] = [ resource['owner'] ]
-
- for dn in resource['owner']:
- owner = auth.get_entry_attributes(None, dn, ['cn','mail','telephoneNumber'])
- if owner is not None:
- return owner
+ owners = [ resource['owner'] ]
+ else:
+ owners = resource['owner']
else:
- # TODO: get owner attribute from collection
- pass
+ # get owner attribute from collection
+ collections = auth.search_entry_by_attribute('uniquemember', resource['dn'])
+ if not isinstance(collections, list):
+ collections = [ collections ]
+
+ for dn,collection in collections:
+ if collection.has_key('owner') and isinstance(collection['owner'], list):
+ owners += collection['owner']
+ elif collection.has_key('owner'):
+ owners.append(collection['owner'])
+
+ for dn in owners:
+ owner = auth.get_entry_attributes(None, dn, ['cn','mail','telephoneNumber'])
+ if owner is not None:
+ return owner
return None
commit 53e46b7870e48d0a76a997737d4c7df53dee3bd8
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Mar 19 18:49:44 2014 -0400
Add unit tests for wallace module_resources.check_date_conflict; fix invalid iTip block
diff --git a/tests/unit/test-011-wallace_resources.py b/tests/unit/test-011-wallace_resources.py
index 6198a6f..8b01874 100644
--- a/tests/unit/test-011-wallace_resources.py
+++ b/tests/unit/test-011-wallace_resources.py
@@ -1,5 +1,6 @@
import pykolab
import logging
+import datetime
from icalendar import Calendar
from email import message
@@ -47,7 +48,7 @@ DESCRIPTION:test
ORGANIZER;CN=3D"Doe, John":mailto:john.doe at example.org
ATTENDEE;ROLE=3DREQ-PARTICIPANT;PARTSTAT=3DNEEDS-ACTION;RSVP=3DTRUE:mailt=
o:resource-collection-car at example.org
-ATTENDEE;ROLE=3DOPTIONAL;PARTSTAT=3DNEEDS-ACTION;RSVP=3DTRUE:mailto:anoth=
+ATTENDEE;ROLE=3DOPT-PARTICIPANT;PARTSTAT=3DNEEDS-ACTION;RSVP=3DTRUE:mailto:anoth=
er-resource at example.org
TRANSP:OPAQUE
END:VEVENT
@@ -396,3 +397,31 @@ class TestWallaceResources(unittest.TestCase):
self.assertEqual(ical2['attendee'], "MAILTO:resource-collection-car at example.org")
self.assertEqual(ical2['attendee'].params['PARTSTAT'], "DELEGATED")
+
+ def test_007_check_date_conflict(self):
+ astart = datetime.datetime(2014,7,13, 10,0,0)
+ aend = astart + datetime.timedelta(hours=2)
+
+ bstart = datetime.datetime(2014,7,13, 10,0,0)
+ bend = astart + datetime.timedelta(hours=1)
+ self.assertTrue(module_resources.check_date_conflict(astart, aend, bstart, bend))
+
+ bstart = datetime.datetime(2014,7,13, 11,0,0)
+ bend = astart + datetime.timedelta(minutes=30)
+ self.assertTrue(module_resources.check_date_conflict(astart, aend, bstart, bend))
+
+ bend = astart + datetime.timedelta(hours=2)
+ self.assertTrue(module_resources.check_date_conflict(astart, aend, bstart, bend))
+
+ bstart = datetime.datetime(2014,7,13, 12,0,0)
+ bend = astart + datetime.timedelta(hours=1)
+ self.assertFalse(module_resources.check_date_conflict(astart, aend, bstart, bend))
+
+ bstart = datetime.datetime(2014,6,13, 10,0,0)
+ bend = datetime.datetime(2014,6,14, 12,0,0)
+ self.assertFalse(module_resources.check_date_conflict(astart, aend, bstart, bend))
+
+ bstart = datetime.datetime(2014,7,10, 12,0,0)
+ bend = datetime.datetime(2014,7,14, 14,0,0)
+ self.assertTrue(module_resources.check_date_conflict(astart, aend, bstart, bend))
+
More information about the commits
mailing list