annotate idavoll/test/test_gateway.py @ 209:7f3ffb7a1a9e

Add support for node deletion with redirect.
author Ralph Meijer <ralphm@ik.nu>
date Fri, 30 Jan 2009 14:35:05 +0000
parents 274a45d2a5ab
children bfc198af5d27
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
1 # Copyright (c) 2003-2008 Ralph Meijer
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
2 # See LICENSE for details.
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
3
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
4 """
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5 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
6
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
7 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
8 service.
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9 """
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
10
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
11 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
12 from twisted.trial import unittest
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
13 from twisted.web import error
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
14 from twisted.words.xish import domish
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
15
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16 from idavoll import gateway
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
18 AGENT = "Idavoll Test Script"
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
19 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
20
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
21 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
22 TEST_ENTRY.addElement("id",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
23 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
24 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
25 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
26 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
27
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
28 baseURI = "http://localhost:8086/"
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 191
diff changeset
29 componentJID = "pubsub"
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
30
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
31 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
32 timeout = 2
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
33
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
34 def setUp(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
35 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
36 self.client.startService()
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
37 self.addCleanup(self.client.stopService)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
38
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
39 def trapConnectionRefused(failure):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
40 from twisted.internet.error import ConnectionRefusedError
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
41 failure.trap(ConnectionRefusedError)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
42 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
43
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
44 def trapNotFound(failure):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
45 from twisted.web.error import Error
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
46 failure.trap(Error)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
47
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
48 d = self.client.ping()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
49 d.addErrback(trapConnectionRefused)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
50 d.addErrback(trapNotFound)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
51 return d
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
52
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
53
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
54 def tearDown(self):
204
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
55 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
56
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
57
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
58 def test_create(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
59
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
60 def cb(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
61 self.assertIn('uri', response)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
62
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
63 d = self.client.create()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
64 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
65 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
66
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
67 def test_publish(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
68
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
69 def cb(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
70 self.assertIn('uri', response)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
71
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
72 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
73 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
74 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
75
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
76 def test_publishExistingNode(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
77
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
78 def cb2(response, xmppURI):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
79 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
80
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
81 def cb1(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
82 xmppURI = response['uri']
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
83 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
84 d.addCallback(cb2, xmppURI)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
85 return d
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 d = self.client.create()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
88 d.addCallback(cb1)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
89 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
90
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
91 def test_publishNonExisting(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
92 def cb(err):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
93 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
94
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
95 d = self.client.publish(TEST_ENTRY, 'xmpp:%s?node=test' % componentJID)
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
96 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
97 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
98 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
99
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
100 def test_delete(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
101 def cb(response):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
102 xmppURI = response['uri']
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
103 d = self.client.delete(xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
104 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
105
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
106 d = self.client.create()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
107 d.addCallback(cb)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
108 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
109
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
110 def test_deleteWithRedirect(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
111 def cb(response):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
112 xmppURI = response['uri']
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
113 redirectURI = 'xmpp:%s?node=test' % componentJID
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
114 d = self.client.delete(xmppURI, redirectURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
115 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
116
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
117 d = self.client.create()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
118 d.addCallback(cb)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
119 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
120
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
121 def test_deleteNotification(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
122 def onNotification(data, headers):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
123 try:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
124 self.assertTrue(headers.hasHeader('Event'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
125 self.assertEquals(['DELETED'], headers.getRawHeaders('Event'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
126 self.assertFalse(headers.hasHeader('Link'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
127 except:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
128 self.client.deferred.errback()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
129 else:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
130 self.client.deferred.callback(None)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
131
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
132 def cb(response):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
133 xmppURI = response['uri']
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
134 d = self.client.subscribe(xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
135 d.addCallback(lambda _: xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
136 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
137
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
138 def cb2(xmppURI):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
139 d = self.client.delete(xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
140 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
141
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
142 self.client.callback = onNotification
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
143 self.client.deferred = defer.Deferred()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
144 d = self.client.create()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
145 d.addCallback(cb)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
146 d.addCallback(cb2)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
147 return defer.gatherResults([d, self.client.deferred])
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
148
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
149 def test_deleteNotificationWithRedirect(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
150 redirectURI = 'xmpp:%s?node=test' % componentJID
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
151
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
152 def onNotification(data, headers):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
153 try:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
154 self.assertTrue(headers.hasHeader('Event'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
155 self.assertEquals(['DELETED'], headers.getRawHeaders('Event'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
156 self.assertEquals(['<%s>; rel=alternate' % redirectURI],
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
157 headers.getRawHeaders('Link'))
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
158 except:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
159 self.client.deferred.errback()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
160 else:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
161 self.client.deferred.callback(None)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
162
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
163 def cb(response):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
164 xmppURI = response['uri']
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
165 d = self.client.subscribe(xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
166 d.addCallback(lambda _: xmppURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
167 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
168
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
169 def cb2(xmppURI):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
170 d = self.client.delete(xmppURI, redirectURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
171 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
172
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
173 self.client.callback = onNotification
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
174 self.client.deferred = defer.Deferred()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
175 d = self.client.create()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
176 d.addCallback(cb)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
177 d.addCallback(cb2)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
178 return defer.gatherResults([d, self.client.deferred])
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
179
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
180 def test_list(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
181 d = self.client.listNodes()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
182 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
184 def test_subscribe(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
185 def cb(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
186 xmppURI = response['uri']
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
187 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
188 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
189
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
190 d = self.client.create()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
191 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
192 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
193
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
194 def test_subscribeGetNotification(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
195
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
196 def onNotification(data, headers):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
197 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
198
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
199 def cb(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
200 xmppURI = response['uri']
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
201 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
202 d.addCallback(lambda _: xmppURI)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
203 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
204
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
205 def cb2(xmppURI):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
206 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
207 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
208
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
209
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
210 self.client.callback = onNotification
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
211 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
212 d = self.client.create()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
213 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
214 d.addCallback(cb2)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
215 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
216
204
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
217
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
218 def test_subscribeTwiceGetNotification(self):
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
219
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
220 def onNotification1(data, headers):
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
221 d = client1.stopService()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
222 d.chainDeferred(client1.deferred)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
223
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
224 def onNotification2(data, headers):
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
225 d = client2.stopService()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
226 d.chainDeferred(client2.deferred)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
227
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
228 def cb(response):
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
229 xmppURI = response['uri']
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
230 d = client1.subscribe(xmppURI)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
231 d.addCallback(lambda _: xmppURI)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
232 return d
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
233
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
234 def cb2(xmppURI):
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
235 d = client2.subscribe(xmppURI)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
236 d.addCallback(lambda _: xmppURI)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
237 return d
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
238
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
239 def cb3(xmppURI):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
240 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
241 return d
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
242
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
243
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
244 client1 = gateway.GatewayClient(baseURI, callbackPort=8088)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
245 client1.startService()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
246 client1.callback = onNotification1
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
247 client1.deferred = defer.Deferred()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
248 client2 = gateway.GatewayClient(baseURI, callbackPort=8089)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
249 client2.startService()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
250 client2.callback = onNotification2
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
251 client2.deferred = defer.Deferred()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
252
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
253 d = self.client.create()
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
254 d.addCallback(cb)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
255 d.addCallback(cb2)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
256 d.addCallback(cb3)
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
257 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
258 return dl
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
259
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
260
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
261 def test_subscribeGetDelayedNotification(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
262
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
263 def onNotification(data, headers):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
264 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
265
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
266 def cb(response):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
267 xmppURI = response['uri']
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
268 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
269 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
270 d.addCallback(lambda _: xmppURI)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
271 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
272
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
273 def cb2(xmppURI):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
274 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
275 return d
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
276
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
277
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
278 self.client.callback = onNotification
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
279 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
280 d = self.client.create()
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
281 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
282 d.addCallback(cb2)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
283 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
284
187
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
285 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
286 """
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
287 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
288 """
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
289
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
290 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
291 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
292 client1.stopService()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
293
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
294 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
295 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
296 client2.stopService()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
297
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
298 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
299 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
300 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
301 self.assertNot(client2.deferred.called)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
302 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
303 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
304 return d
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
305
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
306 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
307 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
308 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
309 return d
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
310
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
311 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
312 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
313 return d
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
314
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
315 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
316 client1.startService()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
317 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
318 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
319 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
320 client2.startService()
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
321 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
322 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
323
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
324
187
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
325 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
326 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
327 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
328 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
329 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
330 return dl
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
331
69cdd8c6a431 Make sure second subscribers through HTTP also get a notification of the
Ralph Meijer <ralphm@ik.nu>
parents: 186
diff changeset
332
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
333 def test_subscribeNonExisting(self):
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
334 def cb(err):
191
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
335 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
336
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
337 d = self.client.subscribe('xmpp:%s?node=test' % componentJID)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
338 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
339 d.addCallback(cb)
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
340 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
341
186
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
342
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
343 def test_subscribeRootGetNotification(self):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
344
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
345 def onNotification(data, headers):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
346 self.client.deferred.callback(None)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
347
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
348 def cb(response):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
349 xmppURI = response['uri']
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
350 jid, nodeIdentifier = gateway.getServiceAndNode(xmppURI)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
351 rootNode = gateway.getXMPPURI(jid, '')
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
352
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
353 d = self.client.subscribe(rootNode)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
354 d.addCallback(lambda _: xmppURI)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
355 return d
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
356
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
357 def cb2(xmppURI):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
358 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
359
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
360
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
361 self.client.callback = onNotification
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
362 self.client.deferred = defer.Deferred()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
363 d = self.client.create()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
364 d.addCallback(cb)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
365 d.addCallback(cb2)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
366 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
367
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
368
191
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
369 def test_unsubscribeNonExisting(self):
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
370 def cb(err):
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
371 self.assertEqual('403', err.status)
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
372
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
373 d = self.client.unsubscribe('xmpp:%s?node=test' % componentJID)
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
374 self.assertFailure(d, error.Error)
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
375 d.addCallback(cb)
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
376 return d
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
377
48245777acea Return proper HTTP status codes on failed un-/subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
378
185
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
379 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
380 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
381 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
382 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
383 return d
9038908dc2f5 Add gateway support for retrieving items from a node. Reorder gateway module.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
384
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
385 d = self.client.publish(TEST_ENTRY)
186
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
386 d.addCallback(cb)
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
387 return d
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
388
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
389
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
390 def test_itemsMaxItems(self):
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
391 def cb(response):
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
392 xmppURI = response['uri']
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
393 d = self.client.items(xmppURI, 2)
365fd3e4daf8 Add maxItems support.
Ralph Meijer <ralphm@ik.nu>
parents: 185
diff changeset
394 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
395
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 204
diff changeset
396 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
397 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
398 return d