test_complete_ui.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #============================================================================
  2. # This file is part of Pwman3.
  3. #
  4. # Pwman3 is free software; you can redistribute it 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-2014 Oz Nahum <nahumoz@gmail.com>
  18. #============================================================================
  19. # pylint: disable=I0011
  20. import pexpect
  21. import unittest
  22. import os
  23. OLD_DB_PATH = os.path.join(os.path.dirname(__file__), 'pwman.v0.0.8.db')
  24. NEW_DB_PATH = os.path.join(os.path.dirname(__file__), 'pwman.v0.0.8-newdb.db')
  25. _db_warn = ("\n*** WARNNING: You are using the old database format"
  26. " which is insecure."
  27. " Please upgrade to the new database "
  28. " format. Do note: support for this DB format will be dropped in"
  29. " v0.5. This database format is on hold. No bugs are fixead"
  30. " Check the help (pwman3 -h) or look at the manpage which"
  31. " explains how to proceed. ***")
  32. class Ferrum(unittest.TestCase):
  33. def test_db_warning(self):
  34. "when trying to run with old db, we should see warning"
  35. child = pexpect.spawn(os.path.join(os.path.dirname(__file__),
  36. '../../scripts/pwman3')+' -t -d '+OLD_DB_PATH)
  37. self.assertEqual(0, child.expect_exact(_db_warn, timeout=0.5))
  38. def test_run_convert(self):
  39. "invoke pwman with -k option to convert the old data"
  40. child = pexpect.spawn(os.path.join(os.path.dirname(__file__),
  41. '../../scripts/pwman3')+' -t -k -d '+OLD_DB_PATH)
  42. #child = pexpect.spawn('../../scripts/pwman3 -t -k -d '+OLD_DB_PATH)
  43. child.expect('[\s|\S]+Please enter your password:', timeout=0.5)
  44. self.assertEqual(6, child.sendline('12345'))
  45. rv = child.expect_exact(('\r\npwman successfully converted the old database '
  46. 'to the new format.\r\nPlease run `pwman3 -d %s` '
  47. 'to make sure your password and data are still '
  48. 'correct. If you are convinced that no harm was '
  49. 'done, update your config file to indicate the '
  50. 'permanent location to your new database. '
  51. 'If you found errors, please report a bug in Pwman '
  52. 'homepage in github. \r\n' % NEW_DB_PATH))
  53. self.assertEqual(0, rv)
  54. def suite():
  55. loader = unittest.TestLoader()
  56. suite = unittest.TestSuite()
  57. suite.addTest(loader.loadTestsFromTestCase(Ferrum))
  58. return suite
  59. if __name__ == '__main__':
  60. unittest.TextTestRunner(verbosity=2).run(suite())
  61. os.remove(NEW_DB_PATH)