Exemplo n.º 1
0
 def create(self, request):
     """Create a new member."""
     service = getUtility(ISubscriptionService)
     try:
         validator = Validator(
             list_id=unicode,
             subscriber=subscriber_validator,
             display_name=unicode,
             delivery_mode=enum_validator(DeliveryMode),
             role=enum_validator(MemberRole),
             _optional=('delivery_mode', 'display_name', 'role'))
         member = service.join(**validator(request))
     except AlreadySubscribedError:
         return http.conflict([], b'Member already subscribed')
     except NoSuchListError:
         return http.bad_request([], b'No such list')
     except InvalidEmailAddressError:
         return http.bad_request([], b'Invalid email address')
     except ValueError as error:
         return http.bad_request([], str(error))
     # The member_id are UUIDs.  We need to use the integer equivalent in
     # the URL.
     member_id = member.member_id.int
     location = path_to('members/{0}'.format(member_id))
     # Include no extra headers or body.
     return http.created(location, [], None)
Exemplo n.º 2
0
 def test_conflict(self):
     r = http.conflict([("Content-Type", "text/plain")], "409 Conflict")
     assert r.status.startswith("409")
     assert r.headers["Content-Type"] == "text/plain"
     assert "409 Conflict" in r.body
     exc = http.ConflictError([("Content-Type", "text/plain")], "409 Conflict")
     r = exc.make_response()
     assert r.status.startswith("409")
Exemplo n.º 3
0
 def test_conflict(self):
     r = http.conflict([('Content-Type', 'text/plain')], '409 Conflict')
     assert r.status.startswith('409')
     assert r.headers['Content-Type'] == 'text/plain'
     assert '409 Conflict' in r.body
     exc = http.ConflictError([('Content-Type', 'text/plain')], '409 Conflict')
     r = exc.make_response()
     assert r.status.startswith('409')
Exemplo n.º 4
0
 def test_conflict(self):
     r = http.conflict([('Content-Type', 'text/plain')], '409 Conflict')
     assert r.status.startswith('409')
     assert r.headers['Content-Type'] == 'text/plain'
     assert '409 Conflict' in r.body
     exc = http.ConflictError([('Content-Type', 'text/plain')],
                              '409 Conflict')
     r = exc.make_response()
     assert r.status.startswith('409')