Changeset View
Standalone View
tests/unit/test-012-wallace_invitationpolicy.py
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
--=_c8894dbdb8baeedacae836230e3436fd-- | --=_c8894dbdb8baeedacae836230e3436fd-- | ||||
""" | """ | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
if not hasattr(conf, 'defaults'): | if not hasattr(conf, 'defaults'): | ||||
conf.finalize_conf() | conf.finalize_conf() | ||||
class TestWallaceInvitationpolicy(unittest.TestCase): | class TestWallaceInvitationpolicy(unittest.TestCase): | ||||
def setUp(self): | def setUp(self): | ||||
# monkey-patch the pykolab.auth module to check API calls | # monkey-patch the pykolab.auth module to check API calls | ||||
# without actually connecting to LDAP | # without actually connecting to LDAP | ||||
self.patch(pykolab.auth.Auth, "connect", self._mock_nop) | self.patch(pykolab.auth.Auth, "connect", self._mock_nop) | ||||
self.patch(pykolab.auth.Auth, "disconnect", self._mock_nop) | self.patch(pykolab.auth.Auth, "disconnect", self._mock_nop) | ||||
self.patch(pykolab.auth.Auth, "find_user_dn", self._mock_find_user_dn) | self.patch(pykolab.auth.Auth, "find_user_dn", self._mock_find_user_dn) | ||||
self.patch(pykolab.auth.Auth, "get_entry_attributes", self._mock_get_entry_attributes) | self.patch(pykolab.auth.Auth, "get_entry_attributes", self._mock_get_entry_attributes) | ||||
Lint: PEP8 E501: line too long (94 > 79 characters) | |||||
self.patch(pykolab.auth.Auth, "list_domains", self._mock_list_domains) | self.patch(pykolab.auth.Auth, "list_domains", self._mock_list_domains) | ||||
# intercept calls to smtplib.SMTP.sendmail() | # intercept calls to smtplib.SMTP.sendmail() | ||||
import smtplib | import smtplib | ||||
self.patch(smtplib.SMTP, "__init__", self._mock_smtp_init) | self.patch(smtplib.SMTP, "__init__", self._mock_smtp_init) | ||||
self.patch(smtplib.SMTP, "quit", self._mock_nop) | self.patch(smtplib.SMTP, "quit", self._mock_nop) | ||||
self.patch(smtplib.SMTP, "sendmail", self._mock_smtp_sendmail) | self.patch(smtplib.SMTP, "sendmail", self._mock_smtp_sendmail) | ||||
self.smtplog = []; | self.smtplog = [] | ||||
def _mock_find_user_dn(self, value, kolabuser=False): | def _mock_find_user_dn(self, value, kolabuser=False): | ||||
(prefix, domain) = value.split('@') | (prefix, domain) = value.split('@') | ||||
return "uid=" + prefix + ",ou=People,dc=" + ",dc=".join(domain.split('.')) | return "uid=" + prefix + ",ou=People,dc=" + ",dc=".join(domain.split('.')) | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
def _mock_get_entry_attributes(self, domain, entry, attributes): | def _mock_get_entry_attributes(self, domain, entry, attributes): | ||||
(_, uid) = entry.split(',')[0].split('=') | (_, uid) = entry.split(',')[0].split('=') | ||||
return { 'cn': uid, 'mail': uid + "@example.org", '_attrib': attributes } | return {'cn': uid, 'mail': uid + "@example.org", '_attrib': attributes} | ||||
def _mock_list_domains(self): | def _mock_list_domains(self): | ||||
return {'example.org': 'example.org'} | return {'example.org': 'example.org'} | ||||
def _mock_nop(self, domain=None): | def _mock_nop(self, domain=None): | ||||
pass | pass | ||||
def _mock_smtp_init(self, host=None, port=None, local_hostname=None, timeout=0): | def _mock_smtp_init(self, host=None, port=None, local_hostname=None, timeout=0): | ||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
pass | pass | ||||
def _mock_smtp_sendmail(self, from_addr, to_addr, message, mail_options=None, rcpt_options=None): | def _mock_smtp_sendmail(self, from_addr, to_addr, message, mail_options=None, rcpt_options=None): | ||||
Lint: PEP8 E501 line too long (101 > 79 characters) Lint: PEP8 E501: line too long (101 > 79 characters) | |||||
self.smtplog.append((from_addr, to_addr, message)) | self.smtplog.append((from_addr, to_addr, message)) | ||||
return True | return True | ||||
def test_001_itip_events_from_message(self): | def test_001_itip_events_from_message(self): | ||||
itips = pykolab.itip.events_from_message(message_from_string(itip_multipart)) | itips = pykolab.itip.events_from_message(message_from_string(itip_multipart)) | ||||
Lint: PEP8 E501 line too long (85 > 79 characters) Lint: PEP8 E501: line too long (85 > 79 characters) | |||||
self.assertEqual(len(itips), 1, "Multipart iTip message with text/calendar") | self.assertEqual(len(itips), 1, "Multipart iTip message with text/calendar") | ||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
self.assertEqual(itips[0]['method'], "REQUEST", "iTip request method property") | self.assertEqual(itips[0]['method'], "REQUEST", "iTip request method property") | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
self.assertEqual(len(itips[0]['attendees']), 2, "List attendees from iTip") | self.assertEqual(len(itips[0]['attendees']), 2, "List attendees from iTip") | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
self.assertEqual(itips[0]['attendees'][0], "mailto:jane.doe@example.org", "First attendee from iTip") | self.assertEqual(itips[0]['attendees'][0], "mailto:jane.doe@example.org", "First attendee from iTip") | ||||
Lint: PEP8 E501 line too long (109 > 79 characters) Lint: PEP8 E501: line too long (109 > 79 characters) | |||||
def test_002_user_dn_from_email_address(self): | def test_002_user_dn_from_email_address(self): | ||||
res = MIP.user_dn_from_email_address("doe@example.org") | res = MIP.user_dn_from_email_address("doe@example.org") | ||||
self.assertEqual("uid=doe,ou=People,dc=example,dc=org", res) | self.assertEqual("uid=doe,ou=People,dc=example,dc=org", res) | ||||
def test_003_get_matching_invitation_policy(self): | def test_003_get_matching_invitation_policy(self): | ||||
user = { 'kolabinvitationpolicy': [ | user = {'kolabinvitationpolicy': [ | ||||
'TASK_REJECT:*', | 'TASK_REJECT:*', | ||||
'EVENT_ACCEPT:example.org', | 'EVENT_ACCEPT:example.org', | ||||
'EVENT_REJECT:gmail.com', | 'EVENT_REJECT:gmail.com', | ||||
'ALL_UPDATE:outlook:com', | 'ALL_UPDATE:outlook:com', | ||||
'ALL_MANUAL:*' | 'ALL_MANUAL:*' | ||||
] } | ]} | ||||
self.assertEqual(MIP.get_matching_invitation_policies(user, 'a@fastmail.net', MIP.COND_TYPE_EVENT), [MIP.ACT_MANUAL]) | self.assertEqual(MIP.get_matching_invitation_policies(user, 'a@fastmail.net', MIP.COND_TYPE_EVENT), [MIP.ACT_MANUAL]) | ||||
Lint: PEP8 E501 line too long (127 > 79 characters) Lint: PEP8 E501: line too long (127 > 79 characters) | |||||
self.assertEqual(MIP.get_matching_invitation_policies(user, 'b@example.org', MIP.COND_TYPE_EVENT), [MIP.ACT_ACCEPT, MIP.ACT_MANUAL]) | self.assertEqual(MIP.get_matching_invitation_policies(user, 'b@example.org', MIP.COND_TYPE_EVENT), [MIP.ACT_ACCEPT, MIP.ACT_MANUAL]) | ||||
Lint: PEP8 E501 line too long (143 > 79 characters) Lint: PEP8 E501: line too long (143 > 79 characters) | |||||
self.assertEqual(MIP.get_matching_invitation_policies(user, 'c@gmail.com', MIP.COND_TYPE_EVENT), [MIP.ACT_REJECT, MIP.ACT_MANUAL]) | self.assertEqual(MIP.get_matching_invitation_policies(user, 'c@gmail.com', MIP.COND_TYPE_EVENT), [MIP.ACT_REJECT, MIP.ACT_MANUAL]) | ||||
Lint: PEP8 E501 line too long (143 > 79 characters) Lint: PEP8 E501: line too long (143 > 79 characters) | |||||
self.assertEqual(MIP.get_matching_invitation_policies(user, 'd@somedomain.net', MIP.COND_TYPE_TASK), [MIP.ACT_REJECT, MIP.ACT_MANUAL]) | self.assertEqual(MIP.get_matching_invitation_policies(user, 'd@somedomain.net', MIP.COND_TYPE_TASK), [MIP.ACT_REJECT, MIP.ACT_MANUAL]) | ||||
Lint: PEP8 E501 line too long (143 > 79 characters) Lint: PEP8 E501: line too long (143 > 79 characters) | |||||
user = { 'kolabinvitationpolicy': ['ALL_SAVE_TO_FOLDER:maya.foo@example.org', 'ACT_REJECT:others'] } | user = {'kolabinvitationpolicy': ['ALL_SAVE_TO_FOLDER:maya.foo@example.org', 'ACT_REJECT:others']} | ||||
Lint: PEP8 E501 line too long (106 > 79 characters) Lint: PEP8 E501: line too long (106 > 79 characters) | |||||
self.assertEqual(MIP.get_matching_invitation_policies(user, 'maya.foo@example.org', MIP.COND_TYPE_ALL), [MIP.ACT_SAVE_TO_FOLDER]) | self.assertEqual(MIP.get_matching_invitation_policies(user, 'maya.foo@example.org', MIP.COND_TYPE_ALL), [MIP.ACT_SAVE_TO_FOLDER]) | ||||
Lint: PEP8 E501 line too long (137 > 79 characters) Lint: PEP8 E501: line too long (137 > 79 characters) | |||||
self.assertEqual(MIP.get_matching_invitation_policies(user, 'd@somedomain.net', MIP.COND_TYPE_ALL), [MIP.ACT_MANUAL]) | self.assertEqual(MIP.get_matching_invitation_policies(user, 'd@somedomain.net', MIP.COND_TYPE_ALL), [MIP.ACT_MANUAL]) | ||||
Lint: PEP8 E501 line too long (129 > 79 characters) Lint: PEP8 E501: line too long (129 > 79 characters) | |||||
# def test_004_write_locks(self): | # def test_004_write_locks(self): | ||||
# user = { 'cn': 'John Doe', 'mail': "doe@example.org" } | # user = { 'cn': 'John Doe', 'mail': "doe@example.org" } | ||||
# | # | ||||
# lock_key = MIP.get_lock_key(user, '1234567890-abcdef') | # lock_key = MIP.get_lock_key(user, '1234567890-abcdef') | ||||
# lock_file = os.path.join(MIP.mybasepath, 'locks', lock_key + '.lock') | # lock_file = os.path.join(MIP.mybasepath, 'locks', lock_key + '.lock') | ||||
# MIP.set_write_lock(lock_key) | # MIP.set_write_lock(lock_key) | ||||
# | # | ||||
# time.sleep(1) | # time.sleep(1) | ||||
# self.assertTrue(os.path.isfile(lock_file)) | # self.assertTrue(os.path.isfile(lock_file)) | ||||
# self.assertFalse(MIP.set_write_lock(lock_key, False)) | # self.assertFalse(MIP.set_write_lock(lock_key, False)) | ||||
# | # | ||||
# MIP.remove_write_lock(lock_key) | # MIP.remove_write_lock(lock_key) | ||||
# self.assertFalse(os.path.isfile(lock_file)) | # self.assertFalse(os.path.isfile(lock_file)) | ||||
def test_005_is_auto_reply(self): | def test_005_is_auto_reply(self): | ||||
all_manual = [ 'ACT_MANUAL' ] | all_manual = ['ACT_MANUAL'] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
accept_none = [ 'ACT_REJECT' ] | accept_none = ['ACT_REJECT'] | ||||
accept_all = [ 'ACT_ACCEPT', 'ACT_UPDATE' ] | accept_all = ['ACT_ACCEPT', 'ACT_UPDATE'] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
accept_cond = [ 'ACT_ACCEPT_IF_NO_CONFLICT', 'ACT_REJECT_IF_CONFLICT' ] | accept_cond = ['ACT_ACCEPT_IF_NO_CONFLICT', 'ACT_REJECT_IF_CONFLICT'] | ||||
accept_some = [ 'ACT_ACCEPT_IF_NO_CONFLICT', 'ACT_SAVE_TO_CALENDAR:example.org', 'ACT_REJECT_IF_CONFLICT' ] | accept_some = ['ACT_ACCEPT_IF_NO_CONFLICT', 'ACT_SAVE_TO_CALENDAR:example.org', 'ACT_REJECT_IF_CONFLICT'] | ||||
Lint: PEP8 E501 line too long (113 > 79 characters) Lint: PEP8 E501: line too long (113 > 79 characters) | |||||
accept_avail = [ 'ACT_ACCEPT_IF_NO_CONFLICT', 'ACT_REJECT_IF_CONFLICT:example.org' ] | accept_avail = ['ACT_ACCEPT_IF_NO_CONFLICT', 'ACT_REJECT_IF_CONFLICT:example.org'] | ||||
Lint: PEP8 E501 line too long (90 > 79 characters) Lint: PEP8 E501: line too long (90 > 79 characters) | |||||
self.assertFalse( MIP.is_auto_reply({ 'kolabinvitationpolicy':all_manual }, 'user@domain.org', 'event')) | self.assertFalse( MIP.is_auto_reply({'kolabinvitationpolicy': all_manual}, 'user@domain.org', 'event')) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (113 > 79 characters) Lint: PEP8 E501: line too long (113 > 79 characters) | |||||
self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_none }, 'user@domain.org', 'event')) | self.assertTrue( MIP.is_auto_reply({'kolabinvitationpolicy': accept_none}, 'user@domain.org', 'event')) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (113 > 79 characters) Lint: PEP8 E501: line too long (113 > 79 characters) | |||||
self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_all }, 'user@domain.com', 'event')) | self.assertTrue( MIP.is_auto_reply({'kolabinvitationpolicy': accept_all}, 'user@domain.com', 'event')) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (113 > 79 characters) Lint: PEP8 E501: line too long (113 > 79 characters) | |||||
self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_cond }, 'user@domain.com', 'event')) | self.assertTrue( MIP.is_auto_reply({'kolabinvitationpolicy': accept_cond}, 'user@domain.com', 'event')) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (113 > 79 characters) Lint: PEP8 E501: line too long (113 > 79 characters) | |||||
self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_some }, 'user@domain.com', 'event')) | self.assertTrue( MIP.is_auto_reply({'kolabinvitationpolicy': accept_some}, 'user@domain.com', 'event')) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (113 > 79 characters) Lint: PEP8 E501: line too long (113 > 79 characters) | |||||
self.assertFalse( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_some }, 'sam@example.org', 'event')) | self.assertFalse( MIP.is_auto_reply({'kolabinvitationpolicy': accept_some}, 'sam@example.org', 'event')) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (113 > 79 characters) Lint: PEP8 E501: line too long (113 > 79 characters) | |||||
self.assertFalse( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_avail }, 'user@domain.com', 'event')) | self.assertFalse( MIP.is_auto_reply({'kolabinvitationpolicy': accept_avail}, 'user@domain.com', 'event')) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (113 > 79 characters) Lint: PEP8 E501: line too long (113 > 79 characters) | |||||
self.assertTrue( MIP.is_auto_reply({ 'kolabinvitationpolicy':accept_avail }, 'john@example.org', 'event')) | self.assertTrue( MIP.is_auto_reply({'kolabinvitationpolicy': accept_avail}, 'john@example.org', 'event')) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (114 > 79 characters) Lint: PEP8 E501: line too long (114 > 79 characters) | |||||
def test_006_send_update_notification(self): | def test_006_send_update_notification(self): | ||||
itips = pykolab.itip.events_from_message(message_from_string(itip_multipart.replace('SUMMARY:test', 'SUMMARY:with äöü'))) | itips = pykolab.itip.events_from_message(message_from_string(itip_multipart.replace('SUMMARY:test', 'SUMMARY:with äöü'))) | ||||
Lint: PEP8 E501 line too long (129 > 79 characters) Lint: PEP8 E501: line too long (129 > 79 characters) | |||||
MIP.send_update_notification(itips[0]['xml'], { 'mail': 'sender@example.org' }, old=None, reply=True) | MIP.send_update_notification(itips[0]['xml'], {'mail': 'sender@example.org'}, old=None, reply=True) | ||||
Lint: PEP8 E501 line too long (107 > 79 characters) Lint: PEP8 E501: line too long (107 > 79 characters) | |||||
self.assertEqual(len(self.smtplog), 1) | self.assertEqual(len(self.smtplog), 1) | ||||
self.assertIn("Subject: =?utf-8?", self.smtplog[0][2]) | self.assertIn("Subject: =?utf-8?", self.smtplog[0][2]) | ||||
self.assertIn("The event 'with =C3=A4=C3=B6=C3=BC' at", self.smtplog[0][2]) | self.assertIn("The event 'with =C3=A4=C3=B6=C3=BC' at", self.smtplog[0][2]) | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
line too long (94 > 79 characters)