diff options
| author | Barry Warsaw | 2014-12-15 18:44:17 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2014-12-15 18:44:17 -0500 |
| commit | acf95993ceb605c71ad07a32a572ae1f0888a7de (patch) | |
| tree | cf0dfe685c8f6fcd5949b4ff3709f4481ddbe163 /src | |
| parent | d91715ea8b2692475b0751742e131bc1673b138b (diff) | |
| download | mailman-acf95993ceb605c71ad07a32a572ae1f0888a7de.tar.gz mailman-acf95993ceb605c71ad07a32a572ae1f0888a7de.tar.zst mailman-acf95993ceb605c71ad07a32a572ae1f0888a7de.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/rest/lists.py | 7 | ||||
| -rw-r--r-- | src/mailman/rest/root.py | 8 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_lists.py | 10 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_root.py | 9 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_users.py | 2 | ||||
| -rw-r--r-- | src/mailman/rest/users.py | 4 |
6 files changed, 20 insertions, 20 deletions
diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py index feaa96323..87aa9f4b5 100644 --- a/src/mailman/rest/lists.py +++ b/src/mailman/rest/lists.py @@ -213,9 +213,8 @@ class AllLists(_ListBase): except ListAlreadyExistsError: bad_request(response, b'Mailing list exists') except BadDomainSpecificationError as error: - bad_request( - response, - b'Domain does not exist: {0}'.format(error.domain)) + reason = 'Domain does not exist: {}'.format(error.domain) + bad_request(response, reason.encode('utf-8')) except ValueError as error: bad_request(response, str(error)) else: @@ -275,7 +274,7 @@ class ArchiverGetterSetter(GetterSetter): # attribute will contain the (bytes) name of the archiver that is # getting a new status. value will be the representation of the new # boolean status. - archiver = self._archiver_set.get(attribute.decode('utf-8')) + archiver = self._archiver_set.get(attribute) if archiver is None: raise ValueError('No such archiver: {}'.format(attribute)) archiver.is_enabled = as_boolean(value) diff --git a/src/mailman/rest/root.py b/src/mailman/rest/root.py index a8e975fed..a82f7cdef 100644 --- a/src/mailman/rest/root.py +++ b/src/mailman/rest/root.py @@ -66,8 +66,8 @@ class Root: # the case where no error is raised. if request.auth is None: raise falcon.HTTPUnauthorized( - b'401 Unauthorized', - b'The REST API requires authentication') + '401 Unauthorized', + 'The REST API requires authentication') if request.auth.startswith('Basic '): # b64decode() returns bytes, but we require a str. credentials = b64decode(request.auth[6:]).decode('utf-8') @@ -76,8 +76,8 @@ class Root: password != config.webservice.admin_pass): # Not authorized. raise falcon.HTTPUnauthorized( - b'401 Unauthorized', - b'User is not authorized for the REST API') + '401 Unauthorized', + 'User is not authorized for the REST API') return TopLevel() diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py index e8cc54d4b..23d082fb8 100644 --- a/src/mailman/rest/tests/test_lists.py +++ b/src/mailman/rest/tests/test_lists.py @@ -128,7 +128,7 @@ class TestLists(unittest.TestCase): }) self.assertEqual(cm.exception.code, 400) self.assertEqual(cm.exception.reason, - 'Domain does not exist: no-domain.example.org') + b'Domain does not exist: no-domain.example.org') def test_cannot_create_duplicate_list(self): # You cannot create a list that already exists. @@ -140,7 +140,7 @@ class TestLists(unittest.TestCase): 'fqdn_listname': 'ant@example.com', }) self.assertEqual(cm.exception.code, 400) - self.assertEqual(cm.exception.reason, 'Mailing list exists') + self.assertEqual(cm.exception.reason, b'Mailing list exists') def test_cannot_delete_missing_list(self): # You cannot delete a list that does not exist. @@ -219,7 +219,7 @@ class TestListArchivers(unittest.TestCase): method='PATCH') self.assertEqual(cm.exception.code, 400) self.assertEqual(cm.exception.reason, - 'Unexpected parameters: bogus-archiver') + b'Unexpected parameters: bogus-archiver') def test_put_incomplete_statuses(self): # PUT requires the full resource representation. This one forgets to @@ -232,7 +232,7 @@ class TestListArchivers(unittest.TestCase): method='PUT') self.assertEqual(cm.exception.code, 400) self.assertEqual(cm.exception.reason, - 'Missing parameters: mhonarc, prototype') + b'Missing parameters: mhonarc, prototype') def test_patch_bogus_status(self): # Archiver statuses must be interpretable as booleans. @@ -245,7 +245,7 @@ class TestListArchivers(unittest.TestCase): }, method='PATCH') self.assertEqual(cm.exception.code, 400) - self.assertEqual(cm.exception.reason, 'Invalid boolean value: sure') + self.assertEqual(cm.exception.reason, b'Invalid boolean value: sure') diff --git a/src/mailman/rest/tests/test_root.py b/src/mailman/rest/tests/test_root.py index c5787bcb1..49877c3ae 100644 --- a/src/mailman/rest/tests/test_root.py +++ b/src/mailman/rest/tests/test_root.py @@ -102,22 +102,23 @@ class TestRoot(unittest.TestCase): } response, raw_content = Http().request(url, 'GET', None, headers) self.assertEqual(response.status, 401) - content = json.loads(raw_content) + content = json.loads(raw_content.decode('utf-8')) self.assertEqual(content['title'], '401 Unauthorized') self.assertEqual(content['description'], 'The REST API requires authentication') def test_unauthorized(self): # Bad Basic Auth credentials results in a 401 error. - auth = b64encode('baduser:badpass') + userpass = b64encode(b'baduser:badpass') + auth = 'Basic {}'.format(userpass.decode('ascii')) url = 'http://localhost:9001/3.0/system' headers = { 'Content-Type': 'application/x-www-form-urlencode', - 'Authorization': 'Basic ' + auth, + 'Authorization': auth, } response, raw_content = Http().request(url, 'GET', None, headers) self.assertEqual(response.status, 401) - content = json.loads(raw_content) + content = json.loads(raw_content.decode('utf-8')) self.assertEqual(content['title'], '401 Unauthorized') self.assertEqual(content['description'], 'User is not authorized for the REST API') diff --git a/src/mailman/rest/tests/test_users.py b/src/mailman/rest/tests/test_users.py index 1936fdc68..a130b1cc9 100644 --- a/src/mailman/rest/tests/test_users.py +++ b/src/mailman/rest/tests/test_users.py @@ -119,7 +119,7 @@ class TestUsers(unittest.TestCase): }) self.assertEqual(cm.exception.code, 400) self.assertEqual(cm.exception.reason, - 'Address already exists: anne@example.com') + b'Address already exists: anne@example.com') def test_addresses_of_missing_user_id(self): # Trying to get the /addresses of a missing user id results in error. diff --git a/src/mailman/rest/users.py b/src/mailman/rest/users.py index 7e6e70c5a..c8e3475e7 100644 --- a/src/mailman/rest/users.py +++ b/src/mailman/rest/users.py @@ -122,8 +122,8 @@ class AllUsers(_UserBase): try: user = getUtility(IUserManager).create_user(**arguments) except ExistingAddressError as error: - bad_request( - response, b'Address already exists: {0}'.format(error.address)) + reason = 'Address already exists: {}'.format(error.address) + bad_request(response, reason.encode('utf-8')) return if password is None: # This will have to be reset since it cannot be retrieved. |
