annotate idavoll/test/test_backend.py @ 187:69cdd8c6a431

Make sure second subscribers through HTTP also get a notification of the last item.
author Ralph Meijer <ralphm@ik.nu>
date Thu, 17 Apr 2008 16:02:22 +0000
parents 07114105885a
children e404775b12df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
1 # Copyright (c) 2003-2008 Ralph Meijer
155
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 143
diff changeset
2 # See LICENSE for details.
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 143
diff changeset
3
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
4 """
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
5 Tests for L{idavoll.backend}.
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
6 """
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
7
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
8 from twisted.internet import defer
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9 from twisted.trial import unittest
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
10 from twisted.words.protocols.jabber import jid
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
11 from twisted.words.protocols.jabber.error import StanzaError
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
12
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
13 from wokkel import pubsub
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
14
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
15 from idavoll import backend, error
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17 OWNER = jid.JID('owner@example.com')
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
18 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
19
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
20 class BackendTest(unittest.TestCase):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
21 def test_delete_node(self):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
22 class testNode:
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
23 id = 'to-be-deleted'
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
24 def get_affiliation(self, entity):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
25 if entity is OWNER:
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
26 return defer.succeed('owner')
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
27
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
28 class testStorage:
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
29 def get_node(self, node_id):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
30 return defer.succeed(testNode())
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
31
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
32 def delete_node(self, node_id):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
33 if node_id in ['to-be-deleted']:
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
34 self.delete_called = True
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
35 return defer.succeed(None)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
36 else:
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
37 return defer.fail(error.NodeNotFound())
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
38
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
39 def pre_delete(node_id):
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
40 self.pre_delete_called = True
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
41 return defer.succeed(None)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
42
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
43 def cb(result):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
44 self.assertTrue(self.pre_delete_called)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
45 self.assertTrue(self.storage.delete_called)
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
46
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
47 self.storage = testStorage()
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
48 self.backend = backend.BackendService(self.storage)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
49 self.storage.backend = self.backend
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
50
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
51 self.pre_delete_called = False
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
52 self.delete_called = False
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
53
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
54 self.backend.register_pre_delete(pre_delete)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
55 d = self.backend.delete_node('to-be-deleted', OWNER)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
56 d.addCallback(cb)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
57 return d
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
58
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
59 def test_create_nodeNoID(self):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
60 """
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
61 Test creation of a node without a given node identifier.
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
62 """
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
63 class testStorage:
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
64 def create_node(self, node_id, requestor):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
65 self.node_id = node_id
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
66 return defer.succeed(None)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
67
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
68 self.storage = testStorage()
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
69 self.backend = backend.BackendService(self.storage)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
70 self.storage.backend = self.backend
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
71
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
72 def checkID(nodeIdentifier):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
73 self.assertNotIdentical(None, nodeIdentifier)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
74 self.assertIdentical(self.storage.node_id, nodeIdentifier)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
75
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
76 d = self.backend.create_node(None, OWNER)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
77 d.addCallback(checkID)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
78 return d
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
79
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
80 def test_publishNoID(self):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
81 """
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
82 Test publish request with an item without a node identifier.
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
83 """
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
84 class testNode:
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
85 id = 'node'
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
86 def get_affiliation(self, entity):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
87 if entity is OWNER:
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
88 return defer.succeed('owner')
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
89 def get_configuration(self):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
90 return {'pubsub#deliver_payloads': True,
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
91 'pubsub#persist_items': False}
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
92
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
93 class testStorage:
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
94 def get_node(self, node_id):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
95 return defer.succeed(testNode())
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
96
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
97 def checkID(notification):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
98 self.assertNotIdentical(None, notification['items'][0]['id'])
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
99
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
100 self.storage = testStorage()
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
101 self.backend = backend.BackendService(self.storage)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
102 self.storage.backend = self.backend
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
103
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
104 self.backend.register_notifier(checkID)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
105
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
106 items = [pubsub.Item()]
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
107 d = self.backend.publish('node', items, OWNER)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
108 return d
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
109
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
110 def test_notifyOnSubscription(self):
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
111 """
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
112 Test notification of last published item on subscription.
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
113 """
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
114 ITEM = "<item xmlns='%s' id='1'/>" % NS_PUBSUB
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
115
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
116 class testNode:
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
117 id = 'node'
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
118 def get_affiliation(self, entity):
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
119 if entity is OWNER:
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
120 return defer.succeed('owner')
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
121 def get_configuration(self):
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
122 return {'pubsub#deliver_payloads': True,
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
123 'pubsub#persist_items': False,
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
124 'pubsub#send_last_published_item': 'on_sub'}
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
125 def get_items(self, max_items):
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
126 return [ITEM]
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
127 def add_subscription(self, subscriber, state):
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
128 return defer.succeed(None)
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
129
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
130 class testStorage:
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
131 def get_node(self, node_id):
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
132 return defer.succeed(testNode())
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
133
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
134 def cb(data):
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
135 self.assertEquals('node', data['node_id'])
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
136 self.assertEquals([ITEM], data['items'])
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
137 self.assertEquals(OWNER, data['subscriber'])
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
138
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
139 self.storage = testStorage()
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
140 self.backend = backend.BackendService(self.storage)
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
141 self.storage.backend = self.backend
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
142
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
143 d1 = defer.Deferred()
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
144 d1.addCallback(cb)
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
145 self.backend.register_notifier(d1.callback)
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
146 d2 = self.backend.subscribe('node', OWNER, OWNER)
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
147 return defer.gatherResults([d1, d2])
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
148
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
149 test_notifyOnSubscription.timeout = 2
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
150
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
151
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
152 class BaseTestBackend(object):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
153 """
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
154 Base class for backend stubs.
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
155 """
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
156
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
157 def supports_publisher_affiliation(self):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
158 return True
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
159
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
160 def supports_outcast_affiliation(self):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
161 return True
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
162
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
163 def supports_persistent_items(self):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
164 return True
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
165
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
166 def supports_instant_nodes(self):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
167 return True
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
168
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
169 def register_notifier(self, observerfn, *args, **kwargs):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
170 return
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
171
175
bd86f0c3fd39 Make test backend consistent with interface.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
172 def register_pre_delete(self, pre_delete_fn):
bd86f0c3fd39 Make test backend consistent with interface.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
173 return
bd86f0c3fd39 Make test backend consistent with interface.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
174
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
175
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
176 class PubSubServiceFromBackendTest(unittest.TestCase):
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
177
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
178 def test_unsubscribeNotSubscribed(self):
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
179 """
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
180 Test unsubscription request when not subscribed.
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
181 """
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
182
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
183 class TestBackend(BaseTestBackend):
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
184 def unsubscribe(self, nodeIdentifier, subscriber, requestor):
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
185 return defer.fail(error.NotSubscribed())
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
186
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
187 def cb(e):
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
188 self.assertEquals('unexpected-request', e.condition)
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
189
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
190 s = backend.PubSubServiceFromBackend(TestBackend())
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
191 d = s.unsubscribe(OWNER, 'test.example.org', 'test', OWNER)
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
192 self.assertFailure(d, StanzaError)
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
193 d.addCallback(cb)
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
194 return d
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
195
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
196 def test_getNodeInfo(self):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
197 """
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
198 Test retrieving node information.
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
199 """
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
200
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
201 class TestBackend(BaseTestBackend):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
202 def get_node_type(self, nodeIdentifier):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
203 return defer.succeed('leaf')
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
204
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
205 def get_node_meta_data(self, nodeIdentifier):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
206 return defer.succeed({'pubsub#persist_items': True})
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
207
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
208 def cb(info):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
209 self.assertIn('type', info)
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
210 self.assertEquals('leaf', info['type'])
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
211 self.assertIn('meta-data', info)
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
212 self.assertEquals({'pubsub#persist_items': True}, info['meta-data'])
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
213
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
214 s = backend.PubSubServiceFromBackend(TestBackend())
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
215 d = s.getNodeInfo(OWNER, 'test.example.org', 'test')
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
216 d.addCallback(cb)
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
217 return d