Commit c7074204 authored by Barry Warsaw's avatar Barry Warsaw

More tests.

parent ba2c7550
......@@ -21,12 +21,22 @@ from __future__ import absolute_import, unicode_literals
__metaclass__ = type
__all__ = [
'APIValueError',
'IResolvePathNames',
]
from lazr.restful.declarations import error_status
from zope.interface import Interface
from mailman.core.errors import MailmanError
@error_status(400)
class APIValueError(MailmanError, ValueError):
"""A `ValueError` from the REST API."""
class IResolvePathNames(Interface):
......
......@@ -38,7 +38,7 @@ from mailman.interfaces.domain import IDomainCollection, IDomainManager
from mailman.interfaces.listmanager import IListManager, NoSuchListError
from mailman.interfaces.member import DeliveryMode, NotAMemberError
from mailman.interfaces.membership import ISubscriptionService
from mailman.interfaces.rest import IResolvePathNames
from mailman.interfaces.rest import APIValueError, IResolvePathNames
......@@ -102,12 +102,15 @@ class SubscriptionService:
mlist = getUtility(IListManager).get(fqdn_listname)
if mlist is None:
raise NoSuchListError(fqdn_listname)
# Convert from string to enum. Allow ValueError exceptions to be
# returned by the API. XXX 2009-12-30 Does lazr.restful intelligently
# handle ValueError?
mode = (DeliveryMode.regular
if delivery_mode is None
else DeliveryMode(delivery_mode))
# Convert from string to enum. Turn Python's ValueErrors into one
# suitable for the REST API.
try:
mode = (DeliveryMode.regular
if delivery_mode is None
else DeliveryMode(delivery_mode))
except ValueError:
raise APIValueError(
'Invalid delivery_mode: {0}'.format(delivery_mode))
if real_name is None:
real_name, at, domain = address.partition('@')
if len(at) == 0:
......
......@@ -11,6 +11,7 @@
<webservice:register module="mailman.interfaces.domain" />
<webservice:register module="mailman.interfaces.listmanager" />
<webservice:register module="mailman.interfaces.membership" />
<webservice:register module="mailman.interfaces.rest" />
<webservice:register module="mailman.interfaces.system" />
<adapter factory="zope.publisher.http.HTTPCharsets" />
......@@ -52,11 +53,12 @@
/>
<!--
XXX 2009-12-28 Why is this necessary? NotAMemberError is decorated with
@error_status(400) so it /should/ already be adaptable to
WebServiceExceptionView. For some reason though rest/membership.txt fails
without this.
XXX 2009-12-28 Why are these necessary? NotAMemberError and
AlreadySubscribedError are decorated with @error_status(400) so they
/should/ already be adaptable to WebServiceExceptionView. For some reason
though rest/membership.txt fails without these.
-->
<adapter
for="mailman.interfaces.member.NotAMemberError
lazr.restful.simple.Request"
......@@ -65,6 +67,16 @@
name="index.html"
/>
<adapter
for="mailman.interfaces.member.AlreadySubscribedError
lazr.restful.simple.Request"
provides="zope.interface.Interface"
factory="lazr.restful.error.WebServiceExceptionView"
name="index.html"
/>
<!-- Utilities -->
<utility
factory="mailman.rest.configuration.AdminWebServiceConfiguration"
provides="lazr.restful.interfaces.IWebServiceConfiguration"
......
......@@ -231,6 +231,32 @@ Elly is no longer a member of the mailing list.
set([])
Digest delivery
===============
Fred joins the alpha mailing list but wants MIME digest delivery.
>>> transaction.abort()
>>> dump_json('http://localhost:8001/3.0/members', {
... 'ws.op': 'join',
... 'fqdn_listname': '[email protected]',
... 'address': '[email protected]',
... 'real_name': 'Fred Person',
... 'delivery_mode': 'mime_digests',
... })
http_etag: ...
resource_type_link: http://localhost:8001/3.0/#member
self_link: http://localhost:8001/3.0/lists/[email protected]/member/[email protected]
>>> fred = user_manager.get_user('[email protected]')
>>> memberships = list(fred.memberships.members)
>>> len(memberships)
1
>>> memberships[0]
<Member: Fred Person <[email protected]>
on [email protected] as MemberRole.member>
Corner cases
============
......@@ -258,6 +284,17 @@ Then, she tries to leave a mailing list that does not exist.
...
HTTPError: HTTP Error 400: Bad Request
She then tries to leave a mailing list with a bogus address.
>>> dump_json('http://localhost:8001/3.0/members', {
... 'ws.op': 'leave',
... 'fqdn_listname': '[email protected]',
... 'address': 'elly',
... })
Traceback (most recent call last):
...
HTTPError: HTTP Error 400: Bad Request
For some reason, Elly tries to leave the mailing list again, but she's already
been unsubscribed.
......@@ -269,3 +306,27 @@ been unsubscribed.
Traceback (most recent call last):
...
HTTPError: HTTP Error 400: Bad Request
Anna tries to join a mailing list she's already a member of.
>>> dump_json('http://localhost:8001/3.0/members', {
... 'ws.op': 'join',
... 'fqdn_listname': '[email protected]',
... 'address': '[email protected]',
... })
Traceback (most recent call last):
...
HTTPError: HTTP Error 400: Bad Request
Gwen tries to join the alpha mailing list using an invalid delivery mode.
>>> dump_json('http://localhost:8001/3.0/members', {
... 'ws.op': 'join',
... 'fqdn_listname': '[email protected]',
... 'address': '[email protected]',
... 'real_name': 'Gwen Person',
... 'delivery_mode': 'in_digests',
... })
Traceback (most recent call last):
...
HTTPError: HTTP Error 400: Bad Request
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment