summaryrefslogtreecommitdiff
path: root/src/mailman/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/app')
-rw-r--r--src/mailman/app/tests/test_membership.py11
-rw-r--r--src/mailman/app/tests/test_subscriptions.py14
-rw-r--r--src/mailman/app/tests/test_templates.py42
3 files changed, 20 insertions, 47 deletions
diff --git a/src/mailman/app/tests/test_membership.py b/src/mailman/app/tests/test_membership.py
index 113ae6a52..a22a239b7 100644
--- a/src/mailman/app/tests/test_membership.py
+++ b/src/mailman/app/tests/test_membership.py
@@ -137,17 +137,14 @@ class AddMemberTest(unittest.TestCase):
'Anne Person', '123', DeliveryMode.regular,
system_preferences.preferred_language,
MemberRole.member)
- try:
+ with self.assertRaises(AlreadySubscribedError) as cm:
add_member(self._mlist, 'aperson@example.com',
'Anne Person', '123', DeliveryMode.regular,
system_preferences.preferred_language,
MemberRole.member)
- except AlreadySubscribedError as exc:
- self.assertEqual(exc.fqdn_listname, 'test@example.com')
- self.assertEqual(exc.email, 'aperson@example.com')
- self.assertEqual(exc.role, MemberRole.member)
- else:
- raise AssertionError('AlreadySubscribedError expected')
+ self.assertEqual(cm.exception.fqdn_listname, 'test@example.com')
+ self.assertEqual(cm.exception.email, 'aperson@example.com')
+ self.assertEqual(cm.exception.role, MemberRole.member)
def test_add_member_with_different_roles(self):
# Adding a member twice with different roles is okay.
diff --git a/src/mailman/app/tests/test_subscriptions.py b/src/mailman/app/tests/test_subscriptions.py
index 1c37d4cb9..c4c8f2795 100644
--- a/src/mailman/app/tests/test_subscriptions.py
+++ b/src/mailman/app/tests/test_subscriptions.py
@@ -51,19 +51,13 @@ class TestJoin(unittest.TestCase):
def test_join_user_with_bogus_id(self):
# When `subscriber` is a missing user id, an exception is raised.
- try:
+ with self.assertRaises(MissingUserError) as cm:
self._service.join('test.example.com', uuid.UUID(int=99))
- except MissingUserError as exc:
- self.assertEqual(exc.user_id, uuid.UUID(int=99))
- else:
- raise AssertionError('MissingUserError expected')
+ self.assertEqual(cm.exception.user_id, uuid.UUID(int=99))
def test_join_user_with_invalid_email_address(self):
# When `subscriber` is a string that is not an email address, an
# exception is raised.
- try:
+ with self.assertRaises(InvalidEmailAddressError) as cm:
self._service.join('test.example.com', 'bogus')
- except InvalidEmailAddressError as exc:
- self.assertEqual(exc.email, 'bogus')
- else:
- raise AssertionError('InvalidEmailAddressError expected')
+ self.assertEqual(cm.exception.email, 'bogus')
diff --git a/src/mailman/app/tests/test_templates.py b/src/mailman/app/tests/test_templates.py
index 6dfbd7109..788412a57 100644
--- a/src/mailman/app/tests/test_templates.py
+++ b/src/mailman/app/tests/test_templates.py
@@ -98,49 +98,31 @@ class TestTemplateLoader(unittest.TestCase):
self.assertEqual(content, 'Test content')
def test_uri_not_found(self):
- try:
+ with self.assertRaises(urllib2.URLError) as cm:
self._loader.get('mailman:///missing.txt')
- except urllib2.URLError as error:
- self.assertEqual(error.reason, 'No such file')
- else:
- raise AssertionError('Exception expected')
+ self.assertEqual(cm.exception.reason, 'No such file')
def test_shorter_url_error(self):
- try:
+ with self.assertRaises(urllib2.URLError) as cm:
self._loader.get('mailman:///')
- except urllib2.URLError as error:
- self.assertEqual(error.reason, 'No template specified')
- else:
- raise AssertionError('Exception expected')
+ self.assertEqual(cm.exception.reason, 'No template specified')
def test_short_url_error(self):
- try:
+ with self.assertRaises(urllib2.URLError) as cm:
self._loader.get('mailman://')
- except urllib2.URLError as error:
- self.assertEqual(error.reason, 'No template specified')
- else:
- raise AssertionError('Exception expected')
+ self.assertEqual(cm.exception.reason, 'No template specified')
def test_bad_language(self):
- try:
+ with self.assertRaises(urllib2.URLError) as cm:
self._loader.get('mailman:///xx/demo.txt')
- except urllib2.URLError as error:
- self.assertEqual(error.reason, 'Bad language or list name')
- else:
- raise AssertionError('Exception expected')
+ self.assertEqual(cm.exception.reason, 'Bad language or list name')
def test_bad_mailing_list(self):
- try:
+ with self.assertRaises(urllib2.URLError) as cm:
self._loader.get('mailman:///missing@example.com/demo.txt')
- except urllib2.URLError as error:
- self.assertEqual(error.reason, 'Bad language or list name')
- else:
- raise AssertionError('Exception expected')
+ self.assertEqual(cm.exception.reason, 'Bad language or list name')
def test_too_many_path_components(self):
- try:
+ with self.assertRaises(urllib2.URLError) as cm:
self._loader.get('mailman:///missing@example.com/en/foo/demo.txt')
- except urllib2.URLError as error:
- self.assertEqual(error.reason, 'No such file')
- else:
- raise AssertionError('Exception expected')
+ self.assertEqual(cm.exception.reason, 'No such file')