|
@@ -28,11 +28,8 @@ from pwman.util.crypto_engine import CryptoEngine
|
|
|
from pwman import default_config, set_xsel
|
|
|
from pwman.ui import get_ui_platform
|
|
|
from pwman.ui.tools import CMDLoop, CliMenuItem
|
|
|
-from pwman import (parser_options, get_conf_options, get_conf_file, set_umask)
|
|
|
+from pwman import (parser_options, get_conf_options, get_conf, set_umask)
|
|
|
from pwman.data.database import __DB_FORMAT__
|
|
|
-from pwman.ui.mac import PwmanCliMacNew
|
|
|
-from pwman.ui.win import PwmanCliWinNew
|
|
|
-from collections import namedtuple
|
|
|
import sys
|
|
|
import unittest
|
|
|
if sys.version_info.major > 2:
|
|
@@ -86,7 +83,7 @@ class DBTests(unittest.TestCase):
|
|
|
def setUp(self):
|
|
|
"test that the right db instance was created"
|
|
|
dbver = __DB_FORMAT__
|
|
|
- self.dbtype = config.get_value("Database", "type")
|
|
|
+ self.dbtype = 'SQLite'
|
|
|
self.db = factory.create(self.dbtype, dbver, testdb)
|
|
|
self.tester = SetupTester(dbver, testdb)
|
|
|
self.tester.create()
|
|
@@ -176,32 +173,32 @@ class DBTests(unittest.TestCase):
|
|
|
self.assertEqual("test", db._filename)
|
|
|
|
|
|
|
|
|
-class TestDBFalseConfig(unittest.TestCase):
|
|
|
-
|
|
|
- def setUp(self):
|
|
|
- # filename = default_config['Database'].pop('filename')
|
|
|
- self.fname1 = default_config['Database'].pop('filename')
|
|
|
- self.fname = config._conf['Database'].pop('filename')
|
|
|
-
|
|
|
- @unittest.skip("Legacy test. Database and file should always be given")
|
|
|
- def test_db_missing_conf_parameter(self):
|
|
|
- self.assertRaises(DatabaseException, factory.create,
|
|
|
- 'SQLite', __DB_FORMAT__)
|
|
|
-
|
|
|
- def test_get_ui_platform(self):
|
|
|
- uiclass, osx = get_ui_platform('windows')
|
|
|
- self.assertFalse(osx)
|
|
|
- self.assertEqual(uiclass.__name__, PwmanCliWinNew.__name__)
|
|
|
- uiclass, osx = get_ui_platform('darwin')
|
|
|
- self.assertTrue(osx)
|
|
|
- self.assertEqual(uiclass.__name__, PwmanCliMacNew.__name__)
|
|
|
- del(uiclass)
|
|
|
- del(osx)
|
|
|
-
|
|
|
- def tearDown(self):
|
|
|
- config.set_value('Database', 'filename', self.fname)
|
|
|
- default_config['Database']['filename'] = self.fname1
|
|
|
- config._conf['Database']['filename'] = self.fname
|
|
|
+#class TestDBFalseConfig(unittest.TestCase):
|
|
|
+#
|
|
|
+# def setUp(self):
|
|
|
+# # filename = default_config['Database'].pop('filename')
|
|
|
+# self.fname1 = default_config['Database'].pop('filename')
|
|
|
+# self.fname = config._conf['Database'].pop('filename')
|
|
|
+#
|
|
|
+# @unittest.skip("Legacy test. Database and file should always be given")
|
|
|
+# def test_db_missing_conf_parameter(self):
|
|
|
+# self.assertRaises(DatabaseException, factory.create,
|
|
|
+# 'SQLite', __DB_FORMAT__)
|
|
|
+#
|
|
|
+# def test_get_ui_platform(self):
|
|
|
+# uiclass, osx = get_ui_platform('windows')
|
|
|
+# self.assertFalse(osx)
|
|
|
+# self.assertEqual(uiclass.__name__, PwmanCliWinNew.__name__)
|
|
|
+# uiclass, osx = get_ui_platform('darwin')
|
|
|
+# self.assertTrue(osx)
|
|
|
+# self.assertEqual(uiclass.__name__, PwmanCliMacNew.__name__)
|
|
|
+# del(uiclass)
|
|
|
+# del(osx)
|
|
|
+#
|
|
|
+# def tearDown(self):
|
|
|
+# config.set_value('Database', 'filename', self.fname)
|
|
|
+# default_config['Database']['filename'] = self.fname1
|
|
|
+# config._conf['Database']['filename'] = self.fname
|
|
|
|
|
|
|
|
|
class CLITests(unittest.TestCase):
|
|
@@ -212,7 +209,7 @@ class CLITests(unittest.TestCase):
|
|
|
|
|
|
def setUp(self):
|
|
|
"test that the right db instance was created"
|
|
|
- self.dbtype = config.get_value("Database", "type")
|
|
|
+ self.dbtype = 'SQLite'
|
|
|
self.db = factory.create(self.dbtype, __DB_FORMAT__, testdb)
|
|
|
self.tester = SetupTester(__DB_FORMAT__, testdb)
|
|
|
self.tester.create()
|
|
@@ -349,7 +346,7 @@ class CLITests(unittest.TestCase):
|
|
|
self.tester.cli._db.editnode(2, node)
|
|
|
|
|
|
def test_get_pass_conf(self):
|
|
|
- numerics, leet, s_chars = get_pass_conf()
|
|
|
+ numerics, leet, s_chars = get_pass_conf(self.tester.cli.config)
|
|
|
self.assertFalse(numerics)
|
|
|
self.assertFalse(leet)
|
|
|
self.assertFalse(s_chars)
|
|
@@ -393,122 +390,122 @@ class FactoryTest(unittest.TestCase):
|
|
|
self.assertRaises(DatabaseException, factory.create, 'UNKNOWN')
|
|
|
|
|
|
|
|
|
-class ConfigTest(unittest.TestCase):
|
|
|
-
|
|
|
- def setUp(self):
|
|
|
- "test that the right db instance was created"
|
|
|
- dbver = 0.4
|
|
|
- self.dbtype = config.get_value("Database", "type")
|
|
|
- self.db = factory.create(self.dbtype, dbver, testdb)
|
|
|
- self.tester = SetupTester(dbver, testdb)
|
|
|
- self.tester.create()
|
|
|
- self.orig_config = config._conf.copy()
|
|
|
- self.orig_config['Encryption'] = {'algorithm': 'AES'}
|
|
|
-
|
|
|
- def test_config_write(self):
|
|
|
- _filename = os.path.join(os.path.dirname(__file__),
|
|
|
- 'testing_config')
|
|
|
- config._file = _filename
|
|
|
- config.save(_filename)
|
|
|
- self.assertTrue(_filename)
|
|
|
- os.remove(_filename)
|
|
|
-
|
|
|
- def test_config_write_with_none(self):
|
|
|
- _filename = os.path.join(os.path.dirname(__file__),
|
|
|
- 'testing_config')
|
|
|
- config._file = _filename
|
|
|
- config.save()
|
|
|
- self.assertTrue(os.path.exists(_filename))
|
|
|
- os.remove(_filename)
|
|
|
-
|
|
|
- def test_write_no_permission(self):
|
|
|
- # this test will pass if you run as root ...
|
|
|
- # assuming you are not doing something like that
|
|
|
- self.assertRaises(config.ConfigException, config.save,
|
|
|
- '/root/test_config')
|
|
|
-
|
|
|
- def test_add_default(self):
|
|
|
- config.add_defaults({'Section1': {'name': 'value'}})
|
|
|
- self.assertIn('Section1', config._defaults)
|
|
|
- config._defaults.pop('Section1')
|
|
|
-
|
|
|
- def test_get_conf(self):
|
|
|
- cnf = config.get_conf()
|
|
|
- cnf_keys = cnf.keys()
|
|
|
- self.assertTrue('Encryption' in cnf_keys)
|
|
|
- self.assertTrue('Readline' in cnf_keys)
|
|
|
- self.assertTrue('Global' in cnf_keys)
|
|
|
- self.assertTrue('Database' in cnf_keys)
|
|
|
-
|
|
|
- def test_load_conf(self):
|
|
|
- self.assertRaises(config.ConfigException, config.load, 'NoSuchFile')
|
|
|
- # Everything should be ok
|
|
|
- config.save('TestConfig.ini')
|
|
|
- config.load('TestConfig.ini')
|
|
|
+#class ConfigTest(unittest.TestCase):
|
|
|
+#
|
|
|
+# def setUp(self):
|
|
|
+# "test that the right db instance was created"
|
|
|
+# dbver = 0.4
|
|
|
+# self.dbtype = config.get_value("Database", "type")
|
|
|
+# self.db = factory.create(self.dbtype, dbver, testdb)
|
|
|
+# self.tester = SetupTester(dbver, testdb)
|
|
|
+# self.tester.create()
|
|
|
+# self.orig_config = config._conf.copy()
|
|
|
+# self.orig_config['Encryption'] = {'algorithm': 'AES'}
|
|
|
+#
|
|
|
+# def test_config_write(self):
|
|
|
+# _filename = os.path.join(os.path.dirname(__file__),
|
|
|
+# 'testing_config')
|
|
|
+# config._file = _filename
|
|
|
+# config.save(_filename)
|
|
|
+# self.assertTrue(_filename)
|
|
|
+# os.remove(_filename)
|
|
|
+#
|
|
|
+# def test_config_write_with_none(self):
|
|
|
+# _filename = os.path.join(os.path.dirname(__file__),
|
|
|
+# 'testing_config')
|
|
|
+# config._file = _filename
|
|
|
+# config.save()
|
|
|
+# self.assertTrue(os.path.exists(_filename))
|
|
|
+# os.remove(_filename)
|
|
|
+
|
|
|
+# def test_write_no_permission(self):
|
|
|
+# # this test will pass if you run as root ...
|
|
|
+# # assuming you are not doing something like that
|
|
|
+# self.assertRaises(config.ConfigException, config.save,
|
|
|
+# '/root/test_config')
|
|
|
+
|
|
|
+# def test_add_default(self):
|
|
|
+# config.add_defaults({'Section1': {'name': 'value'}})
|
|
|
+# self.assertIn('Section1', config._defaults)
|
|
|
+# config._defaults.pop('Section1')
|
|
|
+
|
|
|
+# def test_get_conf(self):
|
|
|
+# cnf = config.get_conf()
|
|
|
+# cnf_keys = cnf.keys()
|
|
|
+# self.assertTrue('Encryption' in cnf_keys)
|
|
|
+# self.assertTrue('Readline' in cnf_keys)
|
|
|
+# self.assertTrue('Global' in cnf_keys)
|
|
|
+# self.assertTrue('Database' in cnf_keys)
|
|
|
+
|
|
|
+# def test_load_conf(self):
|
|
|
+# self.assertRaises(config.ConfigException, config.load, 'NoSuchFile')
|
|
|
+# # Everything should be ok
|
|
|
+# config.save('TestConfig.ini')
|
|
|
+# config.load('TestConfig.ini')
|
|
|
# let's corrupt the file
|
|
|
- cfg = open('TestConfig.ini', 'w')
|
|
|
- cfg.write('Corruption')
|
|
|
- cfg.close()
|
|
|
- self.assertRaises(config.ConfigException, config.load,
|
|
|
- 'TestConfig.ini')
|
|
|
- os.remove('TestConfig.ini')
|
|
|
-
|
|
|
- def test_all_config(self):
|
|
|
- sys.argv = ['pwman3']
|
|
|
- default_config['Database'] = {'type': '',
|
|
|
- 'filename': ''}
|
|
|
- _save_conf = config._conf.copy()
|
|
|
- config._conf = {}
|
|
|
- with open('dummy.conf', 'w') as dummy:
|
|
|
- dummy.write(dummyfile)
|
|
|
- sys.argv = ['pwman3', '-d', '', '-c', 'dummy.conf']
|
|
|
- p2 = parser_options()
|
|
|
- args = p2.parse_args()
|
|
|
- self.assertRaises(Exception, get_conf_options, args, False)
|
|
|
- config._conf = _save_conf.copy()
|
|
|
- os.unlink('dummy.conf')
|
|
|
-
|
|
|
- def test_set_xsel(self):
|
|
|
- set_xsel(config, False)
|
|
|
-
|
|
|
- set_xsel(config, True)
|
|
|
- if sys.platform == 'linux2':
|
|
|
- self.assertEqual(None, config._conf['Global']['xsel'])
|
|
|
-
|
|
|
- def test_get_conf_file(self):
|
|
|
- Args = namedtuple('args', 'cfile')
|
|
|
- args = Args(cfile='nosuchfile')
|
|
|
+# cfg = open('TestConfig.ini', 'w')
|
|
|
+# cfg.write('Corruption')
|
|
|
+# cfg.close()
|
|
|
+# self.assertRaises(config.ConfigException, config.load,
|
|
|
+# 'TestConfig.ini')
|
|
|
+# os.remove('TestConfig.ini')
|
|
|
+
|
|
|
+# def test_all_config(self):
|
|
|
+# sys.argv = ['pwman3']
|
|
|
+# default_config['Database'] = {'type': '',
|
|
|
+# 'filename': ''}
|
|
|
+# _save_conf = config._conf.copy()
|
|
|
+# config._conf = {}
|
|
|
+# with open('dummy.conf', 'w') as dummy:
|
|
|
+# dummy.write(dummyfile)
|
|
|
+# sys.argv = ['pwman3', '-d', '', '-c', 'dummy.conf']
|
|
|
+# p2 = parser_options()
|
|
|
+# args = p2.parse_args()
|
|
|
+# self.assertRaises(Exception, get_conf_options, args, False)
|
|
|
+# config._conf = _save_conf.copy()
|
|
|
+# os.unlink('dummy.conf')
|
|
|
+
|
|
|
+# def test_set_xsel(self):
|
|
|
+# set_xsel(config, False)
|
|
|
+
|
|
|
+# set_xsel(config, True)
|
|
|
+# if sys.platform == 'linux2':
|
|
|
+# self.assertEqual(None, config._conf['Global']['xsel'])
|
|
|
+
|
|
|
+# def test_get_conf_file(self):
|
|
|
+# Args = namedtuple('args', 'cfile')
|
|
|
+# args = Args(cfile='nosuchfile')
|
|
|
# setting the default
|
|
|
# in case the user specifies cfile as command line option
|
|
|
# and that file does not exist!
|
|
|
- foo = config._conf.copy()
|
|
|
- get_conf_file(args)
|
|
|
+# foo = config._conf.copy()
|
|
|
+# get_conf_file(args)
|
|
|
# args.cfile does not exist, hence the config values
|
|
|
# should be the same as in the defaults
|
|
|
- config.set_config(foo)
|
|
|
-
|
|
|
- def test_get_conf_options(self):
|
|
|
- Args = namedtuple('args', 'cfile, dbase, algo')
|
|
|
- args = Args(cfile='nosuchfile', dbase='dummy.db', algo='AES')
|
|
|
- self.assertRaises(Exception, get_conf_options, (args, 'False'))
|
|
|
- config._defaults['Database']['type'] = 'SQLite'
|
|
|
- # config._conf['Database']['type'] = 'SQLite'
|
|
|
- xsel, dbtype = get_conf_options(args, 'True')
|
|
|
- self.assertEqual(dbtype, 'SQLite')
|
|
|
-
|
|
|
- def test_set_conf(self):
|
|
|
- set_conf_f = getattr(config, 'set_conf')
|
|
|
- private_conf = getattr(config, '_conf')
|
|
|
- set_conf_f({'Config': 'OK'})
|
|
|
- self.assertDictEqual({'Config': 'OK'}, config._conf)
|
|
|
- config._conf = private_conf
|
|
|
-
|
|
|
- def test_umask(self):
|
|
|
- config._defaults = {'Global': {}}
|
|
|
- self.assertRaises(config.ConfigException, set_umask, config)
|
|
|
-
|
|
|
- def tearDown(self):
|
|
|
- config._conf = self.orig_config.copy()
|
|
|
+# config.set_config(foo)
|
|
|
+
|
|
|
+# def test_get_conf_options(self):
|
|
|
+# Args = namedtuple('args', 'cfile, dbase, algo')
|
|
|
+# args = Args(cfile='nosuchfile', dbase='dummy.db', algo='AES')
|
|
|
+# self.assertRaises(Exception, get_conf_options, (args, 'False'))
|
|
|
+# config._defaults['Database']['type'] = 'SQLite'
|
|
|
+# # config._conf['Database']['type'] = 'SQLite'
|
|
|
+# xsel, dbtype = get_conf_options(args, 'True')
|
|
|
+# self.assertEqual(dbtype, 'SQLite')
|
|
|
+
|
|
|
+# def test_set_conf(self):
|
|
|
+# set_conf_f = getattr(config, 'set_conf')
|
|
|
+# private_conf = getattr(config, '_conf')
|
|
|
+# set_conf_f({'Config': 'OK'})
|
|
|
+# self.assertDictEqual({'Config': 'OK'}, config._conf)
|
|
|
+# config._conf = private_conf
|
|
|
+
|
|
|
+# def test_umask(self):
|
|
|
+# config._defaults = {'Global': {}}
|
|
|
+# self.assertRaises(config.ConfigException, set_umask, config)
|
|
|
+
|
|
|
+# def tearDown(self):
|
|
|
+# config._conf = self.orig_config.copy()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
# make sure we use local pwman
|