test_sqlite.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #============================================================================
  2. # This file is part of Pwman3.
  3. #
  4. # Pwman3 is free software; you can redistribute iut and/or modify
  5. # it under the terms of the GNU General Public License, version 2
  6. # as published by the Free Software Foundation;
  7. #
  8. # Pwman3 is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with Pwman3; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. #============================================================================
  17. # Copyright (C) 2012 Oz Nahum Tiram <nahumoz@gmail.com>
  18. #============================================================================
  19. import os
  20. import unittest
  21. from pwman.data.drivers.sqlite import SQLite
  22. class TestSQLite(unittest.TestCase):
  23. def setUp(self):
  24. self.db = SQLite('test.db')
  25. self.db._open()
  26. def test_1_create_tables(self):
  27. self.db._create_tables()
  28. self.db._con.commit()
  29. # the method _open calls _create_tables
  30. self.db.save_crypto_info("foo", "bar")
  31. self.db._create_tables()
  32. def test_1a_create_tables(self):
  33. self.db._create_tables()
  34. def test_2_crypto_info(self):
  35. self.db._create_tables()
  36. self.db.save_crypto_info("foo", "bar")
  37. f = self.db.fetch_crypto_info()
  38. self.assertListEqual([u'foo', u'bar'], list(f))
  39. def test_3_add_node(self):
  40. node = ("alice", "secret", "wonderland.com", "a really great place")
  41. self.db.add_node(node)
  42. rv = self.db._cur.execute("select * from node")
  43. self.assertIn('alice', rv.fetchone())
  44. def tearDown(self):
  45. self.db.close()
  46. if __name__ == '__main__':
  47. try:
  48. unittest.main(verbosity=2)
  49. except SystemExit:
  50. os.remove('test.db')