db_tests.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 test(self):
  35. self.assertTrue(True)
  36. def test_db_created(self):
  37. "test that the right db instance was created"
  38. dbver = 0.4
  39. dbtype = config.get_value("Database", "type")
  40. self.db = pwman.data.factory.create(dbtype, dbver)
  41. self.assertIn(dbtype, self.db.__class__.__name__)
  42. def db_opened(self):
  43. """
  44. if the db was successfuly opened
  45. it will have a file name associated
  46. """
  47. self.assertTrue(hasattr(self.db, '_filename'))
  48. class CLITests(unittest.TestCase):
  49. """test command line functionallity"""
  50. def test(self):
  51. self.assertTrue(True)