Mercurial > libervia-pubsub
annotate idavoll/test/test_storage.py @ 220:e59b48f3f636
Add tests for subscription and unsubscription JID checks in [53d2c0019458].
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sat, 16 Oct 2010 20:54:52 +0200 |
parents | bb7103da9879 |
children | a430976f2977 |
rev | line source |
---|---|
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
1 # Copyright (c) 2003-2008 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 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
8 from zope.interface.verify import verifyObject |
114 | 9 from twisted.trial import unittest |
10 from twisted.words.protocols.jabber import jid | |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
11 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
|
12 from twisted.words.xish import domish |
114 | 13 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
14 from idavoll import error, iidavoll |
114 | 15 |
16 OWNER = jid.JID('owner@example.com') | |
17 SUBSCRIBER = jid.JID('subscriber@example.com/Home') | |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
18 SUBSCRIBER_NEW = jid.JID('new@example.com/Home') |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
19 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
|
20 SUBSCRIBER_PENDING = jid.JID('pending@example.com/Home') |
131 | 21 PUBLISHER = jid.JID('publisher@example.com') |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
22 ITEM = domish.Element((None, 'item')) |
131 | 23 ITEM['id'] = 'current' |
24 ITEM.addElement(('testns', 'test'), content=u'Test \u2083 item') | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
25 ITEM_NEW = domish.Element((None, 'item')) |
131 | 26 ITEM_NEW['id'] = 'new' |
27 ITEM_NEW.addElement(('testns', 'test'), content=u'Test \u2083 item') | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
28 ITEM_UPDATED = domish.Element((None, 'item')) |
131 | 29 ITEM_UPDATED['id'] = 'current' |
30 ITEM_UPDATED.addElement(('testns', 'test'), content=u'Test \u2084 item') | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
31 ITEM_TO_BE_DELETED = domish.Element((None, 'item')) |
131 | 32 ITEM_TO_BE_DELETED['id'] = 'to-be-deleted' |
33 ITEM_TO_BE_DELETED.addElement(('testns', 'test'), content=u'Test \u2083 item') | |
114 | 34 |
139
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
35 def decode(object): |
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
36 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
|
37 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
|
38 return object |
8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Ralph Meijer <ralphm@ik.nu>
parents:
138
diff
changeset
|
39 |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
40 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
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 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
47 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
48 def setUp(self): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
49 d = self.s.getNode('pre-existing') |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
50 d.addCallback(self._assignTestNode) |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
51 return d |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
52 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
53 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
54 def test_interfaceIStorage(self): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
55 self.assertTrue(verifyObject(iidavoll.IStorage, self.s)) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
56 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
57 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
58 def test_interfaceINode(self): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
59 self.assertTrue(verifyObject(iidavoll.INode, self.node)) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
60 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
61 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
62 def test_interfaceILeafNode(self): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
63 self.assertTrue(verifyObject(iidavoll.ILeafNode, self.node)) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
64 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
65 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
66 def test_getNode(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
67 return self.s.getNode('pre-existing') |
114 | 68 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
69 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
70 def test_getNonExistingNode(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
71 d = self.s.getNode('non-existing') |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
72 self.assertFailure(d, error.NodeNotFound) |
114 | 73 return d |
74 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
75 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
76 def test_getNodeIDs(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
77 def cb(nodeIdentifiers): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
78 self.assertIn('pre-existing', nodeIdentifiers) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
79 self.assertNotIn('non-existing', nodeIdentifiers) |
114 | 80 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
81 return self.s.getNodeIds().addCallback(cb) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
82 |
114 | 83 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
84 def test_createExistingNode(self): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
85 config = self.s.getDefaultConfiguration('leaf') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
86 config['pubsub#node_type'] = 'leaf' |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
87 d = self.s.createNode('pre-existing', OWNER, config) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
88 self.assertFailure(d, error.NodeExists) |
114 | 89 return d |
90 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
91 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
92 def test_createNode(self): |
114 | 93 def cb(void): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
94 d = self.s.getNode('new 1') |
114 | 95 return d |
96 | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
97 config = self.s.getDefaultConfiguration('leaf') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
98 config['pubsub#node_type'] = 'leaf' |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
99 d = self.s.createNode('new 1', OWNER, config) |
114 | 100 d.addCallback(cb) |
101 return d | |
102 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
103 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
104 def test_deleteNonExistingNode(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
105 d = self.s.deleteNode('non-existing') |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
106 self.assertFailure(d, error.NodeNotFound) |
114 | 107 return d |
108 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
109 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
110 def test_deleteNode(self): |
114 | 111 def cb(void): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
112 d = self.s.getNode('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
|
113 self.assertFailure(d, error.NodeNotFound) |
114 | 114 return d |
115 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
116 d = self.s.deleteNode('to-be-deleted') |
114 | 117 d.addCallback(cb) |
118 return d | |
119 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
120 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
121 def test_getAffiliations(self): |
114 | 122 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
|
123 self.assertIn(('pre-existing', 'owner'), affiliations) |
114 | 124 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
125 d = self.s.getAffiliations(OWNER) |
114 | 126 d.addCallback(cb) |
127 return d | |
128 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
129 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
130 def test_getSubscriptions(self): |
114 | 131 def cb(subscriptions): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
132 found = False |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
133 for subscription in subscriptions: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
134 if (subscription.nodeIdentifier == 'pre-existing' and |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
135 subscription.subscriber == SUBSCRIBER and |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
136 subscription.state == 'subscribed'): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
137 found = True |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
138 self.assertTrue(found) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
139 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
140 d = self.s.getSubscriptions(SUBSCRIBER) |
114 | 141 d.addCallback(cb) |
142 return d | |
143 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
144 |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
145 # Node tests |
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
146 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
147 def test_getType(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
148 self.assertEqual(self.node.getType(), 'leaf') |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
149 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
150 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
151 def test_getConfiguration(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
152 config = self.node.getConfiguration() |
157
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#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
|
154 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
|
155 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
|
156 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
|
157 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
158 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
159 def test_setConfiguration(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
160 def getConfig(node): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
161 d = node.setConfiguration({'pubsub#persist_items': False}) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
162 d.addCallback(lambda _: node) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
163 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
164 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
165 def checkObjectConfig(node): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
166 config = node.getConfiguration() |
157
21fcfb86433f
Fix tests to work with current Twisted. Really do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents:
155
diff
changeset
|
167 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
|
168 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
169 def getNode(void): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
170 return self.s.getNode('to-be-reconfigured') |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
171 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
172 def checkStorageConfig(node): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
173 config = node.getConfiguration() |
157
21fcfb86433f
Fix tests to work with current Twisted. Really do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents:
155
diff
changeset
|
174 self.assertEqual(config['pubsub#persist_items'], False) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
175 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
176 d = self.s.getNode('to-be-reconfigured') |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
177 d.addCallback(getConfig) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
178 d.addCallback(checkObjectConfig) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
179 d.addCallback(getNode) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
180 d.addCallback(checkStorageConfig) |
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 |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
183 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
184 def test_getMetaData(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
185 metaData = self.node.getMetaData() |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
186 for key, value in self.node.getConfiguration().iteritems(): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
187 self.assertIn(key, metaData.iterkeys()) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
188 self.assertEqual(value, metaData[key]) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
189 self.assertIn('pubsub#node_type', metaData.iterkeys()) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
190 self.assertEqual(metaData['pubsub#node_type'], 'leaf') |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
191 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
192 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
193 def test_getAffiliation(self): |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
194 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
|
195 self.assertEqual(affiliation, 'owner') |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
196 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
197 d = self.node.getAffiliation(OWNER) |
123
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 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
201 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
202 def test_getNonExistingAffiliation(self): |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
203 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
|
204 self.assertEqual(affiliation, None) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
205 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
206 d = self.node.getAffiliation(SUBSCRIBER) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
207 d.addCallback(cb) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
208 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
209 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
210 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
211 def test_addSubscription(self): |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
212 def cb1(void): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
213 return self.node.getSubscription(SUBSCRIBER_NEW) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
214 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
215 def cb2(subscription): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
216 self.assertEqual(subscription.state, 'pending') |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
217 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
218 d = self.node.addSubscription(SUBSCRIBER_NEW, 'pending', {}) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
219 d.addCallback(cb1) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
220 d.addCallback(cb2) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
221 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
222 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
223 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
224 def test_addExistingSubscription(self): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
225 d = self.node.addSubscription(SUBSCRIBER, 'pending', {}) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
226 self.assertFailure(d, error.SubscriptionExists) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
227 return d |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
228 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
229 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
230 def test_getSubscription(self): |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
231 def cb(subscriptions): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
232 self.assertEquals(subscriptions[0].state, 'subscribed') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
233 self.assertEquals(subscriptions[1].state, 'pending') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
234 self.assertEquals(subscriptions[2], None) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
235 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
236 d = defer.gatherResults([self.node.getSubscription(SUBSCRIBER), |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
237 self.node.getSubscription(SUBSCRIBER_PENDING), |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
238 self.node.getSubscription(OWNER)]) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
239 d.addCallback(cb) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
240 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
241 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
242 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
243 def test_removeSubscription(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
244 return self.node.removeSubscription(SUBSCRIBER_TO_BE_DELETED) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
245 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
246 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
247 def test_removeNonExistingSubscription(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
248 d = self.node.removeSubscription(OWNER) |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
249 self.assertFailure(d, error.NotSubscribed) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
250 return d |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
251 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
252 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
253 def test_getNodeSubscriptions(self): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
254 def extractSubscribers(subscriptions): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
255 return [subscription.subscriber for subscription in subscriptions] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
256 |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
257 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
|
258 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
|
259 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
|
260 self.assertNotIn(OWNER, subscribers) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
261 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
262 d = self.node.getSubscriptions('subscribed') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
263 d.addCallback(extractSubscribers) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
264 d.addCallback(cb) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
265 return d |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
266 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
267 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
268 def test_isSubscriber(self): |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
269 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
|
270 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
|
271 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
|
272 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
|
273 self.assertEquals(subscribed[3][1], False) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
274 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
275 d = defer.DeferredList([self.node.isSubscribed(SUBSCRIBER), |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
276 self.node.isSubscribed(SUBSCRIBER.userhostJID()), |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
277 self.node.isSubscribed(SUBSCRIBER_PENDING), |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
278 self.node.isSubscribed(OWNER)]) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
279 d.addCallback(cb) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
280 return d |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
281 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
282 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
283 def test_storeItems(self): |
138
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
284 def cb1(void): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
285 return self.node.getItemsById(['new']) |
138
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
286 |
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
287 def cb2(result): |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
288 self.assertEqual(ITEM_NEW.toXml(), result[0].toXml()) |
138
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
289 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
290 d = self.node.storeItems([ITEM_NEW], PUBLISHER) |
138
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
291 d.addCallback(cb1) |
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
292 d.addCallback(cb2) |
635e433810ef
Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents:
137
diff
changeset
|
293 return d |
131 | 294 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
295 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
296 def test_storeUpdatedItems(self): |
131 | 297 def cb1(void): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
298 return self.node.getItemsById(['current']) |
131 | 299 |
300 def cb2(result): | |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
301 self.assertEqual(ITEM_UPDATED.toXml(), result[0].toXml()) |
131 | 302 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
303 d = self.node.storeItems([ITEM_UPDATED], PUBLISHER) |
131 | 304 d.addCallback(cb1) |
305 d.addCallback(cb2) | |
306 return d | |
307 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
308 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
309 def test_removeItems(self): |
142
812300cdbc22
Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents:
139
diff
changeset
|
310 def cb1(result): |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
311 self.assertEqual(['to-be-deleted'], result) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
312 return self.node.getItemsById(['to-be-deleted']) |
131 | 313 |
314 def cb2(result): | |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
315 self.assertEqual(0, len(result)) |
131 | 316 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
317 d = self.node.removeItems(['to-be-deleted']) |
131 | 318 d.addCallback(cb1) |
319 d.addCallback(cb2) | |
320 return d | |
321 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
322 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
323 def test_removeNonExistingItems(self): |
142
812300cdbc22
Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents:
139
diff
changeset
|
324 def cb(result): |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
325 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
|
326 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
327 d = self.node.removeItems(['non-existing']) |
142
812300cdbc22
Changed behaviour of retraction of items so that only the actually deleted
Ralph Meijer <ralphm@ik.nu>
parents:
139
diff
changeset
|
328 d.addCallback(cb) |
131 | 329 return d |
330 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
331 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
332 def test_getItems(self): |
131 | 333 def cb(result): |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
334 items = [item.toXml() for item in result] |
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
335 self.assertIn(ITEM.toXml(), items) |
131 | 336 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
337 d = self.node.getItems() |
131 | 338 d.addCallback(cb) |
339 return d | |
340 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
341 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
342 def test_lastItem(self): |
131 | 343 def cb(result): |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
344 self.assertEqual(1, len(result)) |
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
345 self.assertEqual(ITEM.toXml(), result[0].toXml()) |
131 | 346 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
347 d = self.node.getItems(1) |
131 | 348 d.addCallback(cb) |
349 return d | |
350 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
351 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
352 def test_getItemsById(self): |
131 | 353 def cb(result): |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
354 self.assertEqual(1, len(result)) |
131 | 355 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
356 d = self.node.getItemsById(['current']) |
131 | 357 d.addCallback(cb) |
358 return d | |
359 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
360 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
361 def test_getNonExistingItemsById(self): |
131 | 362 def cb(result): |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
363 self.assertEqual(0, len(result)) |
131 | 364 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
365 d = self.node.getItemsById(['non-existing']) |
131 | 366 d.addCallback(cb) |
367 return d | |
368 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
369 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
370 def test_purge(self): |
131 | 371 def cb1(node): |
372 d = node.purge() | |
373 d.addCallback(lambda _: node) | |
374 return d | |
375 | |
376 def cb2(node): | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
377 return node.getItems() |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
378 |
131 | 379 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
|
380 self.assertEqual([], result) |
131 | 381 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
382 d = self.s.getNode('to-be-purged') |
131 | 383 d.addCallback(cb1) |
384 d.addCallback(cb2) | |
385 d.addCallback(cb3) | |
386 return d | |
387 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
388 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
389 def test_getNodeAffilatiations(self): |
145
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
390 def cb1(node): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
391 return node.getAffiliations() |
145
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
392 |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
397 d = self.s.getNode('pre-existing') |
145
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
398 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
|
399 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
|
400 return d |
f393bccec4bc
Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents:
142
diff
changeset
|
401 |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
402 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
403 |
114 | 404 class MemoryStorageStorageTestCase(unittest.TestCase, StorageTests): |
405 | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
406 def setUp(self): |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
407 from idavoll.memory_storage import Storage, PublishedItem, LeafNode |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
408 from idavoll.memory_storage import Subscription |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
409 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
410 defaultConfig = Storage.defaultConfig['leaf'] |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
411 |
114 | 412 self.s = Storage() |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
413 self.s._nodes['pre-existing'] = \ |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
414 LeafNode('pre-existing', OWNER, defaultConfig) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
415 self.s._nodes['to-be-deleted'] = \ |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
416 LeafNode('to-be-deleted', OWNER, None) |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
417 self.s._nodes['to-be-reconfigured'] = \ |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
418 LeafNode('to-be-reconfigured', OWNER, defaultConfig) |
131 | 419 self.s._nodes['to-be-purged'] = \ |
420 LeafNode('to-be-purged', OWNER, None) | |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
421 |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
422 subscriptions = self.s._nodes['pre-existing']._subscriptions |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
423 subscriptions[SUBSCRIBER.full()] = Subscription('pre-existing', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
424 SUBSCRIBER, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
425 'subscribed') |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
426 subscriptions[SUBSCRIBER_TO_BE_DELETED.full()] = \ |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
427 Subscription('pre-existing', SUBSCRIBER_TO_BE_DELETED, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
428 'subscribed') |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
429 subscriptions[SUBSCRIBER_PENDING.full()] = \ |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
430 Subscription('pre-existing', SUBSCRIBER_PENDING, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
431 'pending') |
114 | 432 |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
433 item = PublishedItem(ITEM_TO_BE_DELETED, PUBLISHER) |
131 | 434 self.s._nodes['pre-existing']._items['to-be-deleted'] = item |
435 self.s._nodes['pre-existing']._itemlist.append(item) | |
436 self.s._nodes['to-be-purged']._items['to-be-deleted'] = item | |
437 self.s._nodes['to-be-purged']._itemlist.append(item) | |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
438 item = PublishedItem(ITEM, PUBLISHER) |
131 | 439 self.s._nodes['pre-existing']._items['current'] = item |
440 self.s._nodes['pre-existing']._itemlist.append(item) | |
441 | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
442 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
|
443 |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
444 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
445 |
114 | 446 class PgsqlStorageStorageTestCase(unittest.TestCase, StorageTests): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
447 |
219
bb7103da9879
Make the PostgreSQL ConnectionPool only once for all unit tests.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
448 dbpool = None |
bb7103da9879
Make the PostgreSQL ConnectionPool only once for all unit tests.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
449 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
450 def setUp(self): |
114 | 451 from idavoll.pgsql_storage import Storage |
204
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
452 from twisted.enterprise import adbapi |
219
bb7103da9879
Make the PostgreSQL ConnectionPool only once for all unit tests.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
453 if self.dbpool is None: |
bb7103da9879
Make the PostgreSQL ConnectionPool only once for all unit tests.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
454 self.__class__.dbpool = adbapi.ConnectionPool('pyPgSQL.PgSQL', |
204
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
455 database='pubsub_test', |
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
456 cp_reconnect=True, |
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
457 client_encoding='utf-8', |
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
458 ) |
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
459 self.s = Storage(self.dbpool) |
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
460 self.dbpool.start() |
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
461 d = self.dbpool.runInteraction(self.init) |
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
462 d.addCallback(lambda _: StorageTests.setUp(self)) |
117
bc872c33e88c
Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
114
diff
changeset
|
463 return d |
114 | 464 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
465 |
204
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
466 def tearDown(self): |
b4bf0a5ce50d
Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
467 return self.dbpool.runInteraction(self.cleandb) |
114 | 468 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
469 |
114 | 470 def init(self, cursor): |
471 self.cleandb(cursor) | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
472 cursor.execute("""INSERT INTO nodes |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
473 (node, node_type, persist_items) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
474 VALUES ('pre-existing', 'leaf', TRUE)""") |
114 | 475 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
|
476 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-reconfigured')""") |
131 | 477 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-purged')""") |
114 | 478 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
|
479 OWNER.userhost()) |
114 | 480 cursor.execute("""INSERT INTO affiliations |
481 (node_id, entity_id, affiliation) | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
482 SELECT node_id, entity_id, 'owner' |
114 | 483 FROM nodes, entities |
484 WHERE node='pre-existing' AND jid=%s""", | |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
485 OWNER.userhost()) |
114 | 486 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
|
487 SUBSCRIBER.userhost()) |
114 | 488 cursor.execute("""INSERT INTO subscriptions |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
489 (node_id, entity_id, resource, state) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
490 SELECT node_id, entity_id, %s, 'subscribed' |
114 | 491 FROM nodes, entities |
492 WHERE node='pre-existing' AND jid=%s""", | |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
493 (SUBSCRIBER.resource, |
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
494 SUBSCRIBER.userhost())) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
495 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
|
496 SUBSCRIBER_TO_BE_DELETED.userhost()) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
497 cursor.execute("""INSERT INTO subscriptions |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
498 (node_id, entity_id, resource, state) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
499 SELECT node_id, entity_id, %s, 'subscribed' |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
500 FROM nodes, entities |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
501 WHERE node='pre-existing' AND jid=%s""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
502 (SUBSCRIBER_TO_BE_DELETED.resource, |
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
503 SUBSCRIBER_TO_BE_DELETED.userhost())) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
504 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
|
505 SUBSCRIBER_PENDING.userhost()) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
506 cursor.execute("""INSERT INTO subscriptions |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
507 (node_id, entity_id, resource, state) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
508 SELECT node_id, entity_id, %s, 'pending' |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
509 FROM nodes, entities |
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
510 WHERE node='pre-existing' AND jid=%s""", |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
511 (SUBSCRIBER_PENDING.resource, |
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
512 SUBSCRIBER_PENDING.userhost())) |
131 | 513 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
|
514 PUBLISHER.userhost()) |
131 | 515 cursor.execute("""INSERT INTO items |
516 (node_id, publisher, item, data, date) | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
517 SELECT node_id, %s, 'to-be-deleted', %s, |
131 | 518 now() - interval '1 day' |
519 FROM nodes | |
520 WHERE node='pre-existing'""", | |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
521 (PUBLISHER.userhost(), |
131 | 522 ITEM_TO_BE_DELETED.toXml())) |
523 cursor.execute("""INSERT INTO items (node_id, publisher, item, data) | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
524 SELECT node_id, %s, 'to-be-deleted', %s |
131 | 525 FROM nodes |
526 WHERE node='to-be-purged'""", | |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
527 (PUBLISHER.userhost(), |
131 | 528 ITEM_TO_BE_DELETED.toXml())) |
529 cursor.execute("""INSERT INTO items (node_id, publisher, item, data) | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
204
diff
changeset
|
530 SELECT node_id, %s, 'current', %s |
131 | 531 FROM nodes |
532 WHERE node='pre-existing'""", | |
137
aca904a41a43
Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents:
131
diff
changeset
|
533 (PUBLISHER.userhost(), |
131 | 534 ITEM.toXml())) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
535 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
536 |
114 | 537 def cleandb(self, cursor): |
538 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
|
539 ('non-existing', 'pre-existing', 'to-be-deleted', |
131 | 540 'new 1', 'new 2', 'new 3', 'to-be-reconfigured', |
541 'to-be-purged')""") | |
114 | 542 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
|
543 OWNER.userhost()) |
114 | 544 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
|
545 SUBSCRIBER.userhost()) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
546 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
|
547 SUBSCRIBER_TO_BE_DELETED.userhost()) |
123
8f99b4f7aea2
Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents:
117
diff
changeset
|
548 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
|
549 SUBSCRIBER_PENDING.userhost()) |
131 | 550 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
|
551 PUBLISHER.userhost()) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
552 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
553 try: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
554 import pyPgSQL |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
555 pyPgSQL |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
556 except ImportError: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
557 PgsqlStorageStorageTestCase.skip = "pyPgSQL not available" |