Commit 7803db0a authored by Rafael Monnerat's avatar Rafael Monnerat

slapos.package.test: Include Initial tests for getDistributionHandler

  Fix minor typo changes on distribution.py
parent a0a3e41d
......@@ -38,6 +38,9 @@ _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
_release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
_codename_file_re = re.compile("(?:DISTRIB_CODENAME\s*=)\s*(.*)", re.I)
class UnsupportedOSException(Exception):
pass
def patched_linux_distribution(distname='', version='', id='',
supported_dists=platform._supported_dists,
full_distribution_name=1):
......@@ -80,7 +83,7 @@ class PackageManager:
""" This is implemented in BasePromise """
raise NotImplemented
def _getDistribitionHandler(self):
def _getDistributionHandler(self):
distribution_name = self.getDistributionName()
if distribution_name.lower().strip() == 'opensuse':
return Zypper()
......@@ -88,15 +91,15 @@ class PackageManager:
elif distribution_name.lower().strip() in ['debian', 'ubuntu']:
return AptGet()
raise NotImplemented("Distribution (%s) is not Supported!" % distribution_name)
raise UnsupportedOSException("Distribution (%s) is not Supported!" % distribution_name)
def _purgeRepository(self):
""" Remove all repositories """
return self._getDistribitionHandler().purgeRepository(self._call)
return self._getDistributionHandler().purgeRepository(self._call)
def _addRepository(self, url, alias):
""" Add a repository """
return self._getDistribitionHandler().addRepository(self._call, url, alias)
return self._getDistributionHandler().addRepository(self._call, url, alias)
def _addKey(self, url, alias):
""" Add a gpg or a key """
......@@ -104,19 +107,19 @@ class PackageManager:
def _updateRepository(self):
""" Add a repository """
return self._getDistribitionHandler().updateRepository(self._call)
return self._getDistributionHandler().updateRepository(self._call)
def _installSoftwareList(self, name_list):
""" Upgrade softwares """
return self._getDistribitionHandler().installSoftwareList(self._call, name_list)
return self._getDistributionHandler().installSoftwareList(self._call, name_list)
def _updateSoftware(self):
""" Upgrade softwares """
return self._getDistribitionHandler().updateSoftware(self._call)
return self._getDistributionHandler().updateSoftware(self._call)
def _updateSystem(self):
""" Dist-Upgrade of system """
return self._getDistribitionHandler().updateSystem(self._call)
return self._getDistributionHandler().updateSystem(self._call)
def update(self, repository_list=[], package_list=[], key_list=[]):
""" Perform upgrade """
......
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2012-2014 Vifib SARL and Contributors.
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from slapos.package.distribution import PackageManager, AptGet, Zypper, \
UnsupportedOSException
import os
import unittest
def _fake_call(self, *args, **kw):
self.last_call = args
class testPackageManager(unittest.TestCase):
def setUp(self):
PackageManager._call = _fake_call
def testGetDistributionHandler(self):
package_manager = PackageManager()
def OpenSuseCase():
return "OpenSuse"
package_manager.getDistributionName = OpenSuseCase
self.assertTrue(
isinstance(package_manager._getDistributionHandler(), Zypper))
def DebianCase():
return "Debian"
package_manager.getDistributionName = DebianCase
self.assertTrue(
isinstance(package_manager._getDistributionHandler(), AptGet))
def RedHatCase():
return "Red Hat"
package_manager.getDistributionName = RedHatCase
self.assertRaises(UnsupportedOSException, package_manager._getDistributionHandler)
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