summaryrefslogtreecommitdiff
path: root/src/mailman/rest/tests/test_moderation.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/rest/tests/test_moderation.py')
-rw-r--r--src/mailman/rest/tests/test_moderation.py105
1 files changed, 52 insertions, 53 deletions
diff --git a/src/mailman/rest/tests/test_moderation.py b/src/mailman/rest/tests/test_moderation.py
index 3d3b234c7..0a9bb2608 100644
--- a/src/mailman/rest/tests/test_moderation.py
+++ b/src/mailman/rest/tests/test_moderation.py
@@ -96,7 +96,7 @@ Something else.
call_api(url.format(held_id), {'action': 'bogus'})
self.assertEqual(cm.exception.code, 400)
self.assertEqual(cm.exception.msg,
- b'Cannot convert parameters: action')
+ 'Cannot convert parameters: action')
def test_discard(self):
# Discarding a message removes it from the moderation queue.
@@ -104,8 +104,8 @@ Something else.
held_id = hold_message(self._mlist, self._msg)
url = 'http://localhost:9001/3.0/lists/ant@example.com/held/{}'.format(
held_id)
- content, response = call_api(url, dict(action='discard'))
- self.assertEqual(response.status, 204)
+ json, response = call_api(url, dict(action='discard'))
+ self.assertEqual(response.status_code, 204)
# Now it's gone.
with self.assertRaises(HTTPError) as cm:
call_api(url, dict(action='discard'))
@@ -115,11 +115,11 @@ Something else.
# We can view all the held requests.
with transaction():
held_id = hold_message(self._mlist, self._msg)
- content, response = call_api(
+ json, response = call_api(
'http://localhost:9001/3.0/lists/ant@example.com/held')
- self.assertEqual(response.status, 200)
- self.assertEqual(content['total_size'], 1)
- self.assertEqual(content['entries'][0]['request_id'], held_id)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(json['total_size'], 1)
+ self.assertEqual(json['entries'][0]['request_id'], held_id)
def test_cant_get_other_lists_holds(self):
# Issue #161: It was possible to moderate a held message for another
@@ -187,7 +187,7 @@ class TestSubscriptionModeration(unittest.TestCase):
))
self.assertEqual(cm.exception.code, 400)
self.assertEqual(cm.exception.msg,
- b'Cannot convert parameters: action')
+ 'Cannot convert parameters: action')
def test_list_held_requests(self):
# We can view all the held requests.
@@ -199,13 +199,13 @@ class TestSubscriptionModeration(unittest.TestCase):
token_2, token_owner, member = self._registrar.register(self._bart)
self.assertIsNotNone(token_2)
self.assertIsNone(member)
- content, response = call_api(
+ json, response = call_api(
'http://localhost:9001/3.0/lists/ant@example.com/requests')
- self.assertEqual(response.status, 200)
- self.assertEqual(content['total_size'], 2)
- tokens = set(json['token'] for json in content['entries'])
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(json['total_size'], 2)
+ tokens = set(entry['token'] for entry in json['entries'])
self.assertEqual(tokens, {token_1, token_2})
- emails = set(json['email'] for json in content['entries'])
+ emails = set(entry['email'] for entry in json['entries'])
self.assertEqual(emails, {'anne@example.com', 'bart@example.com'})
def test_view_malformed_held_message(self):
@@ -219,11 +219,11 @@ class TestSubscriptionModeration(unittest.TestCase):
hold_message(self._mlist, msg)
# Now trying to access held messages from REST API should not give
# 500 server error if one of the messages can't be parsed properly.
- content, response = call_api(
+ json, response = call_api(
'http://localhost:9001/3.0/lists/ant@example.com/held')
- self.assertEqual(response.status, 200)
- self.assertEqual(len(content['entries']), 1)
- self.assertEqual(content['entries'][0]['msg'],
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(len(json['entries']), 1)
+ self.assertEqual(json['entries'][0]['msg'],
'This message is defective')
def test_individual_request(self):
@@ -234,11 +234,11 @@ class TestSubscriptionModeration(unittest.TestCase):
self.assertIsNotNone(token)
self.assertIsNone(member)
url = 'http://localhost:9001/3.0/lists/ant@example.com/requests/{}'
- content, response = call_api(url.format(token))
- self.assertEqual(response.status, 200)
- self.assertEqual(content['token'], token)
- self.assertEqual(content['token_owner'], token_owner.name)
- self.assertEqual(content['email'], 'anne@example.com')
+ json, response = call_api(url.format(token))
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(json['token'], token)
+ self.assertEqual(json['token_owner'], token_owner.name)
+ self.assertEqual(json['email'], 'anne@example.com')
def test_accept(self):
# POST to the request to accept it.
@@ -247,10 +247,10 @@ class TestSubscriptionModeration(unittest.TestCase):
# Anne's subscription request got held.
self.assertIsNone(member)
url = 'http://localhost:9001/3.0/lists/ant@example.com/requests/{}'
- content, response = call_api(url.format(token), dict(
+ json, response = call_api(url.format(token), dict(
action='accept',
))
- self.assertEqual(response.status, 204)
+ self.assertEqual(response.status_code, 204)
# Anne is a member.
self.assertEqual(
self._mlist.members.get_member('anne@example.com').address,
@@ -275,7 +275,7 @@ class TestSubscriptionModeration(unittest.TestCase):
action='accept',
))
self.assertEqual(cm.exception.code, 409)
- self.assertEqual(cm.exception.reason, b'Already subscribed')
+ self.assertEqual(cm.exception.reason, 'Already subscribed')
def test_accept_bad_token(self):
# Try to accept a request with a bogus token.
@@ -290,9 +290,9 @@ class TestSubscriptionModeration(unittest.TestCase):
# more requests to handle.
#
# We start with nothing in the queue.
- content, response = call_api(
+ json, response = call_api(
'http://localhost:9001/3.0/lists/ant@example.com/requests')
- self.assertEqual(content['total_size'], 0)
+ self.assertEqual(json['total_size'], 0)
# Anne tries to subscribe to a list that only requests moderator
# approval.
with transaction():
@@ -302,20 +302,20 @@ class TestSubscriptionModeration(unittest.TestCase):
pre_verified=True, pre_confirmed=True)
# There's now one request in the queue, and it's waiting on moderator
# approval.
- content, response = call_api(
+ json, response = call_api(
'http://localhost:9001/3.0/lists/ant@example.com/requests')
- self.assertEqual(content['total_size'], 1)
- json = content['entries'][0]
- self.assertEqual(json['token_owner'], 'moderator')
- self.assertEqual(json['email'], 'anne@example.com')
+ self.assertEqual(json['total_size'], 1)
+ entry = json['entries'][0]
+ self.assertEqual(entry['token_owner'], 'moderator')
+ self.assertEqual(entry['email'], 'anne@example.com')
# The moderator approves the request.
url = 'http://localhost:9001/3.0/lists/ant@example.com/requests/{}'
- content, response = call_api(url.format(token), {'action': 'accept'})
- self.assertEqual(response.status, 204)
+ json, response = call_api(url.format(token), {'action': 'accept'})
+ self.assertEqual(response.status_code, 204)
# And now the request queue is empty.
- content, response = call_api(
+ json, response = call_api(
'http://localhost:9001/3.0/lists/ant@example.com/requests')
- self.assertEqual(content['total_size'], 0)
+ self.assertEqual(json['total_size'], 0)
def test_discard(self):
# POST to the request to discard it.
@@ -324,10 +324,10 @@ class TestSubscriptionModeration(unittest.TestCase):
# Anne's subscription request got held.
self.assertIsNone(member)
url = 'http://localhost:9001/3.0/lists/ant@example.com/requests/{}'
- content, response = call_api(url.format(token), dict(
+ json, response = call_api(url.format(token), dict(
action='discard',
))
- self.assertEqual(response.status, 204)
+ self.assertEqual(response.status_code, 204)
# Anne is not a member.
self.assertIsNone(self._mlist.members.get_member('anne@example.com'))
# The request URL no longer exists.
@@ -344,22 +344,22 @@ class TestSubscriptionModeration(unittest.TestCase):
# Anne's subscription request got held.
self.assertIsNone(member)
url = 'http://localhost:9001/3.0/lists/ant@example.com/requests/{}'
- content, response = call_api(url.format(token), dict(
+ json, response = call_api(url.format(token), dict(
action='defer',
))
- self.assertEqual(response.status, 204)
+ self.assertEqual(response.status_code, 204)
# Anne is not a member.
self.assertIsNone(self._mlist.members.get_member('anne@example.com'))
# The request URL still exists.
- content, response = call_api(url.format(token), dict(
+ json, response = call_api(url.format(token), dict(
action='defer',
))
- self.assertEqual(response.status, 204)
+ self.assertEqual(response.status_code, 204)
# And now we can accept it.
- content, response = call_api(url.format(token), dict(
+ json, response = call_api(url.format(token), dict(
action='accept',
))
- self.assertEqual(response.status, 204)
+ self.assertEqual(response.status_code, 204)
# Anne is a member.
self.assertEqual(
self._mlist.members.get_member('anne@example.com').address,
@@ -390,10 +390,10 @@ class TestSubscriptionModeration(unittest.TestCase):
# confirmation message sent to Anne.
get_queue_messages('virgin')
url = 'http://localhost:9001/3.0/lists/ant@example.com/requests/{}'
- content, response = call_api(url.format(token), dict(
+ json, response = call_api(url.format(token), dict(
action='reject',
))
- self.assertEqual(response.status, 204)
+ self.assertEqual(response.status_code, 204)
# Anne is not a member.
self.assertIsNone(self._mlist.members.get_member('anne@example.com'))
# The request URL no longer exists.
@@ -429,17 +429,17 @@ class TestSubscriptionModeration(unittest.TestCase):
# confirmation message sent to Anne.
get_queue_messages('virgin')
url = 'http://localhost:9001/3.0/lists/ant@example.com/requests/{}'
- content, response = call_api(url.format(token), dict(
+ json, response = call_api(url.format(token), dict(
action='hold',
))
- self.assertEqual(response.status, 204)
+ self.assertEqual(response.status_code, 204)
# Anne is not a member.
self.assertIsNone(self._mlist.members.get_member('anne@example.com'))
# The request URL still exists.
- content, response = call_api(url.format(token), dict(
+ json, response = call_api(url.format(token), dict(
action='defer',
))
- self.assertEqual(response.status, 204)
+ self.assertEqual(response.status_code, 204)
def test_subscribe_other_role_with_no_preferred_address(self):
with transaction():
@@ -451,8 +451,7 @@ class TestSubscriptionModeration(unittest.TestCase):
'role': 'moderator',
})
self.assertEqual(cm.exception.code, 400)
- self.assertEqual(cm.exception.reason,
- b'User without preferred address')
+ self.assertEqual(cm.exception.reason, 'User without preferred address')
def test_subscribe_other_role_banned_email_address(self):
bans = IBanManager(self._mlist)
@@ -465,4 +464,4 @@ class TestSubscriptionModeration(unittest.TestCase):
'role': 'moderator',
})
self.assertEqual(cm.exception.code, 400)
- self.assertEqual(cm.exception.reason, b'Membership is banned')
+ self.assertEqual(cm.exception.reason, 'Membership is banned')