test_complete_ui.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. @unittest.skip("obsolete")
  38. def test_b_run_convert(self):
  39. "invoke pwman with -k option to convert the old data"
  40. lfile = 'convert-test.log'
  41. logfile = open(lfile, 'wb')
  42. cmd = (os.path.join(os.path.dirname(__file__), '../scripts/pwman3'
  43. ) + ' -k -e Blowfish -d ')
  44. child = pexpect.spawn(cmd, logfile=logfile)
  45. child.expect('[\s|\S]+Please enter your password:', timeout=10)
  46. self.assertEqual(6, child.sendline('12345'))
  47. rv = child.expect('pwman successfully converted the old database')
  48. self.assertEqual(0, rv)
  49. # if successfully converted, reset the converted database
  50. # todo - add test to run auto_convert
  51. def test_c_change_pass(self):
  52. lfile = 'test-chg_passwd.log'
  53. logfile = open(lfile, 'wb')
  54. child = pexpect.spawn(os.path.join(os.path.dirname(__file__),
  55. '../scripts/pwman3') +
  56. ' -d ', logfile=logfile)
  57. child.sendline('passwd')
  58. child.expect("Please enter your current password:")
  59. child.sendline('12345')
  60. child.sendline('foobar')
  61. child.sendline('foobar')
  62. self.clean_files()
  63. def suite():
  64. loader = unittest.TestLoader()
  65. suite = unittest.TestSuite()
  66. suite.addTest(loader.loadTestsFromTestCase(Ferrum))
  67. return suite
  68. if __name__ == '__main__':
  69. unittest.TextTestRunner(verbosity=2).run(suite())