test_sqlite.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. from pwman.data.nodes import Node
  23. class TestSQLite(unittest.TestCase):
  24. def setUp(self):
  25. self.db = SQLite('test.db')
  26. self.db._open()
  27. def test_1_create_tables(self):
  28. self.db._create_tables()
  29. self.db._con.commit()
  30. # the method _open calls _create_tables
  31. self.db.save_crypto_info("foo", "bar")
  32. self.db._create_tables()
  33. def test_1a_create_tables(self):
  34. self.db._create_tables()
  35. def test_2_crypto_info(self):
  36. self.db._create_tables()
  37. self.db.save_crypto_info("foo", "bar")
  38. f = self.db.fetch_crypto_info()
  39. self.assertListEqual([u'foo', u'bar'], list(f))
  40. def test_3_add_node(self):
  41. node = Node(clear_text=True,
  42. **{'username': u"alice", 'password': u"secret",
  43. 'url': u"wonderland.com",
  44. 'notes': u"a really great place",
  45. 'tags': [u'foo', u'bar']})
  46. self.db.add_node(node)
  47. rv = self.db._cur.execute("select * from node")
  48. self.assertIn('alice', rv.fetchone())
  49. def tearDown(self):
  50. self.db.close()
  51. if __name__ == '__main__':
  52. try:
  53. unittest.main(verbosity=2)
  54. except SystemExit:
  55. os.remove('test.db')