summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-07-22 10:03:03 -0400
committerThomas Bruederli <bruederli@kolabsys.com>2014-07-22 10:03:03 -0400
commitb3e6648328dd00dd53e60633b23a40ed6ff578e5 (patch)
tree110102750c6222af2e7fc7944c004056448e6700
parent9876593d6551fe4e7dcd7ce93011f70ebab5b8a1 (diff)
downloadpykolab-b3e6648328dd00dd53e60633b23a40ed6ff578e5.tar.gz
Test localized notifications from iTip messages
-rw-r--r--pykolab/xml/attendee.py2
-rw-r--r--tests/functional/test_wallace/test_007_invitationpolicy.py52
-rw-r--r--wallace/module_invitationpolicy.py3
-rw-r--r--wallace/module_resources.py9
4 files changed, 51 insertions, 15 deletions
diff --git a/pykolab/xml/attendee.py b/pykolab/xml/attendee.py
index a01d955..5d469c2 100644
--- a/pykolab/xml/attendee.py
+++ b/pykolab/xml/attendee.py
@@ -22,7 +22,7 @@ participant_status_labels = {
}
def participant_status_label(status):
- return _(participant_status_labels[status]) if participant_status_labels.has_key(status) else status
+ return _(participant_status_labels[status]) if participant_status_labels.has_key(status) else _(status)
class Attendee(kolabformat.Attendee):
diff --git a/tests/functional/test_wallace/test_007_invitationpolicy.py b/tests/functional/test_wallace/test_007_invitationpolicy.py
index dd419f0..1af22ff 100644
--- a/tests/functional/test_wallace/test_007_invitationpolicy.py
+++ b/tests/functional/test_wallace/test_007_invitationpolicy.py
@@ -178,14 +178,14 @@ class TestWallaceInvitationpolicy(unittest.TestCase):
'kolabinvitationpolicy': ['ACT_TENTATIVE_IF_NO_CONFLICT','ACT_SAVE_TO_CALENDAR','ACT_UPDATE']
}
- self.bob = {
- 'displayname': 'Bob Auto',
- 'mail': 'bob.auto@example.org',
- 'dn': 'uid=auto,ou=People,dc=example,dc=org',
- 'preferredlanguage': 'en_US',
- 'mailbox': 'user/bob.auto@example.org',
- 'kolabtargetfolder': 'user/bob.auto/Calendar@example.org',
- 'kolabinvitationpolicy': ['ACT_ACCEPT','ACT_UPDATE']
+ self.mark = {
+ 'displayname': 'Mark German',
+ 'mail': 'mark.german@example.org',
+ 'dn': 'uid=german,ou=People,dc=example,dc=org',
+ 'preferredlanguage': 'de_DE',
+ 'mailbox': 'user/mark.german@example.org',
+ 'kolabtargetfolder': 'user/mark.german/Calendar@example.org',
+ 'kolabinvitationpolicy': ['ACT_ACCEPT','ACT_UPDATE_AND_NOTIFY']
}
self.external = {
@@ -197,7 +197,7 @@ class TestWallaceInvitationpolicy(unittest.TestCase):
user_add("John", "Doe", kolabinvitationpolicy=self.john['kolabinvitationpolicy'], preferredlanguage=self.john['preferredlanguage'])
user_add("Jane", "Manager", kolabinvitationpolicy=self.jane['kolabinvitationpolicy'], preferredlanguage=self.jane['preferredlanguage'])
user_add("Jack", "Tentative", kolabinvitationpolicy=self.jack['kolabinvitationpolicy'], preferredlanguage=self.jack['preferredlanguage'])
- user_add("Bob", "Auto", kolabinvitationpolicy=self.bob['kolabinvitationpolicy'], preferredlanguage=self.bob['preferredlanguage'])
+ user_add("Mark", "German", kolabinvitationpolicy=self.mark['kolabinvitationpolicy'], preferredlanguage=self.mark['preferredlanguage'])
time.sleep(1)
from tests.functional.synchronize import synchronize_once
@@ -606,18 +606,18 @@ class TestWallaceInvitationpolicy(unittest.TestCase):
self.purge_mailbox(self.john['mailbox'])
start = datetime.datetime(2014,8,12, 16,0,0, tzinfo=pytz.timezone("Europe/Berlin"))
- uid = self.create_calendar_event(start, user=self.john, attendees=[self.jane, self.bob, self.jack])
+ uid = self.create_calendar_event(start, user=self.john, attendees=[self.jane, self.mark, self.jack])
# send a reply from jane to john
self.send_itip_reply(uid, self.jane['mail'], self.john['mail'], start=start)
# check for notification message
- # this notification should be suppressed until bob has replied, too
+ # this notification should be suppressed until mark has replied, too
notification = self.check_message_received(_('"%s" has been updated') % ('test'), self.john['mail'])
self.assertEqual(notification, None)
- # send a reply from bob to john
- self.send_itip_reply(uid, self.bob['mail'], self.john['mail'], start=start, partstat='ACCEPTED')
+ # send a reply from mark to john
+ self.send_itip_reply(uid, self.mark['mail'], self.john['mail'], start=start, partstat='ACCEPTED')
notification = self.check_message_received(_('"%s" has been updated') % ('test'), self.john['mail'])
self.assertIsInstance(notification, email.message.Message)
@@ -628,7 +628,7 @@ class TestWallaceInvitationpolicy(unittest.TestCase):
self.purge_mailbox(self.john['mailbox'])
- # send a reply from bob to john
+ # send a reply from mark to john
self.send_itip_reply(uid, self.jack['mail'], self.john['mail'], start=start, partstat='ACCEPTED')
# this triggers an additional notification
@@ -639,6 +639,28 @@ class TestWallaceInvitationpolicy(unittest.TestCase):
self.assertNotIn(_("PENDING"), notification_text)
+ def test_008_notify_translated(self):
+ self.purge_mailbox(self.mark['mailbox'])
+
+ start = datetime.datetime(2014,8,12, 16,0,0, tzinfo=pytz.timezone("Europe/Berlin"))
+ uid = self.create_calendar_event(start, user=self.mark, attendees=[self.jane])
+
+ # send a reply from jane to mark
+ self.send_itip_reply(uid, self.jane['mail'], self.mark['mail'], start=start)
+
+ # change translations to de_DE
+ pykolab.translate.setUserLanguage(self.mark['preferredlanguage'])
+ notification = self.check_message_received(_('"%s" has been updated') % ('test'), self.mark['mail'], self.mark['mailbox'])
+ self.assertIsInstance(notification, email.message.Message)
+
+ notification_text = str(notification.get_payload());
+ self.assertIn(self.jane['mail'], notification_text)
+ self.assertIn(participant_status_label("ACCEPTED")+":", notification_text)
+
+ # reset localization
+ pykolab.translate.setUserLanguage(conf.get('kolab','default_locale'))
+
+
def test_009_outdated_reply(self):
self.purge_mailbox(self.john['mailbox'])
@@ -711,3 +733,5 @@ class TestWallaceInvitationpolicy(unittest.TestCase):
jacks = self.check_user_calendar_event(self.jack['kolabtargetfolder'], uid)
self.assertEqual(jacks.get_attendee(self.jane['mail']).get_participant_status(), kolabformat.PartAccepted)
self.assertEqual(jacks.get_attendee(self.jack['mail']).get_participant_status(), kolabformat.PartNeedsAction)
+
+
diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py
index 03585ee..de29450 100644
--- a/wallace/module_invitationpolicy.py
+++ b/wallace/module_invitationpolicy.py
@@ -144,6 +144,9 @@ def cleanup():
def execute(*args, **kw):
global auth, imap
+ # (re)set language to default
+ pykolab.translate.setUserLanguage(conf.get('kolab','default_locale'))
+
if not os.path.isdir(mybasepath):
os.makedirs(mybasepath)
diff --git a/wallace/module_resources.py b/wallace/module_resources.py
index dba2653..b31a8d0 100644
--- a/wallace/module_resources.py
+++ b/wallace/module_resources.py
@@ -100,6 +100,9 @@ def cleanup():
def execute(*args, **kw):
global auth, imap
+ # (re)set language to default
+ pykolab.translate.setUserLanguage(conf.get('kolab','default_locale'))
+
if not os.path.isdir(mybasepath):
os.makedirs(mybasepath)
@@ -875,6 +878,8 @@ def send_response(from_address, itip_events, owner=None):
attendee = itip_event['xml'].get_attendee_by_email(from_address)
participant_status = itip_event['xml'].get_ical_attendee_participant_status(attendee)
+ # TODO: look-up event organizer in LDAP and change localization to its preferredlanguage
+
message_text = reservation_response_text(participant_status, owner)
subject_template = _("Reservation Request for %(summary)s was %(status)s")
@@ -944,6 +949,10 @@ def send_owner_notification(resource, owner, itip_event, success=True):
level=8
)
+ # change gettext language to the preferredlanguage setting of the resource owner
+ if owner.has_key('preferredlanguage'):
+ pykolab.translate.setUserLanguage(owner['preferredlanguage'])
+
message_text = owner_notification_text(resource, owner, itip_event['xml'], success)
msg = MIMEText(utils.stripped_message(message_text))