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