Mercurial > libervia-pubsub
annotate idavoll/test/test_storage.py @ 155:5191ba7c4df8
Work towards first release 0.5.0.
- Add licensing information (MIT)
- Improve installation instructions.
- Use new plugins framework in twisted.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Mon, 21 Aug 2006 16:05:35 +0000 |
parents | b4490bdc77e5 |
children | 21fcfb86433f |
rev | line source |
---|---|
155
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
146
diff
changeset
|
1 # Copyright (c) 2003-2006 Ralph Meijer |
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
146
diff
changeset
|
2 # See LICENSE for details. |
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
146
diff
changeset
|
3 |
114 | 4 from twisted.trial import unittest |
5 from twisted.trial.assertions import * | |
6 from twisted.words.protocols.jabber import jid | |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
7 from twisted.internet import defer |
131 | 8 from twisted.xish import domish |
114 | 9 |
131 | 10 from idavoll import storage, pubsub |
114 | 11 |
12 OWNER = jid.JID('owner@example.com') | |
13 SUBSCRIBER = jid.JID('subscriber@example.com/Home') | |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
14 SUBSCRIBER_NEW = jid.JID('new@example.com/Home') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
15 SUBSCRIBER_TO_BE_DELETED = jid.JID('to_be_deleted@example.com/Home') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
16 SUBSCRIBER_PENDING = jid.JID('pending@example.com/Home') |
131 | 17 PUBLISHER = jid.JID('publisher@example.com') |
18 ITEM = domish.Element((pubsub.NS_PUBSUB, 'item'), pubsub.NS_PUBSUB) | |
19 ITEM['id'] = 'current' | |
20 ITEM.addElement(('testns', 'test'), content=u'Test \u2083 item') | |
21 ITEM_NEW = domish.Element((pubsub.NS_PUBSUB, 'item'), pubsub.NS_PUBSUB) | |
22 ITEM_NEW['id'] = 'new' | |
23 ITEM_NEW.addElement(('testns', 'test'), content=u'Test \u2083 item') | |
24 ITEM_UPDATED = domish.Element((pubsub.NS_PUBSUB, 'item'), pubsub.NS_PUBSUB) | |
25 ITEM_UPDATED['id'] = 'current' | |
26 ITEM_UPDATED.addElement(('testns', 'test'), content=u'Test \u2084 item') | |
27 ITEM_TO_BE_DELETED = domish.Element((pubsub.NS_PUBSUB, 'item'), | |
28 pubsub.NS_PUBSUB) | |
29 ITEM_TO_BE_DELETED['id'] = 'to-be-deleted' | |
30 ITEM_TO_BE_DELETED.addElement(('testns', 'test'), content=u'Test \u2083 item') | |
114 | 31 |
139
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
32 def decode(object): |
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
33 if isinstance(object, str): |
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
34 object = object.decode('utf-8') |
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
35 return object |
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
36 |
114 | 37 class StorageTests: |
38 | |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
39 def _assignTestNode(self, node): |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
40 self.node = node |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
41 |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
42 def setUpClass(self): |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
43 d = self.s.get_node('pre-existing') |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
44 d.addCallback(self._assignTestNode) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
45 return d |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
46 |
114 | 47 def testGetNode(self): |
48 return self.s.get_node('pre-existing') | |
49 | |
50 def testGetNonExistingNode(self): | |
51 d = self.s.get_node('non-existing') | |
52 assertFailure(d, storage.NodeNotFound) | |
53 return d | |
54 | |
55 def testGetNodeIDs(self): | |
56 def cb(node_ids): | |
57 assertIn('pre-existing', node_ids) | |
58 assertNotIn('non-existing', node_ids) | |
59 | |
60 return self.s.get_node_ids().addCallback(cb) | |
61 | |
62 def testCreateExistingNode(self): | |
63 d = self.s.create_node('pre-existing', OWNER) | |
64 assertFailure(d, storage.NodeExists) | |
65 return d | |
66 | |
67 def testCreateNode(self): | |
68 def cb(void): | |
69 d = self.s.get_node('new 1') | |
70 return d | |
71 | |
72 d = self.s.create_node('new 1', OWNER) | |
73 d.addCallback(cb) | |
74 return d | |
75 | |
76 def testDeleteNonExistingNode(self): | |
77 d = self.s.delete_node('non-existing') | |
78 assertFailure(d, storage.NodeNotFound) | |
79 return d | |
80 | |
81 def testDeleteNode(self): | |
82 def cb(void): | |
83 d = self.s.get_node('to-be-deleted') | |
84 assertFailure(d, storage.NodeNotFound) | |
85 return d | |
86 | |
87 d = self.s.delete_node('to-be-deleted') | |
88 d.addCallback(cb) | |
89 return d | |
90 | |
91 def testGetAffiliations(self): | |
92 def cb(affiliations): | |
93 assertIn(('pre-existing', 'owner'), affiliations) | |
94 | |
95 d = self.s.get_affiliations(OWNER) | |
96 d.addCallback(cb) | |
97 return d | |
98 | |
99 def testGetSubscriptions(self): | |
100 def cb(subscriptions): | |
101 assertIn(('pre-existing', SUBSCRIBER, 'subscribed'), subscriptions) | |
102 | |
103 d = self.s.get_subscriptions(SUBSCRIBER) | |
104 d.addCallback(cb) | |
105 return d | |
106 | |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
107 # Node tests |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
108 |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
109 def testGetType(self): |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
110 assertEqual(self.node.get_type(), 'leaf') |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
111 |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
112 def testGetConfiguration(self): |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
113 config = self.node.get_configuration() |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
114 assertIn('pubsub#persist_items', config.iterkeys()) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
115 assertIn('pubsub#deliver_payloads', config.iterkeys()) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
116 assertEqual(config['pubsub#persist_items'], True) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
117 assertEqual(config['pubsub#deliver_payloads'], True) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
118 |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
119 def testSetConfiguration(self): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
120 def get_config(node): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
121 d = node.set_configuration({'pubsub#persist_items': False}) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
122 d.addCallback(lambda _: node) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
123 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
124 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
125 def check_object_config(node): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
126 config = node.get_configuration() |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
127 assertEqual(config['pubsub#persist_items'], False) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
128 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
129 def get_node(void): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
130 return self.s.get_node('to-be-reconfigured') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
131 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
132 def check_storage_config(node): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
133 config = node.get_configuration() |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
134 assertEqual(config['pubsub#persist_items'], False) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
135 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
136 d = self.s.get_node('to-be-reconfigured') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
137 d.addCallback(get_config) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
138 d.addCallback(check_object_config) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
139 d.addCallback(get_node) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
140 d.addCallback(check_storage_config) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
141 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
142 |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
143 def testGetMetaData(self): |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
144 meta_data = self.node.get_meta_data() |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
145 for key, value in self.node.get_configuration().iteritems(): |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
146 assertIn(key, meta_data.iterkeys()) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
147 assertEqual(value, meta_data[key]) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
148 assertIn('pubsub#node_type', meta_data.iterkeys()) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
149 assertEqual(meta_data['pubsub#node_type'], 'leaf') |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
150 |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
151 def testGetAffiliation(self): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
152 def cb(affiliation): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
153 assertEqual(affiliation, 'owner') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
154 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
155 d = self.node.get_affiliation(OWNER) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
156 d.addCallback(cb) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
157 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
158 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
159 def testGetNonExistingAffiliation(self): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
160 def cb(affiliation): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
161 assertEqual(affiliation, None) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
162 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
163 d = self.node.get_affiliation(SUBSCRIBER) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
164 d.addCallback(cb) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
165 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
166 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
167 def testAddSubscription(self): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
168 def cb1(void): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
169 return self.node.get_subscription(SUBSCRIBER_NEW) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
170 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
171 def cb2(state): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
172 assertEqual(state, 'pending') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
173 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
174 d = self.node.add_subscription(SUBSCRIBER_NEW, 'pending') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
175 d.addCallback(cb1) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
176 d.addCallback(cb2) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
177 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
178 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
179 def testAddExistingSubscription(self): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
180 d = self.node.add_subscription(SUBSCRIBER, 'pending') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
181 assertFailure(d, storage.SubscriptionExists) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
182 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
183 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
184 def testGetSubscription(self): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
185 def cb(subscriptions): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
186 assertEquals(subscriptions[0][1], 'subscribed') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
187 assertEquals(subscriptions[1][1], 'pending') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
188 assertEquals(subscriptions[2][1], None) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
189 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
190 d = defer.DeferredList([self.node.get_subscription(SUBSCRIBER), |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
191 self.node.get_subscription(SUBSCRIBER_PENDING), |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
192 self.node.get_subscription(OWNER)]) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
193 d.addCallback(cb) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
194 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
195 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
196 def testRemoveSubscription(self): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
197 return self.node.remove_subscription(SUBSCRIBER_TO_BE_DELETED) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
198 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
199 def testRemoveNonExistingSubscription(self): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
200 d = self.node.remove_subscription(OWNER) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
201 assertFailure(d, storage.SubscriptionNotFound) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
202 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
203 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
204 def testGetSubscribers(self): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
205 def cb(subscribers): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
206 assertIn(SUBSCRIBER, subscribers) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
207 assertNotIn(SUBSCRIBER_PENDING, subscribers) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
208 assertNotIn(OWNER, subscribers) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
209 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
210 d = self.node.get_subscribers() |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
211 d.addCallback(cb) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
212 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
213 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
214 def testIsSubscriber(self): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
215 def cb(subscribed): |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
216 assertEquals(subscribed[0][1], True) |
146
b4490bdc77e5
Change semantics of Node.is_subscribed() to match all subscriptions for an
Ralph Meijer <ralphm@ik.nu>
parents:
145
diff
changeset
|
217 assertEquals(subscribed[1][1], True) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
218 assertEquals(subscribed[2][1], False) |
146
b4490bdc77e5
Change semantics of Node.is_subscribed() to match all subscriptions for an
Ralph Meijer <ralphm@ik.nu>
parents:
145
diff
changeset
|
219 assertEquals(subscribed[3][1], False) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
220 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
221 d = defer.DeferredList([self.node.is_subscribed(SUBSCRIBER), |
146
b4490bdc77e5
Change semantics of Node.is_subscribed() to match all subscriptions for an
Ralph Meijer <ralphm@ik.nu>
parents:
145
diff
changeset
|
222 self.node.is_subscribed(SUBSCRIBER.userhostJID()), |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
223 self.node.is_subscribed(SUBSCRIBER_PENDING), |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
224 self.node.is_subscribed(OWNER)]) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
225 d.addCallback(cb) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
226 return d |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
227 |
131 | 228 def testStoreItems(self): |
138
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
229 def cb1(void): |
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
230 return self.node.get_items_by_id(['new']) |
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
231 |
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
232 def cb2(result): |
139
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
233 assertEqual(result[0], decode(ITEM_NEW.toXml())) |
138
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
234 |
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
235 d = self.node.store_items([ITEM_NEW], PUBLISHER) |
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
236 d.addCallback(cb1) |
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
237 d.addCallback(cb2) |
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
238 return d |
131 | 239 |
240 def testStoreUpdatedItems(self): | |
241 def cb1(void): | |
242 return self.node.get_items_by_id(['current']) | |
243 | |
244 def cb2(result): | |
139
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
245 assertEqual(result[0], decode(ITEM_UPDATED.toXml())) |
131 | 246 |
247 d = self.node.store_items([ITEM_UPDATED], PUBLISHER) | |
248 d.addCallback(cb1) | |
249 d.addCallback(cb2) | |
250 return d | |
251 | |
252 def testRemoveItems(self): | |
142
812300cdbc22
Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents:
139
diff
changeset
|
253 def cb1(result): |
812300cdbc22
Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents:
139
diff
changeset
|
254 assertEqual(result, ['to-be-deleted']) |
131 | 255 return self.node.get_items_by_id(['to-be-deleted']) |
256 | |
257 def cb2(result): | |
258 assertEqual(len(result), 0) | |
259 | |
260 d = self.node.remove_items(['to-be-deleted']) | |
261 d.addCallback(cb1) | |
262 d.addCallback(cb2) | |
263 return d | |
264 | |
265 def testRemoveNonExistingItems(self): | |
142
812300cdbc22
Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents:
139
diff
changeset
|
266 def cb(result): |
812300cdbc22
Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents:
139
diff
changeset
|
267 assertEqual(result, []) |
812300cdbc22
Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents:
139
diff
changeset
|
268 |
812300cdbc22
Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents:
139
diff
changeset
|
269 d = self.node.remove_items(['non-existing']) |
812300cdbc22
Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents:
139
diff
changeset
|
270 d.addCallback(cb) |
131 | 271 return d |
272 | |
273 def testGetItems(self): | |
274 def cb(result): | |
139
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
275 assertIn(decode(ITEM.toXml()), result) |
131 | 276 |
277 d = self.node.get_items() | |
278 d.addCallback(cb) | |
279 return d | |
280 | |
281 def testLastItem(self): | |
282 def cb(result): | |
139
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
283 assertEqual([decode(ITEM.toXml())], result) |
131 | 284 |
285 d = self.node.get_items(1) | |
286 d.addCallback(cb) | |
287 return d | |
288 | |
289 def testGetItemsById(self): | |
290 def cb(result): | |
291 assertEqual(len(result), 1) | |
292 | |
293 d = self.node.get_items_by_id(['current']) | |
294 d.addCallback(cb) | |
295 return d | |
296 | |
297 def testGetNonExistingItemsById(self): | |
298 def cb(result): | |
299 assertEqual(len(result), 0) | |
300 | |
301 d = self.node.get_items_by_id(['non-existing']) | |
302 d.addCallback(cb) | |
303 return d | |
304 | |
305 def testPurge(self): | |
306 def cb1(node): | |
307 d = node.purge() | |
308 d.addCallback(lambda _: node) | |
309 return d | |
310 | |
311 def cb2(node): | |
312 return node.get_items() | |
313 | |
314 def cb3(result): | |
315 assertEqual([], result) | |
316 | |
317 d = self.s.get_node('to-be-purged') | |
318 d.addCallback(cb1) | |
319 d.addCallback(cb2) | |
320 d.addCallback(cb3) | |
321 return d | |
322 | |
145
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
323 def testGetNodeAffilatiations(self): |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
324 def cb1(node): |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
325 return node.get_affiliations() |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
326 |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
327 def cb2(affiliations): |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
328 affiliations = dict(((a[0].full(), a[1]) for a in affiliations)) |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
329 assertEquals(affiliations[OWNER.full()], 'owner') |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
330 |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
331 d = self.s.get_node('pre-existing') |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
332 d.addCallback(cb1) |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
333 d.addCallback(cb2) |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
334 return d |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
335 |
114 | 336 class MemoryStorageStorageTestCase(unittest.TestCase, StorageTests): |
337 | |
338 def setUpClass(self): | |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
339 from idavoll.memory_storage import Storage, LeafNode, Subscription, \ |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
340 default_config |
114 | 341 self.s = Storage() |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
342 self.s._nodes['pre-existing'] = \ |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
343 LeafNode('pre-existing', OWNER, default_config) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
344 self.s._nodes['to-be-deleted'] = \ |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
345 LeafNode('to-be-deleted', OWNER, None) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
346 self.s._nodes['to-be-reconfigured'] = \ |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
347 LeafNode('to-be-reconfigured', OWNER, default_config) |
131 | 348 self.s._nodes['to-be-purged'] = \ |
349 LeafNode('to-be-purged', OWNER, None) | |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
350 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
351 subscriptions = self.s._nodes['pre-existing']._subscriptions |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
352 subscriptions[SUBSCRIBER.full()] = Subscription('subscribed') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
353 subscriptions[SUBSCRIBER_TO_BE_DELETED.full()] = \ |
114 | 354 Subscription('subscribed') |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
355 subscriptions[SUBSCRIBER_PENDING.full()] = \ |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
356 Subscription('pending') |
114 | 357 |
139
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
358 item = (decode(ITEM_TO_BE_DELETED.toXml()), PUBLISHER) |
131 | 359 self.s._nodes['pre-existing']._items['to-be-deleted'] = item |
360 self.s._nodes['pre-existing']._itemlist.append(item) | |
361 self.s._nodes['to-be-purged']._items['to-be-deleted'] = item | |
362 self.s._nodes['to-be-purged']._itemlist.append(item) | |
139
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
363 item = (decode(ITEM.toXml()), PUBLISHER) |
131 | 364 self.s._nodes['pre-existing']._items['current'] = item |
365 self.s._nodes['pre-existing']._itemlist.append(item) | |
366 | |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
367 return StorageTests.setUpClass(self) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
368 |
114 | 369 class PgsqlStorageStorageTestCase(unittest.TestCase, StorageTests): |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
370 def _callSuperSetUpClass(self, void): |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
371 return StorageTests.setUpClass(self) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
372 |
114 | 373 def setUpClass(self): |
374 from idavoll.pgsql_storage import Storage | |
375 self.s = Storage('ralphm', 'pubsub_test') | |
376 self.s._dbpool.start() | |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
377 d = self.s._dbpool.runInteraction(self.init) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
378 d.addCallback(self._callSuperSetUpClass) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
379 return d |
114 | 380 |
381 def tearDownClass(self): | |
131 | 382 #return self.s._dbpool.runInteraction(self.cleandb) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
383 pass |
114 | 384 |
385 def init(self, cursor): | |
386 self.cleandb(cursor) | |
387 cursor.execute("""INSERT INTO nodes (node) VALUES ('pre-existing')""") | |
388 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-deleted')""") | |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
389 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-reconfigured')""") |
131 | 390 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-purged')""") |
114 | 391 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
392 OWNER.userhost()) |
114 | 393 cursor.execute("""INSERT INTO affiliations |
394 (node_id, entity_id, affiliation) | |
395 SELECT nodes.id, entities.id, 'owner' | |
396 FROM nodes, entities | |
397 WHERE node='pre-existing' AND jid=%s""", | |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
398 OWNER.userhost()) |
114 | 399 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
400 SUBSCRIBER.userhost()) |
114 | 401 cursor.execute("""INSERT INTO subscriptions |
402 (node_id, entity_id, resource, subscription) | |
403 SELECT nodes.id, entities.id, %s, 'subscribed' | |
404 FROM nodes, entities | |
405 WHERE node='pre-existing' AND jid=%s""", | |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
406 (SUBSCRIBER.resource, |
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
407 SUBSCRIBER.userhost())) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
408 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
409 SUBSCRIBER_TO_BE_DELETED.userhost()) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
410 cursor.execute("""INSERT INTO subscriptions |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
411 (node_id, entity_id, resource, subscription) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
412 SELECT nodes.id, entities.id, %s, 'subscribed' |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
413 FROM nodes, entities |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
414 WHERE node='pre-existing' AND jid=%s""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
415 (SUBSCRIBER_TO_BE_DELETED.resource, |
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
416 SUBSCRIBER_TO_BE_DELETED.userhost())) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
417 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
418 SUBSCRIBER_PENDING.userhost()) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
419 cursor.execute("""INSERT INTO subscriptions |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
420 (node_id, entity_id, resource, subscription) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
421 SELECT nodes.id, entities.id, %s, 'pending' |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
422 FROM nodes, entities |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
423 WHERE node='pre-existing' AND jid=%s""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
424 (SUBSCRIBER_PENDING.resource, |
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
425 SUBSCRIBER_PENDING.userhost())) |
131 | 426 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
427 PUBLISHER.userhost()) |
131 | 428 cursor.execute("""INSERT INTO items |
429 (node_id, publisher, item, data, date) | |
430 SELECT nodes.id, %s, 'to-be-deleted', %s, | |
431 now() - interval '1 day' | |
432 FROM nodes | |
433 WHERE node='pre-existing'""", | |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
434 (PUBLISHER.userhost(), |
131 | 435 ITEM_TO_BE_DELETED.toXml())) |
436 cursor.execute("""INSERT INTO items (node_id, publisher, item, data) | |
437 SELECT nodes.id, %s, 'to-be-deleted', %s | |
438 FROM nodes | |
439 WHERE node='to-be-purged'""", | |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
440 (PUBLISHER.userhost(), |
131 | 441 ITEM_TO_BE_DELETED.toXml())) |
442 cursor.execute("""INSERT INTO items (node_id, publisher, item, data) | |
443 SELECT nodes.id, %s, 'current', %s | |
444 FROM nodes | |
445 WHERE node='pre-existing'""", | |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
446 (PUBLISHER.userhost(), |
131 | 447 ITEM.toXml())) |
114 | 448 |
449 def cleandb(self, cursor): | |
450 cursor.execute("""DELETE FROM nodes WHERE node in | |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
451 ('non-existing', 'pre-existing', 'to-be-deleted', |
131 | 452 'new 1', 'new 2', 'new 3', 'to-be-reconfigured', |
453 'to-be-purged')""") | |
114 | 454 cursor.execute("""DELETE FROM entities WHERE jid=%s""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
455 OWNER.userhost()) |
114 | 456 cursor.execute("""DELETE FROM entities WHERE jid=%s""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
457 SUBSCRIBER.userhost()) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
458 cursor.execute("""DELETE FROM entities WHERE jid=%s""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
459 SUBSCRIBER_TO_BE_DELETED.userhost()) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
460 cursor.execute("""DELETE FROM entities WHERE jid=%s""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
461 SUBSCRIBER_PENDING.userhost()) |
131 | 462 cursor.execute("""DELETE FROM entities WHERE jid=%s""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
463 PUBLISHER.userhost()) |