tests/config.py
branchdevel
changeset 184 6b0ff82dff81
parent 179 af65fcbd59d5
child 186 b381eaa774ab
--- a/tests/config.py	Thu Feb 23 16:57:57 2012 +0100
+++ b/tests/config.py	Thu Feb 23 16:58:58 2012 +0100
@@ -4,16 +4,17 @@
 import io
 import ConfigParser
 from  iro import config 
+from iro.offer.provider import Provider, providers
 
 class TestConfig(unittest.TestCase):
     '''test config class'''
     
     def setUp(self):
         self._reloadList=config.config.reloadList
-        config.config.reloadlist=[]
+        config.config.reloadList=[]
 
     def tearDown(self):
-        config.config.reloadlist = self._reloadList
+        config.config.reloadList = self._reloadList
 
     @patch('iro.config.config')
     def testReadConfig(self,pConfig):
@@ -77,10 +78,50 @@
         config.config.readfp(io.BytesIO(sample_config))
         self.assertRaises(ConfigParser.NoOptionError, config.config.read, [])
 
-    def testMust(self):
-        pass
-    testMust.todo= "To implement"
+    @patch('iro.config.ConfigParser.read')
+    def testMust(self,pRead):
+        v=Mock()
+        config.main["test"] = config.Option(v)
+        try:
+            sample_config = """[main]
+hostname = localhost
+port = 8000
+"""
+            config.config.readfp(io.BytesIO(sample_config))
+            config.config.read([])
+            self.assertEqual(v.called,0)
+            sample_config = """[main]
+hostname = localhost
+port = 8000
+test = foohu
+    """
+            config.config.readfp(io.BytesIO(sample_config))
+            config.config.read([])
+            v.assert_called_once_with("foohu","test")
+        finally:
+            del(config.main["test"])
 
-    def testProviders(self):
-        pass
-    testProviders.todo = "to implement"
+    @patch('iro.config.ConfigParser.read')
+    def testProviders(self, pRead):
+        v=Mock()
+        class TestProvider(Provider):
+            def __init__(self,name,c):
+                Provider.__init__(self,name,c)
+                self.options.update({"test":config.Option(v)})
+                self.loadConfig()
+        providers["test"]=TestProvider
+        try:
+            sample_config = """[p]
+"""
+            config.config.readfp(io.BytesIO(sample_config))
+            self.assertRaises(ConfigParser.NoOptionError, config.config.read, [])  
+            self.assertEqual(v.called,0)
+            sample_config = """[p]
+typ= test
+test= foo
+"""
+            config.config.readfp(io.BytesIO(sample_config))
+            config.config.read([])
+            v.assert_called_once_with("foo","test")
+        finally:
+            del(providers["test"])