summaryrefslogtreecommitdiff
path: root/src/mailman/rest
diff options
context:
space:
mode:
authorAbhilash Raj2015-04-06 03:58:22 +0530
committerAbhilash Raj2015-04-06 03:58:22 +0530
commit17fa7ac10ddd6ca0916cdcdd3a5e8c1414e9bcbc (patch)
tree8d69d19d1c47ef4ba76d75140ef5706223f6cc6b /src/mailman/rest
parentfe12351e6f0e11f48bd714357f05aa7a34ec7e90 (diff)
downloadmailman-17fa7ac10ddd6ca0916cdcdd3a5e8c1414e9bcbc.tar.gz
mailman-17fa7ac10ddd6ca0916cdcdd3a5e8c1414e9bcbc.tar.zst
mailman-17fa7ac10ddd6ca0916cdcdd3a5e8c1414e9bcbc.zip
* implement left over methods
* add and remove owners using the address
Diffstat (limited to 'src/mailman/rest')
-rw-r--r--src/mailman/rest/domains.py8
-rw-r--r--src/mailman/rest/lists.py2
-rw-r--r--src/mailman/rest/tests/test_domains.py15
-rw-r--r--src/mailman/rest/users.py25
4 files changed, 29 insertions, 21 deletions
diff --git a/src/mailman/rest/domains.py b/src/mailman/rest/domains.py
index 2f41ecfd9..41a1c50bd 100644
--- a/src/mailman/rest/domains.py
+++ b/src/mailman/rest/domains.py
@@ -25,6 +25,7 @@ __all__ = [
from mailman.interfaces.domain import (
BadDomainSpecificationError, IDomainManager)
+from mailman.interfaces.usermanager import IUserManager
from mailman.rest.helpers import (
BadRequest, CollectionMixin, NotFound, bad_request, child, created, etag,
no_content, not_found, okay, path_to)
@@ -110,10 +111,11 @@ class AllDomains(_DomainBase):
validator = Validator(mail_host=str,
description=str,
base_url=str,
- owner=int,
+ owners=list,
_optional=('description', 'base_url',
- 'owner'))
- domain = domain_manager.add(**validator(request))
+ 'owners'))
+ values = validator(request)
+ domain = domain_manager.add(**values)
except BadDomainSpecificationError as error:
bad_request(response, str(error))
except ValueError as error:
diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py
index f6bc27917..641ddec8e 100644
--- a/src/mailman/rest/lists.py
+++ b/src/mailman/rest/lists.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2015 by the Free Software Foundation, Inc.
+ # Copyright (C) 2010-2015 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rest/tests/test_domains.py b/src/mailman/rest/tests/test_domains.py
index 9ebc0c0d8..13299516c 100644
--- a/src/mailman/rest/tests/test_domains.py
+++ b/src/mailman/rest/tests/test_domains.py
@@ -27,6 +27,7 @@ import unittest
from mailman.app.lifecycle import create_list
from mailman.database.transaction import transaction
from mailman.interfaces.listmanager import IListManager
+from mailman.interfaces.domain import IDomainManager
from mailman.testing.helpers import call_api
from mailman.testing.layers import RESTLayer
from urllib.error import HTTPError
@@ -41,10 +42,16 @@ class TestDomains(unittest.TestCase):
with transaction():
self._mlist = create_list('test@example.com')
- def test_create_domain(self):
- """Create domain via REST"""
- # TODO: Complete this
- # Tests should be failing with improper REST API.
+ def test_create_domains(self):
+ """Test Create domain via REST"""
+ data = {'mail_host': 'example.org',
+ 'description': 'Example domain',
+ 'base_url': 'http://example.org',
+ 'owners': ['someone@example.com',
+ 'secondowner@example.com',]}
+ content, response = call_api('http://localhost:9001/3.0/domains',
+ data, method="POST")
+ self.assertEqual(response.status, 201)
def test_bogus_endpoint_extension(self):
# /domains/<domain>/lists/<anything> is not a valid endpoint.
diff --git a/src/mailman/rest/users.py b/src/mailman/rest/users.py
index 5a3f0118d..b8eaee448 100644
--- a/src/mailman/rest/users.py
+++ b/src/mailman/rest/users.py
@@ -22,6 +22,7 @@ __all__ = [
'AddressUser',
'AllUsers',
'Login',
+ 'OwnersForDomain',
]
@@ -395,27 +396,25 @@ class OwnersForDomain(_UserBase):
def on_post(self, request, response):
"""POST to /domains/<domain>/owners """
- validator = Validator(owner_id=GetterSetter(int))
+ validator = Validator(owner=GetterSetter(str))
try:
values = validator(request)
except ValueError as error:
bad_request(response, str(error))
return
- owner = getUtility(IUserManager).get_user_by_id(values['owner_id'])
- self._domain.add_owner(owner)
+ self._domain.add_owner(values['owner'])
return no_content(response)
- def on_patch(self, request, response):
- # TODO: complete this
- pass
-
- def on_put(self, request, response):
- # TODO: complete this
- pass
-
def on_delete(self, request, response):
- # TODO: complete this
- pass
+ """DELETE to /domains/<domain>/owners"""
+ validator = Validator(owner=GetterSetter(str))
+ try:
+ values = validator(request)
+ except ValueError as error:
+ bad_request(response, str(error))
+ return
+ self._domain.remove_owner(owner)
+ return no_content(response)
@paginate
def _get_collection(self, request):