test_init.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. class TestInit(unittest.TestCase):
  36. @classmethod
  37. def setUpClass(cls):
  38. with open('dummy.cfg', 'w') as d:
  39. d.write(dummyfile)
  40. @classmethod
  41. def tearDownClass(cls):
  42. for item in ('dummy.cfg', testdb):
  43. try:
  44. os.unlink(item)
  45. except OSError:
  46. continue
  47. def test_set_xsel(self):
  48. Args = namedtuple('args', 'cfile, dbase, algo')
  49. args = Args(cfile='dummy.cfg', dbase='dummy.db', algo='AES')
  50. xsel, dbtype, configp = get_conf_options(args, 'True')
  51. set_xsel(configp, False)
  52. set_xsel(configp, True)
  53. def test_get_conf_file(self):
  54. Args = namedtuple('args', 'cfile')
  55. args = Args(cfile='dummy.cfg')
  56. get_conf(args)
  57. def test_get_conf_options(self):
  58. Args = namedtuple('args', 'cfile, dbase, algo')
  59. args = Args(cfile='dummy.cfg', dbase='dummy.db', algo='AES')
  60. self.assertRaises(Exception, get_conf_options, (args, 'False'))
  61. xsel, dbtype, configp = get_conf_options(args, 'True')
  62. self.assertEqual(dbtype, 'SQLite')
  63. # def test_umask(self):
  64. # Args = namedtuple('args', 'cfile, dbase, algo')
  65. # args = Args(cfile='dummy.cfg', dbase='dummy.db', algo='AES')
  66. # xsel, dbtype, configp = get_conf_options(args, 'True')
  67. if __name__ == '__main__':
  68. try:
  69. unittest.main(verbosity=2, failfast=True)
  70. except SystemExit:
  71. if os.path.exists(testdb):
  72. os.remove(testdb)