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