annotate sat_pubsub/test/test_gateway.py @ 273:6ba0d6def7f5

Use twisted.web instead of web2, initial tests.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 20 Jan 2013 13:38:41 +0100
parents d55620ceafed
children 6641ea7990ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
1 #!/usr/bin/python
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
2 #-*- coding: utf-8 -*-
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
3
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
4 """
235
64f780413b82 fixed Ralph Meijer copyright years (last commit was in 2011, not in 2009)
Goffi <goffi@goffi.org>
parents: 234
diff changeset
5 Copyright (c) 2003-2011 Ralph Meijer
255
d55620ceafed copyright update
Goffi <goffi@goffi.org>
parents: 235
diff changeset
6 Copyright (c) 2012, 2013 Jérôme Poisson
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
7
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
8
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
9 This program is free software: you can redistribute it and/or modify
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
10 it under the terms of the GNU Affero General Public License as published by
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
11 the Free Software Foundation, either version 3 of the License, or
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
12 (at your option) any later version.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
13
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
14 This program is distributed in the hope that it will be useful,
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
17 GNU Affero General Public License for more details.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
18
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
19 You should have received a copy of the GNU Affero General Public License
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
21 --
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
22
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
23 This program is based on Idavoll (http://idavoll.ik.nu/),
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
24 originaly written by Ralph Meijer (http://ralphm.net/blog/)
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
25 It is sublicensed under AGPL v3 (or any later version) as allowed by the original
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
26 license.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
27
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
28 --
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
29
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
30 Here is a copy of the original license:
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
31
235
64f780413b82 fixed Ralph Meijer copyright years (last commit was in 2011, not in 2009)
Goffi <goffi@goffi.org>
parents: 234
diff changeset
32 Copyright (c) 2003-2011 Ralph Meijer
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
33
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
34 Permission is hereby granted, free of charge, to any person obtaining
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
35 a copy of this software and associated documentation files (the
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
36 "Software"), to deal in the Software without restriction, including
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
37 without limitation the rights to use, copy, modify, merge, publish,
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
38 distribute, sublicense, and/or sell copies of the Software, and to
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
39 permit persons to whom the Software is furnished to do so, subject to
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
40 the following conditions:
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
41
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
42 The above copyright notice and this permission notice shall be
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
43 included in all copies or substantial portions of the Software.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
44
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
45 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
46 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
47 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
48 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
49 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
50 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
51 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
52
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
53 """
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
54
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
55 """
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
56 Tests for L{idavoll.gateway}.
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
57
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
58 Note that some tests are functional tests that require a running idavoll
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
59 service.
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
60 """
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
61
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
62 from StringIO import StringIO
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
63
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
64 import simplejson
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
65
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
66 from twisted.internet import defer
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
67 from twisted.trial import unittest
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
68 from twisted.web import error, http, http_headers, server
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
69 from twisted.web.test import requesthelper
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
70 from twisted.words.xish import domish
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
71 from twisted.words.protocols.jabber.jid import JID
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
72
234
51af2ed8bd50 replaced idavoll imports by sat_pubsub imports
Goffi <goffi@goffi.org>
parents: 233
diff changeset
73 from sat_pubsub import gateway
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
74 from sat_pubsub.backend import BackendService
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
75 from sat_pubsub.memory_storage import Storage
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
76
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
77 AGENT = "Idavoll Test Script"
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
78 NS_ATOM = "http://www.w3.org/2005/Atom"
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
79
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
80 TEST_ENTRY = domish.Element((NS_ATOM, 'entry'))
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
81 TEST_ENTRY.addElement("id",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
82 content="urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a")
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
83 TEST_ENTRY.addElement("title", content="Atom-Powered Robots Run Amok")
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
84 TEST_ENTRY.addElement("author").addElement("name", content="John Doe")
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
85 TEST_ENTRY.addElement("content", content="Some text.")
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
86
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
87 baseURI = "http://localhost:8086/"
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
88 component = "pubsub"
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
89 componentJID = JID(component)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
90 ownerJID = JID('owner@example.org')
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
91
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
92 def _render(resource, request):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
93 result = resource.render(request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
94 if isinstance(result, str):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
95 request.write(result)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
96 request.finish()
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
97 return defer.succeed(None)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
98 elif result is server.NOT_DONE_YET:
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
99 if request.finished:
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
100 return defer.succeed(None)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
101 else:
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
102 return request.notifyFinish()
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
103 else:
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
104 raise ValueError("Unexpected return value: %r" % (result,))
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
105
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
106
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
107 class DummyRequest(requesthelper.DummyRequest):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
108
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
109 def __init__(self, *args, **kwargs):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
110 requesthelper.DummyRequest.__init__(self, *args, **kwargs)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
111 self.requestHeaders = http_headers.Headers()
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
112
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
113
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
114
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
115 class GetServiceAndNodeTest(unittest.TestCase):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
116 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
117 Tests for {gateway.getServiceAndNode}.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
118 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
119
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
120 def test_basic(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
121 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
122 getServiceAndNode parses an XMPP URI with node parameter.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
123 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
124 uri = b'xmpp:pubsub.example.org?;node=test'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
125 service, nodeIdentifier = gateway.getServiceAndNode(uri)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
126 self.assertEqual(JID(u'pubsub.example.org'), service)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
127 self.assertEqual(u'test', nodeIdentifier)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
128
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
129
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
130 def test_schemeEmpty(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
131 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
132 If the URI scheme is empty, an exception is raised.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
133 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
134 uri = b'pubsub.example.org'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
135 self.assertRaises(gateway.XMPPURIParseError,
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
136 gateway.getServiceAndNode, uri)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
137
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
138
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
139 def test_schemeNotXMPP(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
140 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
141 If the URI scheme is not 'xmpp', an exception is raised.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
142 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
143 uri = b'mailto:test@example.org'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
144 self.assertRaises(gateway.XMPPURIParseError,
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
145 gateway.getServiceAndNode, uri)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
146
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
147
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
148 def test_authorityPresent(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
149 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
150 If the URI has an authority component, an exception is raised.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
151 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
152 uri = b'xmpp://pubsub.example.org/'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
153 self.assertRaises(gateway.XMPPURIParseError,
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
154 gateway.getServiceAndNode, uri)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
155
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
156
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
157 def test_queryEmpty(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
158 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
159 If there is no query component, the nodeIdentifier is empty.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
160 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
161 uri = b'xmpp:pubsub.example.org'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
162 service, nodeIdentifier = gateway.getServiceAndNode(uri)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
163
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
164 self.assertEqual(JID(u'pubsub.example.org'), service)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
165 self.assertEqual(u'', nodeIdentifier)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
166
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
167
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
168 def test_jidInvalid(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
169 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
170 If the JID from the path component is invalid, an exception is raised.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
171 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
172 uri = b'xmpp:@@pubsub.example.org?;node=test'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
173 self.assertRaises(gateway.XMPPURIParseError,
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
174 gateway.getServiceAndNode, uri)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
175
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
176
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
177 def test_pathEmpty(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
178 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
179 If there is no path component, an exception is raised.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
180 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
181 uri = b'xmpp:?node=test'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
182 self.assertRaises(gateway.XMPPURIParseError,
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
183 gateway.getServiceAndNode, uri)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
184
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
185
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
186 def test_nodeAbsent(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
187 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
188 If the node parameter is missing, the nodeIdentifier is empty.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
189 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
190 uri = b'xmpp:pubsub.example.org?'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
191 service, nodeIdentifier = gateway.getServiceAndNode(uri)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
192
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
193 self.assertEqual(JID(u'pubsub.example.org'), service)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
194 self.assertEqual(u'', nodeIdentifier)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
195
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
196
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
197
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
198 class GetXMPPURITest(unittest.TestCase):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
199 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
200 Tests for L{gateway.getXMPPURITest}.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
201 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
202
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
203 def test_basic(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
204 uri = gateway.getXMPPURI(JID(u'pubsub.example.org'), u'test')
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
205 self.assertEqual('xmpp:pubsub.example.org?;node=test', uri)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
206
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
207
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
208 class CreateResourceTest(unittest.TestCase):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
209 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
210 Tests for L{gateway.CreateResource}.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
211 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
212
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
213 def setUp(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
214 self.backend = BackendService(Storage())
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
215 self.resource = gateway.CreateResource(self.backend, componentJID,
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
216 ownerJID)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
217
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
218
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
219 def test_get(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
220 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
221 The method GET is not supported.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
222 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
223 request = DummyRequest([b''])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
224 self.assertRaises(error.UnsupportedMethod,
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
225 _render, self.resource, request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
226
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
227
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
228 def test_post(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
229 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
230 Upon a POST, a new node is created and the URI returned.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
231 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
232 request = DummyRequest([b''])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
233 request.method = 'POST'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
234
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
235 def gotNodes(nodeIdentifiers, uri):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
236 service, nodeIdentifier = gateway.getServiceAndNode(uri)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
237 self.assertIn(nodeIdentifier, nodeIdentifiers)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
238
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
239 def rendered(result):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
240 self.assertEqual('application/json',
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
241 request.outgoingHeaders['content-type'])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
242 payload = simplejson.loads(b''.join(request.written))
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
243 self.assertIn('uri', payload)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
244 d = self.backend.getNodes()
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
245 d.addCallback(gotNodes, payload['uri'])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
246 return d
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
247
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
248 d = _render(self.resource, request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
249 d.addCallback(rendered)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
250 return d
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
251
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
252
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
253
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
254 class DeleteResourceTest(unittest.TestCase):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
255 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
256 Tests for L{gateway.DeleteResource}.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
257 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
258
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
259 def setUp(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
260 self.backend = BackendService(Storage())
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
261 self.resource = gateway.DeleteResource(self.backend, componentJID,
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
262 ownerJID)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
263
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
264
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
265 def test_get(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
266 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
267 The method GET is not supported.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
268 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
269 request = DummyRequest([b''])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
270 self.assertRaises(error.UnsupportedMethod,
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
271 _render, self.resource, request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
272
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
274 def test_post(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
275 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
276 Upon a POST, a new node is created and the URI returned.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
277 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
278 request = DummyRequest([b''])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
279 request.method = b'POST'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
280
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
281 def rendered(result):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
282 self.assertEqual(http.NO_CONTENT, request.responseCode)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
283
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
284 def nodeCreated(nodeIdentifier):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
285 uri = gateway.getXMPPURI(componentJID, nodeIdentifier)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
286 request.args[b'uri'] = [uri]
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
287 request.content = StringIO(b'')
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
288
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
289 return _render(self.resource, request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
290
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
291 d = self.backend.createNode(u'test', ownerJID)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
292 d.addCallback(nodeCreated)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
293 d.addCallback(rendered)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
294 return d
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
295
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
296
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
297 def test_postWithRedirect(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
298 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
299 Upon a POST, a new node is created and the URI returned.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
300 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
301 request = DummyRequest([b''])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
302 request.method = b'POST'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
303 otherNodeURI = b'xmpp:pubsub.example.org?node=other'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
304
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
305 def rendered(result):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
306 self.assertEqual(http.NO_CONTENT, request.responseCode)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
307 self.assertEqual(1, len(deletes))
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
308 nodeIdentifier, owner, redirectURI = deletes[-1]
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
309 self.assertEqual(otherNodeURI, redirectURI)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
310
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
311 def nodeCreated(nodeIdentifier):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
312 uri = gateway.getXMPPURI(componentJID, nodeIdentifier)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
313 request.args[b'uri'] = [uri]
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
314 payload = {b'redirect_uri': otherNodeURI}
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
315 body = simplejson.dumps(payload)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
316 request.content = StringIO(body)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
317 return _render(self.resource, request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
318
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
319 def deleteNode(nodeIdentifier, owner, redirectURI):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
320 deletes.append((nodeIdentifier, owner, redirectURI))
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
321 return defer.succeed(nodeIdentifier)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
322
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
323 deletes = []
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
324 self.patch(self.backend, 'deleteNode', deleteNode)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
325 d = self.backend.createNode(u'test', ownerJID)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
326 d.addCallback(nodeCreated)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
327 d.addCallback(rendered)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
328 return d
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
329
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
330
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
331 def test_postUnknownNode(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
332 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
333 If the node to be deleted is unknown, 404 Not Found is returned.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
334 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
335 request = DummyRequest([b''])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
336 request.method = b'POST'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
337
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
338 def rendered(result):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
339 self.assertEqual(http.NOT_FOUND, request.responseCode)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
340
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
341 uri = gateway.getXMPPURI(componentJID, u'unknown')
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
342 request.args[b'uri'] = [uri]
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
343 request.content = StringIO(b'')
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
344
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
345 d = _render(self.resource, request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
346 d.addCallback(rendered)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
347 return d
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
348
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
349
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
350 def test_postURIMissing(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
351 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
352 If no URI is passed, 400 Bad Request is returned.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
353 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
354 request = DummyRequest([b''])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
355 request.method = b'POST'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
356
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
357 def rendered(result):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
358 self.assertEqual(http.BAD_REQUEST, request.responseCode)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
359
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
360 request.content = StringIO(b'')
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
361
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
362 d = _render(self.resource, request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
363 d.addCallback(rendered)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
364 return d
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
365
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
366
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
367 class CallbackResourceTest(unittest.TestCase):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
368 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
369 Tests for L{gateway.CallbackResource}.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
370 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
371
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
372 def setUp(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
373 self.callbackEvents = []
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
374 self.resource = gateway.CallbackResource(self._callback)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
375
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
376
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
377 def _callback(self, payload, headers):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
378 self.callbackEvents.append((payload, headers))
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
379
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
380
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
381 def test_get(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
382 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
383 The method GET is not supported.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
384 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
385 request = DummyRequest([b''])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
386 self.assertRaises(error.UnsupportedMethod,
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
387 _render, self.resource, request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
388
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
389
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
390 def test_post(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
391 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
392 The body posted is passed to the callback.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
393 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
394 request = DummyRequest([b''])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
395 request.method = 'POST'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
396 request.content = StringIO(b'<root><child/></root>')
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
397
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
398 def rendered(result):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
399 self.assertEqual(1, len(self.callbackEvents))
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
400 payload, headers = self.callbackEvents[-1]
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
401 self.assertEqual('root', payload.name)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
402
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
403 self.assertEqual(http.NO_CONTENT, request.responseCode)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
404 self.assertFalse(b''.join(request.written))
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
405
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
406 d = _render(self.resource, request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
407 d.addCallback(rendered)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
408 return d
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
409
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
410
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
411 def test_postEvent(self):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
412 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
413 If the Event header is set, the payload is empty and the header passed.
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
414 """
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
415 request = DummyRequest([b''])
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
416 request.method = 'POST'
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
417 request.requestHeaders.addRawHeader(b'Event', b'DELETE')
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
418 request.content = StringIO(b'')
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
419
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
420 def rendered(result):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
421 self.assertEqual(1, len(self.callbackEvents))
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
422 payload, headers = self.callbackEvents[-1]
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
423 self.assertIdentical(None, payload)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
424 self.assertEqual(['DELETE'], headers.getRawHeaders(b'Event'))
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
425 self.assertFalse(b''.join(request.written))
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
426
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
427 d = _render(self.resource, request)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
428 d.addCallback(rendered)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
429 return d
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
430
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
431
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
432
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
433 class GatewayTest(unittest.TestCase):
187
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
434 timeout = 2
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
435
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
436 def setUp(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
437 self.client = gateway.GatewayClient(baseURI)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
438 self.client.startService()
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
439 self.addCleanup(self.client.stopService)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
440
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
441 def trapConnectionRefused(failure):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
442 from twisted.internet.error import ConnectionRefusedError
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
443 failure.trap(ConnectionRefusedError)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
444 raise unittest.SkipTest("Gateway to test against is not available")
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
445
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
446 def trapNotFound(failure):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
447 from twisted.web.error import Error
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
448 failure.trap(Error)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
449
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
450 d = self.client.ping()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
451 d.addErrback(trapConnectionRefused)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
452 d.addErrback(trapNotFound)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
453 return d
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
454
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
455
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
456 def tearDown(self):
204
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
457 return self.client.stopService()
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
458
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
459
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
460 def test_create(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
461
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
462 def cb(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
463 self.assertIn('uri', response)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
464
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
465 d = self.client.create()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
466 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
467 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
468
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
469 def test_publish(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
470
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
471 def cb(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
472 self.assertIn('uri', response)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
473
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
474 d = self.client.publish(TEST_ENTRY)
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
475 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
476 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
477
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
478 def test_publishExistingNode(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
479
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
480 def cb2(response, xmppURI):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
481 self.assertEquals(xmppURI, response['uri'])
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
482
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
483 def cb1(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
484 xmppURI = response['uri']
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
485 d = self.client.publish(TEST_ENTRY, xmppURI)
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
486 d.addCallback(cb2, xmppURI)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
487 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
488
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
489 d = self.client.create()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
490 d.addCallback(cb1)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
491 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
492
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
493 def test_publishNonExisting(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
494 def cb(err):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
495 self.assertEqual('404', err.status)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
496
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
497 d = self.client.publish(TEST_ENTRY, 'xmpp:%s?node=test' % component)
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
498 self.assertFailure(d, error.Error)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
499 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
500 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
501
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
502 def test_delete(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
503 def cb(response):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
504 xmppURI = response['uri']
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
505 d = self.client.delete(xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
506 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
507
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
508 d = self.client.create()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
509 d.addCallback(cb)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
510 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
511
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
512 def test_deleteWithRedirect(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
513 def cb(response):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
514 xmppURI = response['uri']
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
515 redirectURI = 'xmpp:%s?node=test' % component
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
516 d = self.client.delete(xmppURI, redirectURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
517 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
518
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
519 d = self.client.create()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
520 d.addCallback(cb)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
521 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
522
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
523 def test_deleteNotification(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
524 def onNotification(data, headers):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
525 try:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
526 self.assertTrue(headers.hasHeader('Event'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
527 self.assertEquals(['DELETED'], headers.getRawHeaders('Event'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
528 self.assertFalse(headers.hasHeader('Link'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
529 except:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
530 self.client.deferred.errback()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
531 else:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
532 self.client.deferred.callback(None)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
533
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
534 def cb(response):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
535 xmppURI = response['uri']
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
536 d = self.client.subscribe(xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
537 d.addCallback(lambda _: xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
538 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
539
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
540 def cb2(xmppURI):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
541 d = self.client.delete(xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
542 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
543
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
544 self.client.callback = onNotification
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
545 self.client.deferred = defer.Deferred()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
546 d = self.client.create()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
547 d.addCallback(cb)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
548 d.addCallback(cb2)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
549 return defer.gatherResults([d, self.client.deferred])
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
550
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
551 def test_deleteNotificationWithRedirect(self):
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
552 redirectURI = 'xmpp:%s?node=test' % component
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
553
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
554 def onNotification(data, headers):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
555 try:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
556 self.assertTrue(headers.hasHeader('Event'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
557 self.assertEquals(['DELETED'], headers.getRawHeaders('Event'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
558 self.assertEquals(['<%s>; rel=alternate' % redirectURI],
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
559 headers.getRawHeaders('Link'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
560 except:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
561 self.client.deferred.errback()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
562 else:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
563 self.client.deferred.callback(None)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
564
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
565 def cb(response):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
566 xmppURI = response['uri']
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
567 d = self.client.subscribe(xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
568 d.addCallback(lambda _: xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
569 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
570
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
571 def cb2(xmppURI):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
572 d = self.client.delete(xmppURI, redirectURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
573 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
574
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
575 self.client.callback = onNotification
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
576 self.client.deferred = defer.Deferred()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
577 d = self.client.create()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
578 d.addCallback(cb)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
579 d.addCallback(cb2)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
580 return defer.gatherResults([d, self.client.deferred])
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
581
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
582 def test_list(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
583 d = self.client.listNodes()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
584 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
585
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
586 def test_subscribe(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
587 def cb(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
588 xmppURI = response['uri']
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
589 d = self.client.subscribe(xmppURI)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
590 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
591
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
592 d = self.client.create()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
593 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
594 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
595
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
596 def test_subscribeGetNotification(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
597
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
598 def onNotification(data, headers):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
599 self.client.deferred.callback(None)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
600
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
601 def cb(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
602 xmppURI = response['uri']
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
603 d = self.client.subscribe(xmppURI)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
604 d.addCallback(lambda _: xmppURI)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
605 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
606
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
607 def cb2(xmppURI):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
608 d = self.client.publish(TEST_ENTRY, xmppURI)
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
609 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
610
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
611
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
612 self.client.callback = onNotification
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
613 self.client.deferred = defer.Deferred()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
614 d = self.client.create()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
615 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
616 d.addCallback(cb2)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
617 return defer.gatherResults([d, self.client.deferred])
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
618
204
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
619
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
620 def test_subscribeTwiceGetNotification(self):
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
621
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
622 def onNotification1(data, headers):
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
623 d = client1.stopService()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
624 d.chainDeferred(client1.deferred)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
625
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
626 def onNotification2(data, headers):
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
627 d = client2.stopService()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
628 d.chainDeferred(client2.deferred)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
629
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
630 def cb(response):
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
631 xmppURI = response['uri']
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
632 d = client1.subscribe(xmppURI)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
633 d.addCallback(lambda _: xmppURI)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
634 return d
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
635
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
636 def cb2(xmppURI):
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
637 d = client2.subscribe(xmppURI)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
638 d.addCallback(lambda _: xmppURI)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
639 return d
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
640
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
641 def cb3(xmppURI):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
642 d = self.client.publish(TEST_ENTRY, xmppURI)
204
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
643 return d
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
644
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
645
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
646 client1 = gateway.GatewayClient(baseURI, callbackPort=8088)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
647 client1.startService()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
648 client1.callback = onNotification1
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
649 client1.deferred = defer.Deferred()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
650 client2 = gateway.GatewayClient(baseURI, callbackPort=8089)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
651 client2.startService()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
652 client2.callback = onNotification2
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
653 client2.deferred = defer.Deferred()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
654
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
655 d = self.client.create()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
656 d.addCallback(cb)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
657 d.addCallback(cb2)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
658 d.addCallback(cb3)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
659 dl = defer.gatherResults([d, client1.deferred, client2.deferred])
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
660 return dl
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
661
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
662
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
663 def test_subscribeGetDelayedNotification(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
664
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
665 def onNotification(data, headers):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
666 self.client.deferred.callback(None)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
667
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
668 def cb(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
669 xmppURI = response['uri']
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
670 self.assertNot(self.client.deferred.called)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
671 d = self.client.publish(TEST_ENTRY, xmppURI)
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
672 d.addCallback(lambda _: xmppURI)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
673 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
674
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
675 def cb2(xmppURI):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
676 d = self.client.subscribe(xmppURI)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
677 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
678
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
679
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
680 self.client.callback = onNotification
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
681 self.client.deferred = defer.Deferred()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
682 d = self.client.create()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
683 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
684 d.addCallback(cb2)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
685 return defer.gatherResults([d, self.client.deferred])
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
686
187
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
687 def test_subscribeGetDelayedNotification2(self):
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
688 """
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
689 Test that subscribing as second results in a notification being sent.
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
690 """
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
691
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
692 def onNotification1(data, headers):
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
693 client1.deferred.callback(None)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
694 client1.stopService()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
695
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
696 def onNotification2(data, headers):
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
697 client2.deferred.callback(None)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
698 client2.stopService()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
699
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
700 def cb(response):
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
701 xmppURI = response['uri']
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
702 self.assertNot(client1.deferred.called)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
703 self.assertNot(client2.deferred.called)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
704 d = self.client.publish(TEST_ENTRY, xmppURI)
187
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
705 d.addCallback(lambda _: xmppURI)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
706 return d
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
707
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
708 def cb2(xmppURI):
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
709 d = client1.subscribe(xmppURI)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
710 d.addCallback(lambda _: xmppURI)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
711 return d
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
712
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
713 def cb3(xmppURI):
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
714 d = client2.subscribe(xmppURI)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
715 return d
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
716
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
717 client1 = gateway.GatewayClient(baseURI, callbackPort=8088)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
718 client1.startService()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
719 client1.callback = onNotification1
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
720 client1.deferred = defer.Deferred()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
721 client2 = gateway.GatewayClient(baseURI, callbackPort=8089)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
722 client2.startService()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
723 client2.callback = onNotification2
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
724 client2.deferred = defer.Deferred()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
725
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
726
187
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
727 d = self.client.create()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
728 d.addCallback(cb)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
729 d.addCallback(cb2)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
730 d.addCallback(cb3)
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
731 dl = defer.gatherResults([d, client1.deferred, client2.deferred])
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
732 return dl
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
733
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
734
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
735 def test_subscribeNonExisting(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
736 def cb(err):
191
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
737 self.assertEqual('403', err.status)
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
738
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
739 d = self.client.subscribe('xmpp:%s?node=test' % component)
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
740 self.assertFailure(d, error.Error)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
741 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
742 return d
185
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
743
186
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
744
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
745 def test_subscribeRootGetNotification(self):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
746
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
747 def clean(rootNode):
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
748 return self.client.unsubscribe(rootNode)
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
749
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
750 def onNotification(data, headers):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
751 self.client.deferred.callback(None)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
752
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
753 def cb(response):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
754 xmppURI = response['uri']
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
755 jid, nodeIdentifier = gateway.getServiceAndNode(xmppURI)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
756 rootNode = gateway.getXMPPURI(jid, '')
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
757
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
758 d = self.client.subscribe(rootNode)
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
759 d.addCallback(lambda _: self.addCleanup(clean, rootNode))
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
760 d.addCallback(lambda _: xmppURI)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
761 return d
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
762
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
763 def cb2(xmppURI):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
764 return self.client.publish(TEST_ENTRY, xmppURI)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
765
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
766
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
767 self.client.callback = onNotification
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
768 self.client.deferred = defer.Deferred()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
769 d = self.client.create()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
770 d.addCallback(cb)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
771 d.addCallback(cb2)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
772 return defer.gatherResults([d, self.client.deferred])
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
773
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
774
191
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
775 def test_unsubscribeNonExisting(self):
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
776 def cb(err):
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
777 self.assertEqual('403', err.status)
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
778
273
6ba0d6def7f5 Use twisted.web instead of web2, initial tests.
Ralph Meijer <ralphm@ik.nu>
parents: 255
diff changeset
779 d = self.client.unsubscribe('xmpp:%s?node=test' % component)
191
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
780 self.assertFailure(d, error.Error)
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
781 d.addCallback(cb)
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
782 return d
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
783
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
784
185
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
785 def test_items(self):
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
786 def cb(response):
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
787 xmppURI = response['uri']
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
788 d = self.client.items(xmppURI)
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
789 return d
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
790
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
791 d = self.client.publish(TEST_ENTRY)
186
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
792 d.addCallback(cb)
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
793 return d
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
794
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
795
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
796 def test_itemsMaxItems(self):
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
797 def cb(response):
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
798 xmppURI = response['uri']
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
799 d = self.client.items(xmppURI, 2)
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
800 return d
185
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
801
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
802 d = self.client.publish(TEST_ENTRY)
185
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
803 d.addCallback(cb)
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
804 return d