db_tests.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import os
  2. import os.path
  3. _saveconfig = True
  4. import sys
  5. if 'darwin' in sys.platform:
  6. from pwman.ui.mac import PwmanCliMac as PwmanCli
  7. from pwman.ui.mac import PwmanCliMacNew as PwmanCliNew
  8. OSX = True
  9. elif 'win' in sys.platform:
  10. from pwman.ui.cli import PwmanCli
  11. from pwman.ui.win import PwmanCliWinNew as PwmanCliNew
  12. OSX = False
  13. else:
  14. from pwman.ui.cli import PwmanCli
  15. from pwman.ui.cli import PwmanCliNew
  16. OSX = False
  17. import pwman.util.config as config
  18. import pwman.data.factory
  19. from pwman.data.convertdb import PwmanConvertDB
  20. # set cls_timout to negative number (e.g. -1) to disable
  21. default_config = {'Global': {'umask': '0100', 'colors': 'yes',
  22. 'cls_timeout': '5'
  23. },
  24. 'Database': {'type': 'SQLite',
  25. 'filename': os.path.join("tests", "pwman.db")},
  26. 'Encryption': {'algorithm': 'AES'},
  27. 'Readline': {'history': os.path.join("tests",
  28. "history")}
  29. }
  30. config.set_defaults(default_config)
  31. import unittest
  32. class DBTests(unittest.TestCase):
  33. """test everything related to db"""
  34. def setUp(self):
  35. "test that the right db instance was created"
  36. dbver = 0.4
  37. self.dbtype = config.get_value("Database", "type")
  38. self.db = pwman.data.factory.create(self.dbtype, dbver)
  39. def test(self):
  40. self.assertTrue(True)
  41. def test_db_created(self):
  42. "test that the right db instance was created"
  43. # self.db = pwman.data.factory.create(dbtype, dbver)
  44. self.assertIn(self.dbtype, self.db.__class__.__name__)
  45. def test_db_opened(self):
  46. "db was successfuly opened"
  47. # it will have a file name associated
  48. self.assertTrue(hasattr(self.db, '_filename'))
  49. class CLITests(unittest.TestCase):
  50. """test command line functionallity"""
  51. def test(self):
  52. self.assertTrue(True)