2017-11-22 00:52:02 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2017 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# 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 2 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2017-12-12 09:44:53 +00:00
|
|
|
import os
|
2018-02-12 15:25:32 +00:00
|
|
|
import mock
|
2017-12-12 09:44:53 +00:00
|
|
|
import time
|
2017-11-22 00:52:02 +00:00
|
|
|
import shutil
|
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
|
2018-02-12 15:25:32 +00:00
|
|
|
from yum.Errors import YumBaseError
|
|
|
|
|
2018-02-05 18:40:39 +00:00
|
|
|
from pylorax.api.config import configure, make_yum_dirs
|
2017-11-22 00:52:02 +00:00
|
|
|
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
|
2018-03-09 18:54:17 +00:00
|
|
|
from pylorax.api.projects import modules_list, modules_info, ProjectsError, dep_evra, dep_nevra
|
2017-11-22 00:52:02 +00:00
|
|
|
from pylorax.api.yumbase import get_base_object
|
|
|
|
|
|
|
|
|
|
|
|
class Yaps(object):
|
|
|
|
"""Test class for yaps tests"""
|
|
|
|
name = "name"
|
|
|
|
summary = "summary"
|
|
|
|
description = "description"
|
|
|
|
url = "url"
|
2018-03-09 18:54:17 +00:00
|
|
|
epoch = 1
|
2017-11-22 00:52:02 +00:00
|
|
|
release = "release"
|
|
|
|
arch = "arch"
|
|
|
|
buildtime = 499222800
|
|
|
|
license = "license"
|
|
|
|
version = "version"
|
|
|
|
|
|
|
|
def returnChangelog(self):
|
|
|
|
return [[0,1,"Heavy!"]]
|
|
|
|
|
|
|
|
|
|
|
|
class TM(object):
|
|
|
|
"""Test class for tm test"""
|
|
|
|
name = "name"
|
2018-03-09 18:54:17 +00:00
|
|
|
epoch = 1
|
2017-11-22 00:52:02 +00:00
|
|
|
version = "version"
|
|
|
|
release = "release"
|
|
|
|
arch = "arch"
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectsTest(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(self):
|
|
|
|
self.tmp_dir = tempfile.mkdtemp(prefix="lorax.test.repo.")
|
2017-11-22 18:29:33 +00:00
|
|
|
self.config = configure(root_dir=self.tmp_dir, test_config=True)
|
2018-02-05 18:40:39 +00:00
|
|
|
make_yum_dirs(self.config)
|
2017-11-22 00:52:02 +00:00
|
|
|
self.yb = get_base_object(self.config)
|
2017-12-12 09:44:53 +00:00
|
|
|
os.environ["TZ"] = "UTC"
|
|
|
|
time.tzset()
|
2017-11-22 00:52:02 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(self):
|
|
|
|
shutil.rmtree(self.tmp_dir)
|
|
|
|
|
|
|
|
def test_api_time(self):
|
2017-12-12 09:44:53 +00:00
|
|
|
self.assertEqual(api_time(499222800), "1985-10-27T01:00:00")
|
2017-11-22 00:52:02 +00:00
|
|
|
|
|
|
|
def test_api_changelog(self):
|
2018-02-12 15:25:32 +00:00
|
|
|
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')]), '')
|
2017-11-22 00:52:02 +00:00
|
|
|
|
|
|
|
def test_yaps_to_project(self):
|
|
|
|
result = {"name":"name",
|
|
|
|
"summary":"summary",
|
|
|
|
"description":"description",
|
|
|
|
"homepage":"url",
|
|
|
|
"upstream_vcs":"UPSTREAM_VCS"}
|
|
|
|
|
|
|
|
y = Yaps()
|
|
|
|
self.assertEqual(yaps_to_project(y), result)
|
|
|
|
|
|
|
|
def test_yaps_to_project_info(self):
|
2018-03-09 18:54:17 +00:00
|
|
|
build = {"epoch":1,
|
2017-11-22 00:52:02 +00:00
|
|
|
"release":"release",
|
|
|
|
"arch":"arch",
|
2017-12-12 09:44:53 +00:00
|
|
|
"build_time":"1985-10-27T01:00:00",
|
2017-11-22 00:52:02 +00:00
|
|
|
"changelog":"Heavy!",
|
|
|
|
"build_config_ref": "BUILD_CONFIG_REF",
|
|
|
|
"build_env_ref": "BUILD_ENV_REF",
|
|
|
|
"metadata": {},
|
|
|
|
"source": {"license":"license",
|
|
|
|
"version":"version",
|
|
|
|
"source_ref": "SOURCE_REF",
|
|
|
|
"metadata": {}}}
|
|
|
|
|
|
|
|
result = {"name":"name",
|
|
|
|
"summary":"summary",
|
|
|
|
"description":"description",
|
|
|
|
"homepage":"url",
|
|
|
|
"upstream_vcs":"UPSTREAM_VCS",
|
|
|
|
"builds": [build]}
|
|
|
|
|
|
|
|
y = Yaps()
|
|
|
|
self.assertEqual(yaps_to_project_info(y), result)
|
|
|
|
|
|
|
|
def test_tm_to_dep(self):
|
|
|
|
result = {"name":"name",
|
2018-03-09 18:54:17 +00:00
|
|
|
"epoch":1,
|
2017-11-22 00:52:02 +00:00
|
|
|
"version":"version",
|
|
|
|
"release":"release",
|
|
|
|
"arch":"arch"}
|
|
|
|
|
|
|
|
tm = TM()
|
|
|
|
self.assertEqual(tm_to_dep(tm), result)
|
|
|
|
|
|
|
|
def test_yaps_to_module(self):
|
|
|
|
result = {"name":"name",
|
|
|
|
"group_type":"rpm"}
|
|
|
|
|
|
|
|
y = Yaps()
|
|
|
|
self.assertEqual(yaps_to_module(y), result)
|
|
|
|
|
2017-11-22 22:46:43 +00:00
|
|
|
def test_dep_evra(self):
|
|
|
|
dep = {"arch": "noarch",
|
2018-03-09 18:54:17 +00:00
|
|
|
"epoch": 0,
|
2017-11-22 22:46:43 +00:00
|
|
|
"name": "basesystem",
|
|
|
|
"release": "7.el7",
|
|
|
|
"version": "10.0"}
|
|
|
|
self.assertEqual(dep_evra(dep), "10.0-7.el7.noarch")
|
|
|
|
|
2018-02-12 15:25:32 +00:00
|
|
|
def test_dep_evra_with_epoch_not_zero(self):
|
|
|
|
dep = {"arch": "x86_64",
|
2018-03-09 18:54:17 +00:00
|
|
|
"epoch": 2,
|
2018-02-12 15:25:32 +00:00
|
|
|
"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",
|
2018-03-09 18:54:17 +00:00
|
|
|
"epoch": 0,
|
2018-02-12 15:25:32 +00:00
|
|
|
"name": "basesystem",
|
|
|
|
"release": "7.el7",
|
|
|
|
"version": "10.0"}
|
|
|
|
self.assertEqual(dep_nevra(dep), "basesystem-10.0-7.el7.noarch")
|
|
|
|
|
2017-11-22 00:52:02 +00:00
|
|
|
def test_projects_list(self):
|
|
|
|
projects = projects_list(self.yb)
|
|
|
|
self.assertEqual(len(projects) > 10, True)
|
|
|
|
|
2018-02-12 15:25:32 +00:00
|
|
|
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)
|
|
|
|
|
2017-11-22 00:52:02 +00:00
|
|
|
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+")
|
|
|
|
|
2018-02-12 15:25:32 +00:00
|
|
|
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"])
|
|
|
|
|
2017-11-22 00:52:02 +00:00
|
|
|
def test_projects_depsolve(self):
|
2018-05-19 00:28:20 +00:00
|
|
|
deps = projects_depsolve(self.yb, [("bash", "*.*")])
|
|
|
|
self.assertTrue(len(deps) > 3)
|
|
|
|
self.assertEqual(deps[2]["name"], "basesystem")
|
2017-11-22 00:52:02 +00:00
|
|
|
|
2018-05-19 00:28:20 +00:00
|
|
|
def test_projects_depsolve_version(self):
|
|
|
|
"""Test that depsolving with a partial wildcard version works"""
|
|
|
|
deps = projects_depsolve(self.yb, [("bash", "4.*")])
|
|
|
|
self.assertEqual(deps[1]["name"], "bash")
|
|
|
|
|
|
|
|
deps = projects_depsolve(self.yb, [("bash", "4.2.*")])
|
|
|
|
self.assertEqual(deps[1]["name"], "bash")
|
|
|
|
|
|
|
|
def test_projects_depsolve_oldversion(self):
|
|
|
|
"""Test that depsolving a specific non-existant version fails"""
|
|
|
|
with self.assertRaises(ProjectsError):
|
|
|
|
deps = projects_depsolve(self.yb, [("bash", "1.0.0")])
|
|
|
|
self.assertEqual(deps[1]["name"], "bash")
|
2017-11-22 00:52:02 +00:00
|
|
|
|
|
|
|
def test_projects_depsolve_fail(self):
|
|
|
|
with self.assertRaises(ProjectsError):
|
2018-05-19 00:28:20 +00:00
|
|
|
projects_depsolve(self.yb, [("nada-package", "*.*")])
|
2017-11-22 00:52:02 +00:00
|
|
|
|
|
|
|
def test_modules_list(self):
|
2017-11-22 23:31:21 +00:00
|
|
|
modules = modules_list(self.yb, None)
|
2017-11-22 00:52:02 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(modules) > 10, True)
|
|
|
|
self.assertEqual(modules[0]["group_type"], "rpm")
|
|
|
|
|
2017-11-22 23:31:21 +00:00
|
|
|
modules = modules_list(self.yb, ["g*"])
|
|
|
|
self.assertEqual(modules[0]["name"].startswith("g"), True)
|
|
|
|
|
2018-02-12 15:25:32 +00:00
|
|
|
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)
|
|
|
|
|
2017-11-22 00:52:02 +00:00
|
|
|
def test_modules_info(self):
|
|
|
|
modules = modules_info(self.yb, ["bash"])
|
|
|
|
|
|
|
|
print(modules)
|
2018-05-19 00:28:20 +00:00
|
|
|
self.assertTrue(len(modules) > 0)
|
|
|
|
self.assertTrue(len(modules[0]["dependencies"]) > 3)
|
2017-11-22 00:52:02 +00:00
|
|
|
self.assertEqual(modules[0]["name"], "bash")
|
2018-05-19 00:28:20 +00:00
|
|
|
self.assertEqual(modules[0]["dependencies"][2]["name"], "basesystem")
|
2018-02-09 15:09:18 +00:00
|
|
|
|
2018-02-12 15:25:32 +00:00
|
|
|
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"])
|
|
|
|
|
2018-02-09 15:09:18 +00:00
|
|
|
|
|
|
|
class ConfigureTest(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(self):
|
|
|
|
self.tmp_dir = tempfile.mkdtemp(prefix="lorax.test.configure.")
|
|
|
|
self.conf_file = os.path.join(self.tmp_dir, 'test.conf')
|
|
|
|
open(self.conf_file, 'w').write("[composer]\ncache_dir = /tmp/cache-test")
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(self):
|
|
|
|
shutil.rmtree(self.tmp_dir)
|
|
|
|
|
|
|
|
def test_configure_reads_existing_file(self):
|
|
|
|
config = configure(conf_file=self.conf_file)
|
|
|
|
self.assertEqual(config.get('composer', 'cache_dir'), '/tmp/cache-test')
|
|
|
|
|
|
|
|
def test_configure_reads_non_existing_file(self):
|
|
|
|
config = configure(conf_file=self.conf_file + '.non-existing')
|
|
|
|
self.assertEqual(config.get('composer', 'cache_dir'), '/var/tmp/composer/cache')
|