test_tools.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from pwman.data import factory
  2. from pwman.util import config
  3. from pwman import which, default_config
  4. from pwman.ui import get_ui_platform
  5. import os
  6. import os.path
  7. import sys
  8. from pwman.util.callback import Callback
  9. PwmanCliNew, OSX = get_ui_platform(sys.platform)
  10. class DummyCallback(Callback):
  11. def getsecret(self, question):
  12. return u'12345'
  13. def getnewsecret(self, question):
  14. return u'12345'
  15. class DummyCallback2(Callback):
  16. def getinput(self, question):
  17. return u'newsecret'
  18. def getsecret(self, question):
  19. return u'wrong'
  20. def getnewsecret(self, question):
  21. return u'newsecret'
  22. class DummyCallback3(Callback):
  23. def getinput(self, question):
  24. return u'newsecret'
  25. def getsecret(self, question):
  26. return u'12345'
  27. def getnewsecret(self, question):
  28. return u'newsecret'
  29. class DummyCallback4(Callback):
  30. def getinput(self, question):
  31. return u'newsecret'
  32. def getsecret(self, question):
  33. return u'newsecret'
  34. def getnewsecret(self, question):
  35. return u'newsecret'
  36. class SetupTester(object):
  37. def __init__(self, dbver=None, filename=None):
  38. config.set_defaults(default_config)
  39. if not OSX:
  40. self.xselpath = which("xsel")
  41. config.set_value("Global", "xsel", self.xselpath)
  42. else:
  43. self.xselpath = "xsel"
  44. self.dbver = dbver
  45. self.filename = filename
  46. def clean(self):
  47. if os.path.exists(config.get_value('Database', 'filename')):
  48. os.remove(config.get_value('Database', 'filename'))
  49. if os.path.exists(os.path.join(os.path.dirname(__file__),
  50. 'testing_config')):
  51. os.remove(os.path.join(os.path.dirname(__file__),
  52. 'testing_config'))
  53. def create(self):
  54. dbtype = config.get_value("Database", "type")
  55. if self.filename:
  56. db = factory.create(dbtype, self.dbver, self.filename)
  57. else:
  58. db = factory.create(dbtype, self.dbver)
  59. self.cli = PwmanCliNew(db, self.xselpath, DummyCallback)