aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSix <unknown>2010-05-01 23:06:55 -0400
committerSix <unknown>2010-05-01 23:06:55 -0400
commite1cd280724290c8354f510922f8b13d3896d0e89 (patch)
tree226ef26f38a87333e4d01a0e1c959b8fb9a8af11 /test
parent8780fb51777b9042cdfd12a3625bbdc871621820 (diff)
downloaddodai-macsupport-e1cd280724290c8354f510922f8b13d3896d0e89.tar.bz2
dodai-macsupport-e1cd280724290c8354f510922f8b13d3896d0e89.tar.xz
dodai-macsupport-e1cd280724290c8354f510922f8b13d3896d0e89.zip
Removed dodai.config.db because it is replaced with dodai.config.databases. Removed dodai.config.file because it is replaced with dodai.config.files
Diffstat (limited to 'test')
-rw-r--r--test/test_config/test_db.py106
-rw-r--r--test/test_config/test_file.py101
2 files changed, 0 insertions, 207 deletions
diff --git a/test/test_config/test_db.py b/test/test_config/test_db.py
deleted file mode 100644
index ed46eae..0000000
--- a/test/test_config/test_db.py
+++ /dev/null
@@ -1,106 +0,0 @@
1# Copyright (C) 2010 Leonard Thomas
2#
3# This file is part of Dodai.
4#
5# Dodai is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# Dodai is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with Dodai. If not, see <http://www.gnu.org/licenses/>.
17
18import unittest
19import os
20from dodai.config.db import ConfigDb
21from dodai.config.db import ConfigDbFile
22from dodai.config.db import BaseConfigDb
23from dodai.config.db import NotConfigParserObject
24from dodai.config.db import InvalidProtocolException
25from dodai.config.db import InvalidPortException
26from dodai.config.db import UnknownHandlerException
27from dodai.config.db import UnknownConnectionException
28from dodai.config.db.sa import Sa
29from dodai.config.file import ConfigFile
30from dodai.db import Db
31
32class TestConfigDb(unittest.TestCase):
33
34
35 def setUp(self):
36 self.config_db = ConfigDb()
37 config = ConfigFile()
38 config.set_directory(os.path.dirname(os.path.abspath(__file__)))
39 config.load('config.cfg')
40 self.parser = config.parser()
41
42 def test_setup(self):
43 obj = self.config_db._handlers['sa'][0]
44 self.assertTrue(obj == Sa)
45
46 def test_register_handler(self):
47 self.config_db.register_handler('foo', Exception)
48 self.assertTrue('foo' in self.config_db._handlers.keys())
49
50 def test_add_config_one(self):
51 self.config_db.add_config(config_parser=self.parser)
52 self.assertTrue('test_db' in self.config_db.connections.keys())
53
54 def test_add_config_two(self):
55 self.failUnlessRaises(NotConfigParserObject, self.config_db.add_config,
56 config_parser='blah')
57
58 def test_load_one(self):
59 self.config_db.add_config(config_parser=self.parser)
60 obj = self.config_db.load('test_db')
61 self.assertTrue(isinstance(obj, Db))
62
63 def test_load_two(self):
64 self.config_db.add_config(config_parser=self.parser)
65 obj = self.config_db.load('test_db')
66 obj = self.config_db.load('test_db')
67 self.assertTrue(isinstance(obj, Db))
68
69 def test_load_handler(self):
70 self.failUnlessRaises(UnknownHandlerException,
71 self.config_db._load_handler, 'test')
72
73 def test_clean_protocol_one(self):
74 self.config_db.add_config(config_parser=self.parser)
75 obj = self.config_db.load('test_db_two')
76 self.assertTrue(isinstance(obj, Db))
77
78 def test_clean_protocol_one(self):
79 self.config_db.add_config(config_parser=self.parser)
80 obj = self.config_db.load('test_db_two')
81 self.assertTrue(isinstance(obj, Db))
82
83 def test_clean_protocol_two(self):
84 self.config_db.add_config(config_parser=self.parser)
85 self.failUnlessRaises(InvalidProtocolException, self.config_db.load,
86 'test_db_three')
87
88 def test_clean_port_one(self):
89 obj = BaseConfigDb()
90 data = obj._clean_port('ad')
91 self.assertTrue(data == None)
92
93 def test_clean_port_two(self):
94 obj = BaseConfigDb()
95 data = obj._clean_port(None)
96 self.assertTrue(data == None)
97
98 def test_clean_port_three(self):
99 obj = BaseConfigDb()
100 self.failUnlessRaises(InvalidPortException, obj._clean_port, 66666)
101
102
103 def test_file_load_one(self):
104 self.config_db.add_config(config_parser=self.parser)
105 obj = self.config_db.load('test_db_six')
106 self.assertTrue(isinstance(obj, Db))
diff --git a/test/test_config/test_file.py b/test/test_config/test_file.py
deleted file mode 100644
index 1ed014e..0000000
--- a/test/test_config/test_file.py
+++ /dev/null
@@ -1,101 +0,0 @@
1# Copyright (C) 2010 Leonard Thomas
2#
3# This file is part of Dodai.
4#
5# Dodai is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# Dodai is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with Dodai. If not, see <http://www.gnu.org/licenses/>.
17
18import unittest
19import os
20from dodai.config.file import ConfigFile
21from dodai.config.file import DirectoryDoesNotExistException
22from dodai.config.file import DirectoryNotSetException
23from dodai.config.file import InvalidDirectoryException
24from dodai.config.file import FileDoesNotExistException
25from dodai.config.file import NoFilesToLoadException
26import ConfigParser
27
28class TestConfigFile(unittest.TestCase):
29
30 def setUp(self):
31 self.obj = ConfigFile()
32 self.path = os.path.dirname(__file__)
33 self.filename = 'config'
34 self.filepath = os.path.join(self.path, self.filename)
35 next_file = os.path.join(self.path, 'config.cfg')
36 self.paths = [self.filepath, next_file]
37
38 def test_file_add(self):
39 self.obj.add_file(self.filepath)
40 paths = [self.filepath]
41 files = self.obj.get_files()
42 self.assertEqual(files, paths)
43
44 def test_double_file_add(self):
45 self.obj.add_file(self.filepath)
46 self.obj.add_file(self.filepath)
47 paths = [self.filepath]
48 files = self.obj.get_files()
49 self.assertEqual(files, paths)
50
51 def test_file_does_not_exist(self):
52 path = os.path.join(self.path, 'foo')
53 self.failUnlessRaises(FileDoesNotExistException,
54 self.obj.add_file, path)
55
56 def test_multiple_file_add(self):
57 self.obj.add_file(self.paths)
58 files = self.obj.get_files()
59 self.assertEqual(files, self.paths)
60
61 def test_empty_parser(self):
62 self.failUnlessRaises(Exception, self.obj.parser)
63
64 def test_parser(self):
65 self.obj.add_file(self.filepath)
66 parser = self.obj.parser()
67 self.assertTrue(isinstance(parser, ConfigParser.ConfigParser))
68
69 def test_parser_error(self):
70 self.failUnlessRaises(NoFilesToLoadException, self.obj.parser)
71
72 def test_set_directory(self):
73 self.obj.set_directory(self.path)
74 dir = self.obj.get_directory()
75 self.assertEqual(dir, self.path)
76
77 def test_invalid_directory(self):
78 self.failUnlessRaises(InvalidDirectoryException,
79 self.obj.set_directory, self.filepath)
80
81 def test_directory_does_not_exist(self):
82 path = os.path.join(self.path, 'nowayjose')
83 self.failUnlessRaises(DirectoryDoesNotExistException,
84 self.obj.set_directory, path)
85
86 def test_load(self):
87 self.obj.set_directory(self.path)
88 self.obj.load(self.filename)
89 check = [self.filepath]
90 self.assertEqual(check, self.obj.get_files())
91
92 def test_no_directory_set(self):
93 self.failUnlessRaises(DirectoryNotSetException,
94 self.obj.load, self.filename)
95
96 def test_reset_parser(self):
97 self.obj.add_file(self.filepath)
98 self.obj.parser()
99 self.obj.add_file(self.paths)
100 self.obj.parser()
101 self.assertEqual(self.obj.files_loaded, self.obj.get_files())