From 52c6cb2aa9a015b9c7153b6cd0c4f12722594eb2 Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Wed, 1 Feb 2006 08:53:58 +0100 Subject: [PATCH] SQLite delitem implementation darcs-hash:20060201075358-86b55-07095573f5b30ad78829bdc933d7561c8a088294.gz --- jabber/storage.py | 12 ++++++++++-- run_test.py | 6 +++--- tests/test_storage.py | 19 +++++++++++-------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/jabber/storage.py b/jabber/storage.py index 2d7e663..8165627 100644 --- a/jabber/storage.py +++ b/jabber/storage.py @@ -60,7 +60,7 @@ class Storage(UserDict): if regexp.search(key)] def __delitem__(self, pk_tuple): -# print "Deleting " + "#".join(map(str, pk_tuple)) + #print "Deleting " + "#".join(map(str, pk_tuple)) del self._registered[str("#".join(map(str, pk_tuple)))] def get_spool_dir(self): @@ -276,4 +276,12 @@ class SQLiteStorage(Storage): def __delitem__(self, pk_tuple): Storage.__delitem__(self, pk_tuple) - # TODO + cursor = self.__connection.cursor() + cursor.execute(""" + delete from account where jid = ? and name = ? + """, + (pk_tuple[0], + pk_tuple[1])) + self.__connection.commit() + cursor.close() + diff --git a/run_test.py b/run_test.py index 5f54a60..19e1486 100644 --- a/run_test.py +++ b/run_test.py @@ -73,9 +73,9 @@ if __name__ == '__main__': # test_support.run_suite(mail_connection_suite) # test_support.run_suite(pop3_connection_suite) # test_support.run_suite(imap_connection_suite) - # test_support.run_suite(mc_factory_suite) - # test_support.run_suite(component_suite) - # test_support.run_suite(component2_suite) + #test_support.run_suite(mc_factory_suite) + #test_support.run_suite(component_suite) + #test_support.run_suite(component2_suite) #test_support.run_suite(storage_suite) #test_support.run_suite(sqlitestorage_suite) #test_support.run_suite(dbmstorage_suite) diff --git a/tests/test_storage.py b/tests/test_storage.py index 361ec91..9dd3c4b 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -34,14 +34,6 @@ class Storage_TestCase(unittest.TestCase): self.assertTrue(os.access(spool_dir, os.F_OK)) self.assertEquals(self._storage.spool_dir, spool_dir) os.removedirs(spool_dir) - -# TODO -class SQLiteStorage_TestCase(unittest.TestCase): - def setUp(self): - self._storage = SQLiteStorage() - - def tearDown(self): - pass class DBMStorage_TestCase(unittest.TestCase): def setUp(self): @@ -209,3 +201,14 @@ class SQLiteStorage_TestCase(DBMStorage_TestCase): self._account1) self.assertEquals(loaded_storage[("test@localhost", "account2")], self._account2) + + def test_del_sync_get(self): + self._storage[("test@localhost", "account1")] = self._account1 + self._storage[("test@localhost", "account2")] = self._account2 + del self._storage[("test@localhost", "account2")] + loaded_storage = SQLiteStorage(nb_pk_fields = 2, spool_dir = "./spool/test") + self.assertEquals(len(loaded_storage.keys()), + 1) + self.assertEquals(loaded_storage[("test@localhost", "account1")], + self._account1) +