test_init.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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) 2014 Oz Nahum Tiram <nahumoz@gmail.com>
  18. # ============================================================================
  19. import unittest
  20. from collections import namedtuple
  21. import os
  22. import os.path
  23. from pwman import set_xsel
  24. from pwman import (get_conf, get_conf_options)
  25. dummyfile = """
  26. [Encryption]
  27. [Readline]
  28. [Global]
  29. xsel = /usr/bin/xsel
  30. colors = yes
  31. cls_timeout = 5
  32. [Database]
  33. """
  34. testdb = os.path.join(os.path.dirname(__file__), "test.pwman.db")
  35. with open('dummy.cfg', 'w') as d:
  36. d.write(dummyfile)
  37. class TestInit(unittest.TestCase):
  38. def test_set_xsel(self):
  39. Args = namedtuple('args', 'cfile, dbase, algo')
  40. args = Args(cfile='dummy.cfg', dbase='dummy.db', algo='AES')
  41. xsel, dbtype, configp = get_conf_options(args, 'True')
  42. set_xsel(configp, False)
  43. set_xsel(configp, True)
  44. def test_get_conf_file(self):
  45. Args = namedtuple('args', 'cfile')
  46. args = Args(cfile='dummy.cfg')
  47. get_conf(args)
  48. def test_get_conf_options(self):
  49. Args = namedtuple('args', 'cfile, dbase, algo')
  50. args = Args(cfile='dummy.cfg', dbase='dummy.db', algo='AES')
  51. self.assertRaises(Exception, get_conf_options, (args, 'False'))
  52. xsel, dbtype, configp = get_conf_options(args, 'True')
  53. self.assertEqual(dbtype, 'SQLite')
  54. # def test_umask(self):
  55. # Args = namedtuple('args', 'cfile, dbase, algo')
  56. # args = Args(cfile='dummy.cfg', dbase='dummy.db', algo='AES')
  57. # xsel, dbtype, configp = get_conf_options(args, 'True')
  58. if __name__ == '__main__':
  59. try:
  60. unittest.main(verbosity=2, failfast=True)
  61. except SystemExit:
  62. if os.path.exists(testdb):
  63. os.remove(testdb)