test_complete_ui.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. from __future__ import print_function
  21. import pexpect
  22. import unittest
  23. import os
  24. import shutil
  25. class Ferrum(unittest.TestCase):
  26. def clean_files(self):
  27. lfile = 'convert-test.log'
  28. with open(lfile) as l:
  29. lines = l.readlines()
  30. orig = lines[0].split(':')[-1].strip()
  31. backup = lines[1].split()[-1].strip()
  32. shutil.copy(backup, orig)
  33. # do some cleaning
  34. os.remove(lfile)
  35. os.remove('test-chg_passwd.log')
  36. os.remove(backup)
  37. def test_b_run_convert(self):
  38. "invoke pwman with -k option to convert the old data"
  39. lfile = 'convert-test.log'
  40. logfile = open(lfile, 'wb')
  41. cmd = (os.path.join(os.path.dirname(__file__), '../scripts/pwman3'
  42. ) + ' -k -e Blowfish -d ')
  43. child = pexpect.spawn(cmd, logfile=logfile)
  44. child.expect('[\s|\S]+Please enter your password:', timeout=10)
  45. self.assertEqual(6, child.sendline('12345'))
  46. rv = child.expect('pwman successfully converted the old database')
  47. self.assertEqual(0, rv)
  48. # if successfully converted, reset the converted database
  49. # todo - add test to run auto_convert
  50. def test_c_change_pass(self):
  51. lfile = 'test-chg_passwd.log'
  52. logfile = open(lfile, 'wb')
  53. child = pexpect.spawn(os.path.join(os.path.dirname(__file__),
  54. '../../scripts/pwman3') +
  55. ' -d ', logfile=logfile)
  56. child.sendline('passwd')
  57. child.expect("Please enter your current password:")
  58. child.sendline('12345')
  59. child.sendline('foobar')
  60. child.sendline('foobar')
  61. self.clean_files()
  62. def suite():
  63. loader = unittest.TestLoader()
  64. suite = unittest.TestSuite()
  65. suite.addTest(loader.loadTestsFromTestCase(Ferrum))
  66. return suite
  67. if __name__ == '__main__':
  68. unittest.TextTestRunner(verbosity=2).run(suite())