aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSix <unknown>2010-04-10 17:05:55 -0400
committerSix <unknown>2010-04-10 17:05:55 -0400
commit418bb176021361f539fe5de13c6af0b316d8e4be (patch)
treebf2eb2bda93c523f739b7592d4d6bfd138e6641f /test
downloaddodai-macsupport-418bb176021361f539fe5de13c6af0b316d8e4be.tar.bz2
dodai-macsupport-418bb176021361f539fe5de13c6af0b316d8e4be.tar.xz
dodai-macsupport-418bb176021361f539fe5de13c6af0b316d8e4be.zip
Initial import of source.
Diffstat (limited to 'test')
-rw-r--r--test/config/connection29
-rw-r--r--test/test_config/config19
-rw-r--r--test/test_config/config.cfg67
-rw-r--r--test/test_config/test_db.py106
-rw-r--r--test/test_config/test_file.py101
-rw-r--r--test/test_config/test_init.py62
-rw-r--r--test/test_config/test_log.py147
-rw-r--r--test/test_config/test_option.py53
-rw-r--r--test/test_config/test_sections.py114
-rw-r--r--test/test_dodai.py38
10 files changed, 736 insertions, 0 deletions
diff --git a/test/config/connection b/test/config/connection
new file mode 100644
index 0000000..36b0414
--- /dev/null
+++ b/test/config/connection
@@ -0,0 +1,29 @@
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
18
19[title]
20foo=bar
21
22
23[test_db]
24protocol=postgresql
25hostname=127.0.0.1
26username=test
27password=test
28port=12345
29database=testing
diff --git a/test/test_config/config b/test/test_config/config
new file mode 100644
index 0000000..d3b7019
--- /dev/null
+++ b/test/test_config/config
@@ -0,0 +1,19 @@
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
18[test_section]
19foo=bar
diff --git a/test/test_config/config.cfg b/test/test_config/config.cfg
new file mode 100644
index 0000000..14764ae
--- /dev/null
+++ b/test/test_config/config.cfg
@@ -0,0 +1,67 @@
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
18[testing]
19foo=bar
20
21
22
23[test_db]
24protocol=postgresql
25hostname=127.0.0.1
26username=test
27password=test
28port=12345
29database=testing
30schema=tesuto
31
32[test_db_two]
33protocol=postgre
34protocol_extra=psycopg2
35hostname=127.0.0.1
36username=test
37password=test
38port=12345
39database=testing
40
41[test_db_three]
42protocol=postgresss
43hostname=127.0.0.1
44username=test
45password=test
46port=12345
47database=testing
48
49[test_db_four]
50protocol=postgre
51hostname=127.0.0.1
52username=test
53password=test
54port=tea
55database=testing
56
57[test_db_five]
58protocol=postgres
59hostname=127.0.0.1
60username=test
61password=test
62port=12345ad
63database=testing
64
65[test_db_six]
66protocol=sqlite
67filename=/tmp/test
diff --git a/test/test_config/test_db.py b/test/test_config/test_db.py
new file mode 100644
index 0000000..ed46eae
--- /dev/null
+++ b/test/test_config/test_db.py
@@ -0,0 +1,106 @@
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
new file mode 100644
index 0000000..1ed014e
--- /dev/null
+++ b/test/test_config/test_file.py
@@ -0,0 +1,101 @@
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())
diff --git a/test/test_config/test_init.py b/test/test_config/test_init.py
new file mode 100644
index 0000000..92b44c6
--- /dev/null
+++ b/test/test_config/test_init.py
@@ -0,0 +1,62 @@
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
19from dodai.config import Config
20from dodai.config.option import ConfigOption
21from dodai.config.file import ConfigFile
22from dodai.config.log import ConfigLog
23from dodai.config import ConfigResults
24from dodai.config.db import ConfigDb
25
26class TestConfig(unittest.TestCase):
27
28 def setUp(self):
29 self.obj = Config()
30
31 def test_set_one(self):
32 self.obj.set('foo', 'bar')
33 self.assertTrue('foo' in self.obj.vars.keys())
34
35 def test_set_two(self):
36 self.obj.set('foo', 'bar')
37 self.assertTrue('bar' == self.obj.vars['foo'])
38
39 def test_options(self):
40 obj = self.obj.options()
41 self.assertTrue(isinstance(obj, ConfigOption))
42
43 def test_files(self):
44 obj = self.obj.files()
45 self.assertTrue(isinstance(obj, ConfigFile))
46
47 def test_logs(self):
48 obj = self.obj.logs()
49 self.assertTrue(isinstance(obj, ConfigLog))
50
51 def test_call_one(self):
52 obj = self.obj()
53 self.assertTrue(isinstance(obj, ConfigResults))
54
55 def test_call_two(self):
56 self.obj.set('foo', 'bar')
57 obj = self.obj()
58 self.assertTrue(obj.foo == 'bar')
59
60 def test_db_one(self):
61 obj = self.obj.dbs()
62 self.assertTrue(isinstance(obj, ConfigDb))
diff --git a/test/test_config/test_log.py b/test/test_config/test_log.py
new file mode 100644
index 0000000..d3c46bc
--- /dev/null
+++ b/test/test_config/test_log.py
@@ -0,0 +1,147 @@
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
20import logging
21from logging import Logger
22from dodai.config.log import ConfigLog
23from dodai.config.log import NoDirectoryExistException
24from dodai.config.log import DirectoryNotSetException
25from dodai.config.log import InvalidLevelException
26from logging.handlers import RotatingFileHandler
27from logging import StreamHandler
28
29class TestConfigLog(unittest.TestCase):
30
31
32 def setUp(self):
33 self.obj = ConfigLog()
34 self.path = os.path.dirname(__file__)
35 self.filename = 'test_log_file'
36 self.filepath = os.path.join(self.path, self.filename)
37
38 def tearDown(self):
39 if os.path.isfile(self.filepath):
40 os.remove(self.filepath)
41
42 def test_set_log_level_one(self):
43 self.obj.set_log_level(logging.INFO)
44 self.assertTrue(self.obj.log_level == logging.INFO)
45
46 def test_set_log_level_two(self):
47 self.obj.set_log_level('wArnIng')
48 self.assertTrue(self.obj.log_level == logging.WARNING)
49
50 def test_set_log_level_three(self):
51 default = self.obj.log_level
52 self.obj.set_log_level('i08w9umY3ngas')
53 self.assertTrue(self.obj.log_level == default)
54
55 def test_fetch_log_level_one(self):
56 level = self.obj._fetch_log_level(logging.DEBUG)
57 self.assertTrue(level == logging.DEBUG)
58
59 def test_fetch_log_level_two(self):
60 level = self.obj._fetch_log_level('ErRoR')
61 self.assertTrue(level == logging.ERROR)
62
63 def test_fetch_log_level_three(self):
64 self.failUnlessRaises(InvalidLevelException,
65 self.obj._fetch_log_level,
66 'ba_ri08w9as')
67
68 def test_get_file_message_format(self):
69 default = self.obj.LEVELS[logging.DEBUG][1]
70 out = self.obj.get_file_message_format(logging.DEBUG)
71 self.assertTrue(default == out)
72
73 def test_get_screen_message_format(self):
74 default = self.obj.LEVELS[logging.WARNING][2]
75 out = self.obj.get_screen_message_format(logging.WARNING)
76 self.assertTrue(default == out)
77
78 def test_set_directory_one(self):
79 self.obj.set_directory(self.path)
80 self.assertTrue(self.obj.directory == self.path)
81
82 def test_set_directory_two(self):
83 self.failUnlessRaises(NoDirectoryExistException,
84 self.obj.set_directory,
85 __file__)
86
87 def test_load_one(self):
88 log = self.obj.load('test')
89 self.assertTrue(isinstance(log, Logger))
90
91 def test_build_filepath_one(self):
92 path = self.obj._build_filepath(self.filepath)
93 self.assertTrue(self.filepath == path)
94
95 def test_build_filepath_two(self):
96 self.obj.set_directory(self.path)
97 path = self.obj._build_filepath(self.filename)
98 self.assertTrue(self.filepath == path)
99
100 def test_build_filepath_three(self):
101 self.failUnlessRaises(NoDirectoryExistException,
102 self.obj._build_filepath,
103 os.path.join(__file__, 'blah'))
104
105 def test_build_filepath_four(self):
106 self.failUnlessRaises(DirectoryNotSetException,
107 self.obj._build_filepath,
108 self.filename)
109
110 def test_attach_file_handler(self):
111 self.obj.set_log_level(logging.WARNING)
112 self.obj.set_directory(self.path)
113 log = self.obj.load('test')
114 self.obj.attach_file_handler(log, self.filename)
115 handlers = log.handlers
116 has_stream = False
117 for handle in handlers:
118 print handle
119 if isinstance(handle, RotatingFileHandler):
120 has_stream = True
121 self.assertTrue(has_stream, 'RotatingFileHandler is missing')
122
123 def test_attach_screen_handler_one(self):
124 self.obj.set_log_level(logging.DEBUG)
125 self.obj.set_directory(self.path)
126 log = self.obj.load('testing')
127 self.obj.attach_screen_handler(log, logging.CRITICAL)
128 handlers = log.handlers
129 has_stream = False
130 for handle in handlers:
131 print handle
132 if isinstance(handle, StreamHandler):
133 has_stream = True
134 self.assertTrue(has_stream, 'StreamHandler is missing')
135
136 def test_attach_screen_handler_two(self):
137 self.obj.set_log_level(logging.DEBUG)
138 self.obj.set_directory(self.path)
139 log = self.obj.load('testing')
140 self.obj.attach_screen_handler(log)
141 handlers = log.handlers
142 has_stream = False
143 for handle in handlers:
144 print handle
145 if isinstance(handle, StreamHandler):
146 has_stream = True
147 self.assertTrue(has_stream, 'StreamHandler is missing')
diff --git a/test/test_config/test_option.py b/test/test_config/test_option.py
new file mode 100644
index 0000000..3fc9e6f
--- /dev/null
+++ b/test/test_config/test_option.py
@@ -0,0 +1,53 @@
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
19from dodai.config.option import ConfigOption
20from optparse import OptionParser
21
22class TestConfigOption(unittest.TestCase):
23
24 def setUp(self):
25 self.obj = ConfigOption()
26
27 def test_parser(self):
28 self.assertTrue(isinstance(self.obj.parser, OptionParser))
29
30 def test_add_quiet(self):
31 self.obj.add_quiet()
32 self.assertTrue(self.obj.parser.has_option('-q'))
33
34 def test_add_verbose(self):
35 self.obj.add_verbose()
36 self.assertTrue(self.obj.parser.has_option('-v'))
37
38 def test_add_log_level(self):
39 self.obj.add_log_level('critical')
40 self.assertTrue(self.obj.parser.has_option('-l'))
41
42 def test_add_setup(self):
43 self.obj.add_setup()
44 self.assertTrue(self.obj.parser.has_option('--setup'))
45
46 def test_get_args(self):
47 args = self.obj.get_args()
48 self.assertTrue(args == [])
49
50 def test_get_options(self):
51 self.obj.add_quiet()
52 options = self.obj.get_options()
53 self.assertTrue(options.verbose == True)
diff --git a/test/test_config/test_sections.py b/test/test_config/test_sections.py
new file mode 100644
index 0000000..2aba3c7
--- /dev/null
+++ b/test/test_config/test_sections.py
@@ -0,0 +1,114 @@
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 sys
19import os
20import ConfigParser
21import unittest
22path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
23sys.path.append(path)
24from dodai.tools.himo import Himo
25from dodai.config.sections import ConfigSections
26
27
28class TestSections(unittest.TestCase):
29
30 def setUp(self):
31 path = os.path.dirname(__file__)
32 filepath = os.path.join(path, 'config.cfg')
33 self.parser = ConfigParser.ConfigParser()
34 self.parser.readfp(open(filepath))
35 self.sections = ConfigSections(Himo)
36
37 def test_call(self):
38 self.sections(self.parser)
39 count = len(self.parser.sections())
40 self.assertEqual(count, len(self.sections))
41
42 def test_iterator(self):
43 result = True
44 for section in self.sections:
45 if not section.get_title() in self.parser.sections():
46 result = False
47 self.assertTrue(result==True)
48
49 def test_get_section(self):
50 self.sections(self.parser)
51 self.sections(self.parser)
52 check = self.sections.get_section('test_db')
53 self.assertEqual(check.get_title(), 'test_db')
54
55 def test_build_string_object(self):
56 sections = ConfigSections()
57 sections(self.parser)
58 count = len(self.parser.sections())
59 self.assertEqual(count, len(sections))
60
61 def test_getitem(self):
62 self.sections(self.parser)
63 title = self.sections['test_db'].get_title()
64 self.assertEqual(title, 'test_db')
65
66 def test_getattr(self):
67 self.sections(self.parser)
68 title = self.sections.test_db.get_title()
69 self.assertEqual(title, 'test_db')
70
71 def test_get_keys(self):
72 self.sections(self.parser)
73 keys = self.sections.keys()
74 self.assertTrue(len(keys))
75
76 def test_section_object_one(self):
77 self.sections(self.parser)
78 keys = self.sections.test_db.keys()
79 self.assertTrue(len(keys))
80
81 def test_section_object_two(self):
82 self.sections(self.parser)
83 keys = self.sections.test_db.___options___.keys()
84 self.assertTrue(len(keys))
85
86 def test_section_object_three(self):
87 self.sections(self.parser)
88 self.sections.test_db.___blah___ = 'test'
89 val = self.sections.test_db.__getattr__('___blah___')
90 self.assertTrue(val == 'test')
91
92 def test_section_object_four(self):
93 self.sections(self.parser)
94 self.sections.test_db.foo = 'bar'
95 val = self.sections.test_db.__getattr__('foo')
96 self.assertTrue(val == 'bar')
97
98 def test_section_object_five(self):
99 self.sections(self.parser)
100 keys = []
101 for key in self.sections.test_db:
102 keys.append(key)
103 self.assertTrue(keys)
104
105 def test_section_object_six(self):
106 self.sections(self.parser)
107 self.sections.test_db.foo = 'bar'
108 val = self.sections.test_db['foo']
109 self.assertTrue(val == 'bar')
110
111
112
113if __name__ == '__main__':
114 unittest.main()
diff --git a/test/test_dodai.py b/test/test_dodai.py
new file mode 100644
index 0000000..a521a38
--- /dev/null
+++ b/test/test_dodai.py
@@ -0,0 +1,38 @@
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 import Configure
21
22class TestConfigure(unittest.TestCase):
23
24 def setUp(self):
25 path = os.path.dirname(os.path.abspath(__file__))
26 path = os.path.join(path, 'config')
27 filename = os.path.join(path, 'connection')
28 self.filename = filename
29 self.obj = Configure('test', config_files=[filename])
30
31 def test_results(self):
32 files = self.obj.config_files
33 self.assertTrue(len(files) == 1)
34
35 def test_add_files(self):
36 self.obj._add_files(self.filename)
37 files = self.obj.config_files
38 self.assertTrue(len(files) == 1)