annotate idavoll/test/test_storage.py @ 202:77c61e2b8c75

Use `domish.Element`s to represent items, instead of serialized XML.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 25 Jun 2008 12:27:55 +0000
parents e404775b12df
children b4bf0a5ce50d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 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
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8 from twisted.trial import unittest
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17 OWNER = jid.JID('owner@example.com')
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
22 PUBLISHER = jid.JID('publisher@example.com')
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
23 ITEM = domish.Element((pubsub.NS_PUBSUB, 'item'), pubsub.NS_PUBSUB)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
24 ITEM['id'] = 'current'
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
25 ITEM.addElement(('testns', 'test'), content=u'Test \u2083 item')
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
26 ITEM_NEW = domish.Element((pubsub.NS_PUBSUB, 'item'), pubsub.NS_PUBSUB)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
27 ITEM_NEW['id'] = 'new'
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
28 ITEM_NEW.addElement(('testns', 'test'), content=u'Test \u2083 item')
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
29 ITEM_UPDATED = domish.Element((pubsub.NS_PUBSUB, 'item'), pubsub.NS_PUBSUB)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
30 ITEM_UPDATED['id'] = 'current'
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
31 ITEM_UPDATED.addElement(('testns', 'test'), content=u'Test \u2084 item')
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
32 ITEM_TO_BE_DELETED = domish.Element((pubsub.NS_PUBSUB, 'item'),
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
33 pubsub.NS_PUBSUB)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
34 ITEM_TO_BE_DELETED['id'] = 'to-be-deleted'
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
35 ITEM_TO_BE_DELETED.addElement(('testns', 'test'), content=u'Test \u2083 item')
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
42
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
43
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
44 class StorageTests:
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
45
117
bc872c33e88c Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 114
diff changeset
46 def _assignTestNode(self, node):
bc872c33e88c Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 114
diff changeset
47 self.node = node
bc872c33e88c Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 114
diff changeset
48
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
49
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
50 def setUp(self):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
51 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
52 d.addCallback(self._assignTestNode)
bc872c33e88c Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 114
diff changeset
53 return d
bc872c33e88c Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 114
diff changeset
54
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
55
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
56 def test_getNode(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
57 return self.s.getNode('pre-existing')
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
58
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
59
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
60 def test_getNonExistingNode(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
61 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
62 self.assertFailure(d, error.NodeNotFound)
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
63 return d
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
64
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
65
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
66 def test_getNodeIDs(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
67 def cb(nodeIdentifiers):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
68 self.assertIn('pre-existing', nodeIdentifiers)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
69 self.assertNotIn('non-existing', nodeIdentifiers)
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
70
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
71 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
72
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
73
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
74 def test_createExistingNode(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
75 d = self.s.createNode('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
76 self.assertFailure(d, error.NodeExists)
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
77 return d
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
78
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
79
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
80 def test_createNode(self):
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
81 def cb(void):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
82 d = self.s.getNode('new 1')
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
83 return d
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
84
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
85 d = self.s.createNode('new 1', OWNER)
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
86 d.addCallback(cb)
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
87 return d
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
88
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
89
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
90 def test_deleteNonExistingNode(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
91 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
92 self.assertFailure(d, error.NodeNotFound)
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
93 return d
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
94
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
95
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
96 def test_deleteNode(self):
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
97 def cb(void):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
98 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
99 self.assertFailure(d, error.NodeNotFound)
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
100 return d
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
101
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
102 d = self.s.deleteNode('to-be-deleted')
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
103 d.addCallback(cb)
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
104 return d
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
105
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
106
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
107 def test_getAffiliations(self):
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
108 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
109 self.assertIn(('pre-existing', 'owner'), affiliations)
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
110
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
111 d = self.s.getAffiliations(OWNER)
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
112 d.addCallback(cb)
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
113 return d
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
114
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
115
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
116 def test_getSubscriptions(self):
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
117 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
118 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
119
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
120 d = self.s.getSubscriptions(SUBSCRIBER)
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
121 d.addCallback(cb)
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
122 return d
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
123
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
124
117
bc872c33e88c Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 114
diff changeset
125 # Node tests
bc872c33e88c Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 114
diff changeset
126
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
127 def test_getType(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
128 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
129
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
130
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
131 def test_getConfiguration(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
132 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
133 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
134 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
135 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
136 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
137
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
138
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
139 def test_setConfiguration(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
140 def getConfig(node):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
141 d = node.setConfiguration({'pubsub#persist_items': False})
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
142 d.addCallback(lambda _: node)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
143 return d
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
144
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
145 def checkObjectConfig(node):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
146 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
147 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
148
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
149 def getNode(void):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
150 return self.s.getNode('to-be-reconfigured')
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
151
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
152 def checkStorageConfig(node):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
153 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
154 self.assertEqual(config['pubsub#persist_items'], False)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
155
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
156 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
157 d.addCallback(getConfig)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
158 d.addCallback(checkObjectConfig)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
159 d.addCallback(getNode)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
160 d.addCallback(checkStorageConfig)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
161 return d
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
162
117
bc872c33e88c Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 114
diff changeset
163
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
164 def test_getMetaData(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
165 metaData = self.node.getMetaData()
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
166 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
167 self.assertIn(key, metaData.iterkeys())
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
168 self.assertEqual(value, metaData[key])
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
169 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
170 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
171
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
172
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
173 def test_getAffiliation(self):
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
174 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
175 self.assertEqual(affiliation, 'owner')
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
176
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
177 d = self.node.getAffiliation(OWNER)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
178 d.addCallback(cb)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
179 return d
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
180
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
181
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
182 def test_getNonExistingAffiliation(self):
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
183 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
184 self.assertEqual(affiliation, None)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
185
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
186 d = self.node.getAffiliation(SUBSCRIBER)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
187 d.addCallback(cb)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
188 return d
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
189
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
190
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
191 def test_addSubscription(self):
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
192 def cb1(void):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
193 return self.node.getSubscription(SUBSCRIBER_NEW)
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 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
196 self.assertEqual(state, 'pending')
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
197
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
198 d = self.node.addSubscription(SUBSCRIBER_NEW, 'pending')
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
199 d.addCallback(cb1)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
200 d.addCallback(cb2)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
201 return d
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
202
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
203
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
204 def test_addExistingSubscription(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
205 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
206 self.assertFailure(d, error.SubscriptionExists)
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
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
209
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
210 def test_getSubscription(self):
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
211 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
212 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
213 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
214 self.assertEquals(subscriptions[2][1], None)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
215
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
216 d = defer.DeferredList([self.node.getSubscription(SUBSCRIBER),
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
217 self.node.getSubscription(SUBSCRIBER_PENDING),
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
218 self.node.getSubscription(OWNER)])
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
219 d.addCallback(cb)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
220 return d
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
221
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
222
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
223 def test_removeSubscription(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
224 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
225
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
226
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
227 def test_removeNonExistingSubscription(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
228 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
229 self.assertFailure(d, error.NotSubscribed)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
230 return d
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
231
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
232
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
233 def test_getSubscribers(self):
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
234 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
235 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
236 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
237 self.assertNotIn(OWNER, subscribers)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
238
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
239 d = self.node.getSubscribers()
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
240 d.addCallback(cb)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
241 return d
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
242
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
243
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
244 def test_isSubscriber(self):
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
245 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
246 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
247 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
248 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
249 self.assertEquals(subscribed[3][1], False)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
250
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
251 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
252 self.node.isSubscribed(SUBSCRIBER.userhostJID()),
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
253 self.node.isSubscribed(SUBSCRIBER_PENDING),
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
254 self.node.isSubscribed(OWNER)])
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
255 d.addCallback(cb)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
256 return d
117
bc872c33e88c Added test cases for a few of the Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 114
diff changeset
257
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
258
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
259 def test_storeItems(self):
138
635e433810ef Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents: 137
diff changeset
260 def cb1(void):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
261 return self.node.getItemsById(['new'])
138
635e433810ef Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents: 137
diff changeset
262
635e433810ef Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents: 137
diff changeset
263 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
264 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
265
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
266 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
267 d.addCallback(cb1)
635e433810ef Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents: 137
diff changeset
268 d.addCallback(cb2)
635e433810ef Actually test whether the item was indeed stored.
Ralph Meijer <ralphm@ik.nu>
parents: 137
diff changeset
269 return d
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
270
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
271
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
272 def test_storeUpdatedItems(self):
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
273 def cb1(void):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
274 return self.node.getItemsById(['current'])
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
275
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
276 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
277 self.assertEqual(ITEM_UPDATED.toXml(), result[0].toXml())
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
278
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
279 d = self.node.storeItems([ITEM_UPDATED], PUBLISHER)
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
280 d.addCallback(cb1)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
281 d.addCallback(cb2)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
282 return d
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
283
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
284
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
285 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
286 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
287 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
288 return self.node.getItemsById(['to-be-deleted'])
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
289
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
290 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
291 self.assertEqual(0, len(result))
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
292
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
293 d = self.node.removeItems(['to-be-deleted'])
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
294 d.addCallback(cb1)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
295 d.addCallback(cb2)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
296 return d
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
297
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
298
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
299 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
300 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
301 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
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.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
304 d.addCallback(cb)
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
305 return d
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
306
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
307
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
308 def test_getItems(self):
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
309 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
310 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
311 self.assertIn(ITEM.toXml(), items)
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
312
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
313 d = self.node.getItems()
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
314 d.addCallback(cb)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
315 return d
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
316
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
317
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
318 def test_lastItem(self):
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
319 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
320 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
321 self.assertEqual(ITEM.toXml(), result[0].toXml())
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
322
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
323 d = self.node.getItems(1)
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
324 d.addCallback(cb)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
325 return d
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
326
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
327
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
328 def test_getItemsById(self):
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
329 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
330 self.assertEqual(1, len(result))
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
331
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
332 d = self.node.getItemsById(['current'])
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
333 d.addCallback(cb)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
334 return d
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
335
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
336
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
337 def test_getNonExistingItemsById(self):
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
338 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
339 self.assertEqual(0, len(result))
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
340
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
341 d = self.node.getItemsById(['non-existing'])
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
342 d.addCallback(cb)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
343 return d
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
344
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
345
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
346 def test_purge(self):
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
347 def cb1(node):
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
348 d = node.purge()
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
349 d.addCallback(lambda _: node)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
350 return d
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
351
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
352 def cb2(node):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
353 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
354
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
355 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
356 self.assertEqual([], result)
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
357
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
358 d = self.s.getNode('to-be-purged')
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
359 d.addCallback(cb1)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
360 d.addCallback(cb2)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
361 d.addCallback(cb3)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
362 return d
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
363
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
364
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
365 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
366 def cb1(node):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
367 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
368
f393bccec4bc Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents: 142
diff changeset
369 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
370 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
371 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
372
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
373 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
374 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
375 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
376 return d
f393bccec4bc Add get_affiliations to Node class in storage facilities in preparation of
Ralph Meijer <ralphm@ik.nu>
parents: 142
diff changeset
377
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
378
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
379
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
380 class MemoryStorageStorageTestCase(unittest.TestCase, StorageTests):
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
381
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
382 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
383 from idavoll.memory_storage import Storage, PublishedItem, LeafNode
77c61e2b8c75 Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
384 from idavoll.memory_storage import Subscription, defaultConfig
77c61e2b8c75 Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
385
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
386 self.s = Storage()
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
387 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
388 LeafNode('pre-existing', OWNER, defaultConfig)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
389 self.s._nodes['to-be-deleted'] = \
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
390 LeafNode('to-be-deleted', OWNER, None)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
391 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
392 LeafNode('to-be-reconfigured', OWNER, defaultConfig)
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
393 self.s._nodes['to-be-purged'] = \
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
394 LeafNode('to-be-purged', OWNER, None)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
395
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
396 subscriptions = self.s._nodes['pre-existing']._subscriptions
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
397 subscriptions[SUBSCRIBER.full()] = Subscription('subscribed')
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
398 subscriptions[SUBSCRIBER_TO_BE_DELETED.full()] = \
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
399 Subscription('subscribed')
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
400 subscriptions[SUBSCRIBER_PENDING.full()] = \
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
401 Subscription('pending')
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
402
202
77c61e2b8c75 Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
403 item = PublishedItem(ITEM_TO_BE_DELETED, PUBLISHER)
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
404 self.s._nodes['pre-existing']._items['to-be-deleted'] = item
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
405 self.s._nodes['pre-existing']._itemlist.append(item)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
406 self.s._nodes['to-be-purged']._items['to-be-deleted'] = item
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
407 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
408 item = PublishedItem(ITEM, PUBLISHER)
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
409 self.s._nodes['pre-existing']._items['current'] = item
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
410 self.s._nodes['pre-existing']._itemlist.append(item)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
411
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
412 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
413
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
414
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
415
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
416 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
417 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
418 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
419
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
420
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
421 def setUp(self):
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
422 from idavoll.pgsql_storage import Storage
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
423 self.s = Storage('ralphm', 'pubsub_test')
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
424 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
425 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
426 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
427 return d
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
428
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
429
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
430 def tearDownClass(self):
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
431 #return self.s._dbpool.runInteraction(self.cleandb)
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
432 pass
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
433
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
434
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
435 def init(self, cursor):
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
436 self.cleandb(cursor)
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
437 cursor.execute("""INSERT INTO nodes (node) VALUES ('pre-existing')""")
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
438 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
439 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-reconfigured')""")
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
440 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-purged')""")
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
441 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
442 OWNER.userhost())
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
443 cursor.execute("""INSERT INTO affiliations
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
444 (node_id, entity_id, affiliation)
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
445 SELECT nodes.id, entities.id, 'owner'
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
446 FROM nodes, entities
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
447 WHERE node='pre-existing' AND jid=%s""",
137
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
448 OWNER.userhost())
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
449 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
450 SUBSCRIBER.userhost())
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
451 cursor.execute("""INSERT INTO subscriptions
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
452 (node_id, entity_id, resource, subscription)
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
453 SELECT nodes.id, entities.id, %s, 'subscribed'
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
454 FROM nodes, entities
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
455 WHERE node='pre-existing' AND jid=%s""",
137
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
456 (SUBSCRIBER.resource,
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
457 SUBSCRIBER.userhost()))
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
458 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""",
137
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
459 SUBSCRIBER_TO_BE_DELETED.userhost())
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
460 cursor.execute("""INSERT INTO subscriptions
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
461 (node_id, entity_id, resource, subscription)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
462 SELECT nodes.id, entities.id, %s, 'subscribed'
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
463 FROM nodes, entities
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
464 WHERE node='pre-existing' AND jid=%s""",
137
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
465 (SUBSCRIBER_TO_BE_DELETED.resource,
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
466 SUBSCRIBER_TO_BE_DELETED.userhost()))
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
467 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
468 SUBSCRIBER_PENDING.userhost())
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
469 cursor.execute("""INSERT INTO subscriptions
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
470 (node_id, entity_id, resource, subscription)
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
471 SELECT nodes.id, entities.id, %s, 'pending'
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
472 FROM nodes, entities
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
473 WHERE node='pre-existing' AND jid=%s""",
137
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
474 (SUBSCRIBER_PENDING.resource,
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
475 SUBSCRIBER_PENDING.userhost()))
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
476 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
477 PUBLISHER.userhost())
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
478 cursor.execute("""INSERT INTO items
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
479 (node_id, publisher, item, data, date)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
480 SELECT nodes.id, %s, 'to-be-deleted', %s,
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
481 now() - interval '1 day'
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
482 FROM nodes
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
483 WHERE node='pre-existing'""",
137
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
484 (PUBLISHER.userhost(),
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
485 ITEM_TO_BE_DELETED.toXml()))
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
486 cursor.execute("""INSERT INTO items (node_id, publisher, item, data)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
487 SELECT nodes.id, %s, 'to-be-deleted', %s
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
488 FROM nodes
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
489 WHERE node='to-be-purged'""",
137
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
490 (PUBLISHER.userhost(),
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
491 ITEM_TO_BE_DELETED.toXml()))
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
492 cursor.execute("""INSERT INTO items (node_id, publisher, item, data)
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
493 SELECT nodes.id, %s, 'current', %s
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
494 FROM nodes
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
495 WHERE node='pre-existing'""",
137
aca904a41a43 Discover client_encoding parameter to pyPgSQL.
Ralph Meijer <ralphm@ik.nu>
parents: 131
diff changeset
496 (PUBLISHER.userhost(),
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
497 ITEM.toXml()))
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
498
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
499
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
500 def cleandb(self, cursor):
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
501 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
502 ('non-existing', 'pre-existing', 'to-be-deleted',
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
503 'new 1', 'new 2', 'new 3', 'to-be-reconfigured',
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
504 'to-be-purged')""")
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
505 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
506 OWNER.userhost())
114
e7cfe05bc1d2 Initial revision.
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
507 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
508 SUBSCRIBER.userhost())
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
509 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
510 SUBSCRIBER_TO_BE_DELETED.userhost())
123
8f99b4f7aea2 Add tests for all Node methods.
Ralph Meijer <ralphm@ik.nu>
parents: 117
diff changeset
511 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
512 SUBSCRIBER_PENDING.userhost())
131
fe8cb99363ff Add test cases for LeafNodes.
Ralph Meijer <ralphm@ik.nu>
parents: 123
diff changeset
513 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
514 PUBLISHER.userhost())
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
515
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
516 try:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
517 import pyPgSQL
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
518 pyPgSQL
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
519 except ImportError:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
520 PgsqlStorageStorageTestCase.skip = "pyPgSQL not available"