test_complete_ui.py 3.1 KB

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