Add tests for functions in api/projects
This commit is contained in:
parent
1c977b79ef
commit
d3d92d13b1
@ -15,15 +15,18 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import os
|
||||
import mock
|
||||
import time
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from yum.Errors import YumBaseError
|
||||
|
||||
from pylorax.api.config import configure, make_yum_dirs
|
||||
from pylorax.api.projects import api_time, api_changelog, yaps_to_project, yaps_to_project_info
|
||||
from pylorax.api.projects import tm_to_dep, yaps_to_module, projects_list, projects_info, projects_depsolve
|
||||
from pylorax.api.projects import modules_list, modules_info, ProjectsError, dep_evra
|
||||
from pylorax.api.projects import modules_list, modules_info, ProjectsError, dep_evra, dep_nevra, ProjectsError
|
||||
from pylorax.api.yumbase import get_base_object
|
||||
|
||||
|
||||
@ -71,7 +74,13 @@ class ProjectsTest(unittest.TestCase):
|
||||
self.assertEqual(api_time(499222800), "1985-10-27T01:00:00")
|
||||
|
||||
def test_api_changelog(self):
|
||||
self.assertEqual(api_changelog([[0,1,"Heavy!"]]), "Heavy!")
|
||||
self.assertEqual(api_changelog([[0,1,"Heavy!"], [0, 1, "Light!"]]), "Heavy!")
|
||||
|
||||
def test_api_changelog_empty_list(self):
|
||||
self.assertEqual(api_changelog([]), '')
|
||||
|
||||
def test_api_changelog_missing_text_entry(self):
|
||||
self.assertEqual(api_changelog([('now', 'atodorov')]), '')
|
||||
|
||||
def test_yaps_to_project(self):
|
||||
result = {"name":"name",
|
||||
@ -132,16 +141,42 @@ class ProjectsTest(unittest.TestCase):
|
||||
"version": "10.0"}
|
||||
self.assertEqual(dep_evra(dep), "10.0-7.el7.noarch")
|
||||
|
||||
def test_dep_evra_with_epoch_not_zero(self):
|
||||
dep = {"arch": "x86_64",
|
||||
"epoch": "2",
|
||||
"name": "tog-pegasus-libs",
|
||||
"release": "3.el7",
|
||||
"version": "2.14.1"}
|
||||
self.assertEqual(dep_evra(dep), "2:2.14.1-3.el7.x86_64")
|
||||
|
||||
def test_dep_nevra(self):
|
||||
dep = {"arch": "noarch",
|
||||
"epoch": "0",
|
||||
"name": "basesystem",
|
||||
"release": "7.el7",
|
||||
"version": "10.0"}
|
||||
self.assertEqual(dep_nevra(dep), "basesystem-10.0-7.el7.noarch")
|
||||
|
||||
def test_projects_list(self):
|
||||
projects = projects_list(self.yb)
|
||||
self.assertEqual(len(projects) > 10, True)
|
||||
|
||||
def test_projects_list_yum_raises_exception(self):
|
||||
with self.assertRaises(ProjectsError):
|
||||
with mock.patch.object(self.yb, 'doPackageLists', side_effect=YumBaseError('TESTING')):
|
||||
projects_list(self.yb)
|
||||
|
||||
def test_projects_info(self):
|
||||
projects = projects_info(self.yb, ["bash"])
|
||||
|
||||
self.assertEqual(projects[0]["name"], "bash")
|
||||
self.assertEqual(projects[0]["builds"][0]["source"]["license"], "GPLv3+")
|
||||
|
||||
def test_projects_info_yum_raises_exception(self):
|
||||
with self.assertRaises(ProjectsError):
|
||||
with mock.patch.object(self.yb, 'doPackageLists', side_effect=YumBaseError('TESTING')):
|
||||
projects_info(self.yb, ["bash"])
|
||||
|
||||
def test_projects_depsolve(self):
|
||||
deps = projects_depsolve(self.yb, ["bash"])
|
||||
|
||||
@ -160,6 +195,11 @@ class ProjectsTest(unittest.TestCase):
|
||||
modules = modules_list(self.yb, ["g*"])
|
||||
self.assertEqual(modules[0]["name"].startswith("g"), True)
|
||||
|
||||
def test_modules_list_yum_raises_exception(self):
|
||||
with self.assertRaises(ProjectsError):
|
||||
with mock.patch.object(self.yb, 'doPackageLists', side_effect=YumBaseError('TESTING')):
|
||||
modules_list(self.yb, None)
|
||||
|
||||
def test_modules_info(self):
|
||||
modules = modules_info(self.yb, ["bash"])
|
||||
|
||||
@ -167,6 +207,11 @@ class ProjectsTest(unittest.TestCase):
|
||||
self.assertEqual(modules[0]["name"], "bash")
|
||||
self.assertEqual(modules[0]["dependencies"][0]["name"], "basesystem")
|
||||
|
||||
def test_modules_info_yum_raises_exception(self):
|
||||
with self.assertRaises(ProjectsError):
|
||||
with mock.patch.object(self.yb, 'doPackageLists', side_effect=YumBaseError('TESTING')):
|
||||
modules_info(self.yb, ["bash"])
|
||||
|
||||
|
||||
class ConfigureTest(unittest.TestCase):
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user