1 from .dbtestcase import DBTestCase |
1 from mock import patch, Mock |
|
2 from twisted.trial import unittest |
|
3 import signal |
|
4 import io |
|
5 import ConfigParser |
|
6 from iro import config |
2 |
7 |
3 class TestConfig(DBTestCase): |
8 class TestConfig(unittest.TestCase): |
4 '''test config class''' |
9 '''test config class''' |
5 pass |
10 |
|
11 def setUp(self): |
|
12 self._reloadList=config.config.reloadList |
|
13 config.config.reloadlist=[] |
|
14 |
|
15 def tearDown(self): |
|
16 config.config.reloadlist = self._reloadList |
|
17 |
|
18 @patch('iro.config.config') |
|
19 def testReadConfig(self,pConfig): |
|
20 config.readConfig() |
|
21 self.assertEqual([i[0] for i in pConfig.method_calls],["read","reload"]) |
|
22 pConfig.read.assert_called_once_with(config.confFiles) |
|
23 pConfig.reload.assert_called_once_with() |
|
24 |
|
25 @patch('signal.signal') |
|
26 @patch('iro.config.readConfig') |
|
27 def testRegisterSignal(self, pReadConfig, pSignal): |
|
28 config.registerSignal() |
|
29 self.assertEqual(pSignal.call_args[0][0],signal.SIGUSR2) |
|
30 self.assertEqual(pReadConfig.called,0) |
|
31 pSignal.call_args[0][1](None, None) |
|
32 pReadConfig.assert_called_once_with() |
|
33 |
|
34 def testRegisterReload(self): |
|
35 def x(): |
|
36 pass |
|
37 config.config.registerReload(x) |
|
38 self.assertEqual(config.config.reloadList,[x]) |
|
39 |
|
40 def testReload(self): |
|
41 x = Mock() |
|
42 config.config.reloadList = [x] |
|
43 config.config.reload_() |
|
44 x.assert_called_once_with() |
|
45 |
|
46 |
|
47 class TestRead(unittest.TestCase): |
|
48 |
|
49 def tearDown(self): |
|
50 for s in config.config.sections(): |
|
51 config.config.remove_section(s) |
|
52 |
|
53 @patch('iro.config.ConfigParser.read') |
|
54 def testMain(self,pRead): |
|
55 sample_config = """[main] |
|
56 hostname = localhost |
|
57 port = 8000 |
|
58 """ |
|
59 config.config.readfp(io.BytesIO(sample_config)) |
|
60 config.config.read([]) |
|
61 pRead.assert_called_once_with(config.config,[]) |
|
62 |
|
63 @patch('iro.config.ConfigParser.read') |
|
64 def testMainBadPort(self,pRead): |
|
65 sample_config = """[main] |
|
66 hostname = localhost |
|
67 port = -8000 |
|
68 """ |
|
69 config.config.readfp(io.BytesIO(sample_config)) |
|
70 self.assertRaises(config.ValidateException, config.config.read, []) |
|
71 |
|
72 @patch('iro.config.ConfigParser.read') |
|
73 def testMainNoMust(self,pRead): |
|
74 sample_config = """[main] |
|
75 port = 8000 |
|
76 """ |
|
77 config.config.readfp(io.BytesIO(sample_config)) |
|
78 self.assertRaises(ConfigParser.NoOptionError, config.config.read, []) |
|
79 |
|
80 def testMust(self): |
|
81 pass |
|
82 testMust.todo= "To implement" |
|
83 |
|
84 def testProviders(self): |
|
85 pass |
|
86 testProviders.todo = "to implement" |