# HG changeset patch # User Ralph Meijer # Date 1211049091 0 # Node ID 48245777aceafab3270e40d3c56aa1c39cd87570 # Parent 6e6c89eca9db7732eb044b9e10625e2f19e7e706 Return proper HTTP status codes on failed un-/subscription. diff -r 6e6c89eca9db -r 48245777acea NEWS --- a/NEWS Sat May 17 18:30:39 2008 +0000 +++ b/NEWS Sat May 17 18:31:31 2008 +0000 @@ -1,3 +1,9 @@ +x.x.x (yyyy-mm-dd) +================== + + - Return appropriate HTTP status codes on failed un-/subscription. + + 0.7.2 (2008-05-16) ================== diff -r 6e6c89eca9db -r 48245777acea idavoll/gateway.py --- a/idavoll/gateway.py Sat May 17 18:30:39 2008 +0000 +++ b/idavoll/gateway.py Sat May 17 18:31:31 2008 +0000 @@ -491,6 +491,12 @@ request to this resource. """ serviceMethod = None + errorMap = { + error.NodeNotFound: + (responsecode.FORBIDDEN, "Node not found"), + error.NotSubscribed: + (responsecode.FORBIDDEN, "No such subscription found"), + } def __init__(self, service): self.service = service @@ -502,9 +508,9 @@ def http_POST(self, request): def trapNotFound(failure): - failure.trap(error.NodeNotFound) - return http.StatusResponse(responsecode.NOT_FOUND, - "Node not found") + err = failure.trap(*self.errorMap.keys()) + code, msg = self.errorMap[err] + return http.StatusResponse(code, msg) def respond(result): return http.Response(responsecode.NO_CONTENT) @@ -734,6 +740,18 @@ return f.deferred + def unsubscribe(self, xmppURI): + params = {'uri': xmppURI, + 'callback': 'http://%s:%s/callback' % (self.callbackHost, + self.callbackPort)} + f = getPageWithFactory(self._makeURI('unsubscribe'), + method='POST', + postdata=simplejson.dumps(params), + headers={'Content-Type': MIME_JSON}, + agent=self.agent) + return f.deferred + + def items(self, xmppURI, maxItems=None): query = {'uri': xmppURI} if maxItems: diff -r 6e6c89eca9db -r 48245777acea idavoll/test/test_gateway.py --- a/idavoll/test/test_gateway.py Sat May 17 18:30:39 2008 +0000 +++ b/idavoll/test/test_gateway.py Sat May 17 18:31:31 2008 +0000 @@ -24,9 +24,8 @@ entry.addElement("author").addElement("name", content="John Doe") entry.addElement("content", content="Some text.") -#baseURI = "http://pubsub-test.ik.nu/" baseURI = "http://localhost:8086/" -componentJID = "test.ik.nu" +componentJID = "pubsub.localhost" class GatewayTest(unittest.TestCase): timeout = 2 @@ -191,7 +190,7 @@ def test_subscribeNonExisting(self): def cb(err): - self.assertEqual('404', err.status) + self.assertEqual('403', err.status) d = self.client.subscribe('xmpp:%s?node=test' % componentJID) self.assertFailure(d, error.Error) @@ -199,6 +198,16 @@ return d + def test_unsubscribeNonExisting(self): + def cb(err): + self.assertEqual('403', err.status) + + d = self.client.unsubscribe('xmpp:%s?node=test' % componentJID) + self.assertFailure(d, error.Error) + d.addCallback(cb) + return d + + def test_items(self): def cb(response): xmppURI = response['uri']