PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/rhn-client-tools-1.7.14/test/testConfig.py

#
Python | 198 lines | 148 code | 42 blank | 8 comment | 1 complexity | 6517bcf277f0bd5add1f04a19bfc7f80 MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/python
  2. import settestpath
  3. # lots of useful util methods for building/tearing down
  4. # test enviroments...
  5. import testutils
  6. from up2date_client import config
  7. import unittest
  8. test_up2date = "etc-sysconfig-rhn/up2date"
  9. class TestConfig(unittest.TestCase):
  10. def setUp(self):
  11. # in this stuff, we get weird stuff existing, so restore
  12. # a config first, then change anything test specifc
  13. testutils.restoreConfig()
  14. self.__setupData()
  15. def __setupData(self):
  16. pass
  17. def tearDown(self):
  18. config.cfg == None
  19. testutils.restoreConfig()
  20. def testEmptyInit(self):
  21. "Verify that the class can be created with no arguments"
  22. cfg = config.initUp2dateConfig(test_up2date)
  23. def testConfigString(self):
  24. "Verify that Config loads a string as a string"
  25. cfg = config.initUp2dateConfig(test_up2date)
  26. assert isinstance(cfg['systemIdPath'], basestring)
  27. def testConfigListSingleItem(self):
  28. "Verify that Config loads a list of one as a list"
  29. cfg = config.initUp2dateConfig(test_up2date)
  30. assert type(cfg['pkgSkipList']) == type([])
  31. def testConfigList(self):
  32. "Verify that Config loads a list as a list"
  33. cfg = config.initUp2dateConfig(test_up2date)
  34. assert type(cfg['disallowConfChanges']) == type([])
  35. def testConfigBool(self):
  36. "Verify that Config loads a bool int as a bool"
  37. cfg = config.initUp2dateConfig(test_up2date)
  38. assert type(cfg['enableProxy']) == type(1)
  39. def testConfigSave(self):
  40. "Verify that Config saves a file without error"
  41. cfg = config.initUp2dateConfig(test_up2date)
  42. cfg.save()
  43. def testConfigSetItem(self):
  44. "Verify that Config.__setitem__ works"
  45. cfg = config.initUp2dateConfig(test_up2date)
  46. cfg['blippyfoobarbazblargh'] = 1
  47. assert cfg['blippyfoobarbazblargh'] == 1
  48. def testConfigInfo(self):
  49. "Verify that Config.into() runs without error"
  50. cfg = config.initUp2dateConfig(test_up2date)
  51. blargh = cfg.info('enableProxy')
  52. def testConfigRuntimeStore(self):
  53. "Verify that values Config['value'] are set for runtime only and not saved"
  54. cfg = config.initUp2dateConfig(test_up2date)
  55. cfg['blippy12345'] = "wantafreehat?"
  56. cfg.save()
  57. # cfg is a fairly persistent singleton, blow it awy to get a new referece
  58. del config.cfg
  59. cfg2 = config.initUp2dateConfig(test_up2date)
  60. # if this returns a value, it means we saved the config file...
  61. assert cfg2['blippy12345'] == None
  62. def testConfigRuntimeStoreNoDir(self):
  63. "Verify that saving a file into a non existent dir works"
  64. # bugzilla: 125179
  65. cfg = config.initUp2dateConfig(test_up2date)
  66. cfg['blippy321'] = "blumblim"
  67. cfg.save()
  68. def testConfigKeysReturnsAList(self):
  69. "Verify that Config.keys() returns a list"
  70. cfg = config.initUp2dateConfig(test_up2date)
  71. blip = cfg.keys()
  72. assert type(blip) == type([])
  73. def testConfigKeys(self):
  74. "Verify that Config.keys() returns a list with the right stuff"
  75. cfg = config.initUp2dateConfig(test_up2date)
  76. blip = cfg.keys()
  77. assert "enableProxy" in blip
  78. def testConfigHasKeyDoesntExist(self):
  79. "Verify that Config.has_key() is correct on non existent keys"
  80. cfg = config.initUp2dateConfig(test_up2date)
  81. assert cfg.has_key("234wfj34ruafho34rhkfe") == 0
  82. def testConfigHasKeyDoesExist(self):
  83. "Verify that Config.has_key() is correct on existing keys"
  84. cfg = config.initUp2dateConfig(test_up2date)
  85. assert cfg.has_key("enableProxy") == 1
  86. def testConfigHasKeyRuntime(self):
  87. "Verify that Config.has_key() is correct for runtime keys"
  88. cfg = config.initUp2dateConfig(test_up2date)
  89. cfg['runtimekey'] = "blippy"
  90. assert cfg.has_key('runtimekey') == 1
  91. def testConfigValues(self):
  92. "Verify that Config.values() runs without error"
  93. cfg = config.initUp2dateConfig(test_up2date)
  94. ret = cfg.values()
  95. assert type(ret) == type([])
  96. def testConfigItems(self):
  97. "Verify that Config.items() runs without error"
  98. cfg = config.initUp2dateConfig(test_up2date)
  99. ret = cfg.items()
  100. assert type(ret) == type([])
  101. def testConfigSet(self):
  102. "Verify that Config.set() sets items into the persistent layer"
  103. cfg = config.initUp2dateConfig(test_up2date)
  104. cfg.set("permItem", 1)
  105. assert cfg.stored["permItem"] == 1
  106. def testConfigSetOverride(self):
  107. "Verify that Config.set() sets items in the persitent layer, overriding runtime"
  108. cfg = config.initUp2dateConfig(test_up2date)
  109. cfg['semiPermItem'] = 1
  110. cfg.set('semiPermItem',0)
  111. assert cfg.stored['semiPermItem'] == 0
  112. def testConfigLoad(self):
  113. "Verify that Config.load() works without exception"
  114. cfg = config.initUp2dateConfig(test_up2date)
  115. cfg.load("/etc/sysconfig/rhn/up2date")
  116. def testNetworkConfig(self):
  117. "Verify that the NetworkConfig class can be created"
  118. nc = config.NetworkConfig()
  119. def testNetworkConfigLoad(self):
  120. "Verify that NetworkConfig.load() runs without error"
  121. nc = config.NetworkConfig()
  122. nc.load()
  123. def testNetworkConfigLoadCorrectness(self):
  124. "Verify that NetworkConfig.load() runs and gets the right info"
  125. testutils.setupConfig("fc2-rpmmd-sources-1")
  126. nc = config.NetworkConfig()
  127. nc.load()
  128. assert nc['blargh'] == "blippyfoo"
  129. def testNetworkConfigLoadCorrectnessOverrides(self):
  130. "Verify that NetworkConfig.load() runs and overrides the default value"
  131. testutils.setupConfig("fc2-rpmmd-sources-1")
  132. nc = config.NetworkConfig()
  133. nc.load()
  134. assert nc['serverURL'] == "http://www.hokeypokeyland.com/XMLRPC"
  135. class TestGetProxySetting(unittest.TestCase):
  136. def setUp(self):
  137. self.cfg = config.initUp2dateConfig(test_up2date)
  138. self.proxy1 = "http://proxy.company.com:8080"
  139. self.proxy2 = "proxy.company.com:8080"
  140. def testHttpSpecified(self):
  141. "Verify that http:// gets stripped from proxy settings"
  142. self.cfg['httpProxy'] = self.proxy1
  143. res = up2dateUtils.getProxySetting()
  144. assert res == "proxy.company.com:8080"
  145. def testHttpUnSpecified(self):
  146. "Verify that proxies with no http:// work correctly"
  147. self.cfg['httpProxy'] = self.proxy2
  148. res = up2dateUtils.getProxySetting()
  149. assert res == "proxy.company.com:8080"
  150. def suite():
  151. suite = unittest.TestSuite()
  152. suite.addTest(unittest.makeSuite(TestConfig))
  153. suite.addTest(unittest.makeSuite(TestGetProxySetting))
  154. return suite
  155. if __name__ == "__main__":
  156. unittest.main(defaultTest="suite")