Commit 79561a0d authored by Rafael Monnerat's avatar Rafael Monnerat

slapos.package.test: Include tests for Distribution

parent 0e2cc3e0
...@@ -35,6 +35,38 @@ import unittest ...@@ -35,6 +35,38 @@ import unittest
def _fake_call(self, *args, **kw): def _fake_call(self, *args, **kw):
self.last_call = args self.last_call = args
def _fake_debian_distribution(*args, **kw):
return ('debian', '7.4', '')
def _fake_opensuse_distribution(*args, **kw):
return ('OpenSuse ', '12.1', '')
class DummyDistributionHandler:
called = []
def purgeRepository(self, caller):
self.called.append("purgeRepository")
def addRepository(self, caller, url, alias):
self.called.append("addRepository")
def addKey(self, caller, url, alias):
self.called.append("addKey")
def updateRepository(self, caller):
self.called.append("updateRepository")
def isUpgradable(self, caller, name):
self.called.append("isUpgradeble")
def installSoftwareList(self, caller, name_list):
self.called.append("installSoftwareList")
def updateSoftware(self, caller):
self.called.append("updateSoftware")
def updateSystem(self, caller):
self.called.append("updateSystem")
class testPackageManager(unittest.TestCase): class testPackageManager(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -60,6 +92,82 @@ class testPackageManager(unittest.TestCase): ...@@ -60,6 +92,82 @@ class testPackageManager(unittest.TestCase):
return "Red Hat" return "Red Hat"
package_manager.getDistributionName = RedHatCase package_manager.getDistributionName = RedHatCase
self.assertRaises(UnsupportedOSException, package_manager._getDistributionHandler) self.assertRaises(UnsupportedOSException,
package_manager._getDistributionHandler)
def testGetDistributionName(self):
package_manager = PackageManager()
package_manager._getLinuxDistribution = _fake_opensuse_distribution
self.assertEquals(package_manager.getDistributionName(), "OpenSuse ")
package_manager._getLinuxDistribution = _fake_debian_distribution
self.assertEquals(package_manager.getDistributionName(), "debian")
def testGetVersion(self):
package_manager = PackageManager()
package_manager._getLinuxDistribution = _fake_opensuse_distribution
self.assertEquals(package_manager.getVersion(), "12.1")
package_manager._getLinuxDistribution = _fake_debian_distribution
self.assertEquals(package_manager.getVersion(), "7.4")
def testOSSignature(self):
package_manager = PackageManager()
package_manager._getLinuxDistribution = _fake_opensuse_distribution
self.assertEquals(package_manager.getOSSignature(), "opensuse+++12.1+++")
package_manager._getLinuxDistribution = _fake_debian_distribution
self.assertEquals(package_manager.getOSSignature(), "debian+++7.4+++")
def _getPatchedPackageManagerForApiTest(self):
package_manager = PackageManager()
dummy_handler = DummyDistributionHandler()
def DummyCase():
dummy_handler.called = []
return dummy_handler
package_manager._getDistributionHandler = DummyCase
self.assertEquals(package_manager._getDistributionHandler(), dummy_handler)
self.assertEquals(dummy_handler.called, [])
return package_manager, dummy_handler
def testPurgeRepositoryAPI(self):
package_manager, handler = self._getPatchedPackageManagerForApiTest()
package_manager._purgeRepository()
self.assertEquals(handler.called, ["purgeRepository"])
def testAddRepositoryAPI(self):
package_manager, handler = self._getPatchedPackageManagerForApiTest()
package_manager._addRepository("http://...", "slapos")
self.assertEquals(handler.called, ["addRepository"])
def testAddKeyAPI(self):
package_manager, handler = self._getPatchedPackageManagerForApiTest()
package_manager._addKey("http://...", "slapos")
self.assertEquals(handler.called, ["addKey"])
def testUpdateRepositoryAPI(self):
package_manager, handler = self._getPatchedPackageManagerForApiTest()
package_manager._updateRepository()
self.assertEquals(handler.called, ["updateRepository"])
def testInstalledSoftwareListAPI(self):
package_manager, handler = self._getPatchedPackageManagerForApiTest()
package_manager._installSoftwareList(["slapos", "re6st"])
self.assertEquals(handler.called, ["installSoftwareList"])
def testUpdateSoftwareAPI(self):
package_manager, handler = self._getPatchedPackageManagerForApiTest()
package_manager._updateSoftware()
self.assertEquals(handler.called, ["updateSoftware"])
def testUpdateSystemAPI(self):
package_manager, handler = self._getPatchedPackageManagerForApiTest()
package_manager._updateSystem()
self.assertEquals(handler.called, ["updateSystem"])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment