def test_parseNonASCIIConfig(self): """ Non-ASCII <string>s found as part of a configuration file will be retrieved as UTF-8 encoded 'str' objects, as parsed by L{NoUnicodePlistParser}. """ cfg = Config(PListConfigProvider({"DataRoot": ""})) tempfile = FilePath(self.mktemp()) tempfile.setContent(nonASCIIConfigPList) cfg.load(tempfile.path) self.assertEquals(cfg.DataRoot, nonASCIIValue)
def test_includes(self): plist1 = """ <plist version="1.0"> <dict> <key>ServerRoot</key> <string>/root</string> <key>DocumentRoot</key> <string>defaultdoc</string> <key>DataRoot</key> <string>defaultdata</string> <key>ConfigRoot</key> <string>defaultconfig</string> <key>LogRoot</key> <string>defaultlog</string> <key>RunRoot</key> <string>defaultrun</string> <key>Includes</key> <array> <string>%s</string> </array> </dict> </plist> """ plist2 = """ <plist version="1.0"> <dict> <key>DataRoot</key> <string>overridedata</string> </dict> </plist> """ tempfile2 = FilePath(self.mktemp()) tempfile2.setContent(plist2) tempfile1 = FilePath(self.mktemp()) tempfile1.setContent(plist1 % (tempfile2.path, )) cfg = Config( PListConfigProvider({ "ServerRoot": "", "DocumentRoot": "", "DataRoot": "", "ConfigRoot": "", "LogRoot": "", "RunRoot": "", "Includes": [], })) cfg.addPostUpdateHooks([_updateDataStore]) cfg.load(tempfile1.path) self.assertEquals(cfg.DocumentRoot, "/root/overridedata/defaultdoc") self.assertEquals(cfg.DataRoot, "/root/overridedata")
def test_relativeDefaultPaths(self): """ The paths specified in the default configuration should be interpreted as relative to the paths specified in the configuration file. """ cfg = Config(PListConfigProvider( {"AccountingLogRoot": "some-path", "LogRoot": "should-be-ignored"})) cfg.addPostUpdateHooks([_updateDataStore]) tempfile = FilePath(self.mktemp()) tempfile.setContent("<plist version='1.0'><dict>" "<key>LogRoot</key><string>/some/root</string>" "</dict></plist>") cfg.load(tempfile.path) self.assertEquals(cfg.AccountingLogRoot, "/some/root/some-path") tempfile.setContent("<plist version='1.0'><dict>" "<key>LogRoot</key><string>/other/root</string>" "</dict></plist>") cfg.load(tempfile.path) self.assertEquals(cfg.AccountingLogRoot, "/other/root/some-path")
def test_HostnameInclude(self): testConfigMaster = """<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>ResponseCompression</key> <false/> <key>ServerRoot</key> <string></string> <key>ConfigRoot</key> <string></string> <key>HTTPPort</key> <integer>8008</integer> <key>SSLPort</key> <integer>8443</integer> <key>DefaultLogLevel</key> <string>info</string> <key>LogLevels</key> <dict> <key>some.namespace</key> <string>debug</string> </dict> <key>Includes</key> <array> <string>%s.#</string> </array> </dict> </plist> """ testConfigInclude = """<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>HTTPPort</key> <integer>9008</integer> </dict> </plist> """ config.setProvider(PListConfigProvider(DEFAULT_CONFIG)) self.testIncludeRoot = self.mktemp() self.testInclude = self.testIncludeRoot + "." + socket.gethostbyname(socket.getfqdn()) with open(self.testInclude, "w") as f: f.write(testConfigInclude) self.testMaster = self.mktemp() with open(self.testMaster, "w") as f: f.write(testConfigMaster % (self.testIncludeRoot,)) config.load(self.testMaster) self.assertEquals(config.HTTPPort, 9008) self.assertEquals(config.SSLPort, 8443)
def setUp(self): TestCase.setUp(self) config.setProvider(PListConfigProvider(DEFAULT_CONFIG)) self.testConfig = self.mktemp() with open(self.testConfig, "w") as f: f.write(testConfig)