Package ldaptor :: Package test :: Module test_config
[hide private]
[frames] | no frames]

Source Code for Module ldaptor.test.test_config

 1  """ 
 2  Test cases for the ldaptor.config module. 
 3  """ 
 4   
 5  from twisted.trial import unittest 
 6  import os 
 7  from ldaptor import config 
 8   
9 -def writeFile(path, content):
10 f = file(path, 'w') 11 f.write(content) 12 f.close()
13
14 -class TestConfig(unittest.TestCase):
15 - def testSomething(self):
16 self.dir = self.mktemp() 17 os.mkdir(self.dir) 18 self.f1 = os.path.join(self.dir, 'one.cfg') 19 writeFile(self.f1, """\ 20 [fooSection] 21 fooVar = val 22 23 [barSection] 24 barVar = anotherVal 25 """) 26 self.f2 = os.path.join(self.dir, 'two.cfg') 27 writeFile(self.f2, """\ 28 [fooSection] 29 fooVar = val2 30 """) 31 self.cfg = config.loadConfig( 32 configFiles=[self.f1, self.f2], 33 reload=True) 34 35 val = self.cfg.get('fooSection', 'fooVar') 36 self.assertEquals(val, 'val2') 37 38 val = self.cfg.get('barSection', 'barVar') 39 self.assertEquals(val, 'anotherVal')
40
41 -class IdentitySearch(unittest.TestCase):
42 - def setUp(self):
43 self.dir = self.mktemp() 44 os.mkdir(self.dir) 45 self.f1 = os.path.join(self.dir, 'one.cfg') 46 writeFile(self.f1, """\ 47 [authentication] 48 identity-search = (something=%(name)s) 49 """) 50 self.cfg = config.loadConfig( 51 configFiles=[self.f1], 52 reload=True) 53 self.config = config.LDAPConfig()
54
55 - def testConfig(self):
56 self.assertEquals(self.config.getIdentitySearch('foo'), 57 '(something=foo)')
58
59 - def testCopy(self):
60 conf = self.config.copy(identitySearch='(&(bar=baz)(quux=%(name)s))') 61 self.assertEquals(conf.getIdentitySearch('foo'), 62 '(&(bar=baz)(quux=foo))')
63
64 - def testInitArg(self):
65 conf = config.LDAPConfig(identitySearch='(&(bar=thud)(quux=%(name)s))') 66 self.assertEquals(conf.getIdentitySearch('foo'), 67 '(&(bar=thud)(quux=foo))')
68