comparison idavoll/test/test_storage.py @ 117:bc872c33e88c

Added test cases for a few of the Node methods. Clean up more in the pgsql database.
author Ralph Meijer <ralphm@ik.nu>
date Fri, 08 Apr 2005 21:00:22 +0000
parents e7cfe05bc1d2
children 8f99b4f7aea2
comparison
equal deleted inserted replaced
116:06bab3d2490d 117:bc872c33e88c
6 6
7 OWNER = jid.JID('owner@example.com') 7 OWNER = jid.JID('owner@example.com')
8 SUBSCRIBER = jid.JID('subscriber@example.com/Home') 8 SUBSCRIBER = jid.JID('subscriber@example.com/Home')
9 9
10 class StorageTests: 10 class StorageTests:
11
12 def _assignTestNode(self, node):
13 self.node = node
14
15 def setUpClass(self):
16 d = self.s.get_node('pre-existing')
17 d.addCallback(self._assignTestNode)
18 return d
11 19
12 def testGetNode(self): 20 def testGetNode(self):
13 return self.s.get_node('pre-existing') 21 return self.s.get_node('pre-existing')
14 22
15 def testGetNonExistingNode(self): 23 def testGetNonExistingNode(self):
67 75
68 d = self.s.get_subscriptions(SUBSCRIBER) 76 d = self.s.get_subscriptions(SUBSCRIBER)
69 d.addCallback(cb) 77 d.addCallback(cb)
70 return d 78 return d
71 79
80 # Node tests
81
82 def testGetType(self):
83 assertEqual(self.node.get_type(), 'leaf')
84
85 def testGetConfiguration(self):
86 config = self.node.get_configuration()
87 assertIn('pubsub#persist_items', config.iterkeys())
88 assertIn('pubsub#deliver_payloads', config.iterkeys())
89 assertEqual(config['pubsub#persist_items'], True)
90 assertEqual(config['pubsub#deliver_payloads'], True)
91
92 def testGetMetaData(self):
93 meta_data = self.node.get_meta_data()
94 for key, value in self.node.get_configuration().iteritems():
95 assertIn(key, meta_data.iterkeys())
96 assertEqual(value, meta_data[key])
97 assertIn('pubsub#node_type', meta_data.iterkeys())
98 assertEqual(meta_data['pubsub#node_type'], 'leaf')
99
100
72 class MemoryStorageStorageTestCase(unittest.TestCase, StorageTests): 101 class MemoryStorageStorageTestCase(unittest.TestCase, StorageTests):
73 102
74 def setUpClass(self): 103 def setUpClass(self):
75 from idavoll.memory_storage import Storage, LeafNode, Subscription 104 from idavoll.memory_storage import Storage, LeafNode, Subscription, \
105 default_config
76 self.s = Storage() 106 self.s = Storage()
77 self.s._nodes['pre-existing'] = LeafNode('pre-existing', OWNER, None) 107 self.s._nodes['pre-existing'] = LeafNode('pre-existing', OWNER,
108 default_config)
78 self.s._nodes['to-be-deleted'] = LeafNode('to-be-deleted', OWNER, None) 109 self.s._nodes['to-be-deleted'] = LeafNode('to-be-deleted', OWNER, None)
79 self.s._nodes['pre-existing']._subscriptions[SUBSCRIBER.full()] = \ 110 self.s._nodes['pre-existing']._subscriptions[SUBSCRIBER.full()] = \
80 Subscription('subscribed') 111 Subscription('subscribed')
81 112
113 return StorageTests.setUpClass(self)
114
82 class PgsqlStorageStorageTestCase(unittest.TestCase, StorageTests): 115 class PgsqlStorageStorageTestCase(unittest.TestCase, StorageTests):
116 def _callSuperSetUpClass(self, void):
117 return StorageTests.setUpClass(self)
118
83 def setUpClass(self): 119 def setUpClass(self):
84 from idavoll.pgsql_storage import Storage 120 from idavoll.pgsql_storage import Storage
85 self.s = Storage('ralphm', 'pubsub_test') 121 self.s = Storage('ralphm', 'pubsub_test')
86 self.s._dbpool.start() 122 self.s._dbpool.start()
87 return self.s._dbpool.runInteraction(self.init) 123 d = self.s._dbpool.runInteraction(self.init)
124 d.addCallback(self._callSuperSetUpClass)
125 return d
88 126
89 def tearDownClass(self): 127 def tearDownClass(self):
90 return self.s._dbpool.runInteraction(self.cleandb) 128 return self.s._dbpool.runInteraction(self.cleandb)
91 129
92 def init(self, cursor): 130 def init(self, cursor):
111 (SUBSCRIBER.resource.encode('utf-8'), 149 (SUBSCRIBER.resource.encode('utf-8'),
112 SUBSCRIBER.userhost().encode('utf-8'))) 150 SUBSCRIBER.userhost().encode('utf-8')))
113 151
114 def cleandb(self, cursor): 152 def cleandb(self, cursor):
115 cursor.execute("""DELETE FROM nodes WHERE node in 153 cursor.execute("""DELETE FROM nodes WHERE node in
116 ('pre-existing', 'new 1', 'new 2', 'new 3')""") 154 ('non-existing', 'pre-existing', 'to-be-deleted',
155 'new 1', 'new 2', 'new 3')""")
117 cursor.execute("""DELETE FROM entities WHERE jid=%s""", 156 cursor.execute("""DELETE FROM entities WHERE jid=%s""",
118 OWNER.userhost().encode('utf-8')) 157 OWNER.userhost().encode('utf-8'))
119 cursor.execute("""DELETE FROM entities WHERE jid=%s""", 158 cursor.execute("""DELETE FROM entities WHERE jid=%s""",
120 SUBSCRIBER.userhost().encode('utf-8')) 159 SUBSCRIBER.userhost().encode('utf-8'))