diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index 7b9238d8..73ba2f3e 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -345,8 +345,8 @@ def v0_api(api): log.error("(v0_modules_list) %s", str(e)) return jsonify(error={"msg":str(e)}), 400 - projects = take_limits(available, offset, limit) - return jsonify(projects=projects, offset=offset, limit=limit, total=len(available)) + modules = take_limits(available, offset, limit) + return jsonify(modules=modules, offset=offset, limit=limit, total=len(available)) @api.route("/api/v0/modules/info/") @crossdomain(origin="*") diff --git a/tests/pylorax/test_projects.py b/tests/pylorax/test_projects.py index 6ab9c17f..e48d85d0 100644 --- a/tests/pylorax/test_projects.py +++ b/tests/pylorax/test_projects.py @@ -14,43 +14,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -import os import shutil import tempfile import unittest -from pylorax.api.config import ComposerConfig +from pylorax.api.config import configure 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 from pylorax.api.yumbase import get_base_object -from pylorax.sysutils import joinpaths - -def config(tmp_dir): - """Create a config to use for testing projects functions""" - conf = ComposerConfig() - - # set defaults - conf.add_section("composer") - conf.set("composer", "yum_conf", joinpaths(tmp_dir, "/var/lib/lorax/composer/yum.conf")) - conf.set("composer", "repo_dir", joinpaths(tmp_dir, "/var/lib/lorax/composer/repos.d/")) - conf.set("composer", "cache_dir", joinpaths("/var/cache/lorax/composer/yum/")) - - conf.add_section("users") - conf.set("users", "root", "1") - - # Enable all available repo files by default - conf.add_section("repos") - conf.set("repos", "use_system_repos", "1") - conf.set("repos", "enabled", "*") - - # Create any missing directories - for section, key in [("composer", "yum_conf"), ("composer", "repo_dir"), ("composer", "cache_dir")]: - path = conf.get(section, key) - if not os.path.isdir(os.path.dirname(path)): - os.makedirs(os.path.dirname(path)) - - return conf class Yaps(object): @@ -83,7 +55,7 @@ class ProjectsTest(unittest.TestCase): @classmethod def setUpClass(self): self.tmp_dir = tempfile.mkdtemp(prefix="lorax.test.repo.") - self.config = config(self.tmp_dir) + self.config = configure(root_dir=self.tmp_dir, test_config=True) self.yb = get_base_object(self.config) @classmethod diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index a199bf39..9f60e7d6 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -21,8 +21,10 @@ import unittest from flask import json import pytoml as toml +from pylorax.api.config import configure from pylorax.api.recipes import open_or_create_repo, commit_recipe_directory -from pylorax.api.server import server, GitLock +from pylorax.api.server import server, GitLock, YumLock +from pylorax.api.yumbase import get_base_object from pylorax.sysutils import joinpaths class ServerTestCase(unittest.TestCase): @@ -34,6 +36,10 @@ class ServerTestCase(unittest.TestCase): repo = open_or_create_repo(server.config["REPO_DIR"]) server.config["GITLOCK"] = GitLock(repo=repo, lock=Lock(), dir=repo_dir) + server.config["COMPOSER_CFG"] = configure(root_dir=repo_dir, test_config=True) + yb = get_base_object(server.config["COMPOSER_CFG"]) + server.config["YUMLOCK"] = YumLock(yb=yb, lock=Lock()) + server.config['TESTING'] = True self.server = server.test_client() @@ -352,3 +358,51 @@ class ServerTestCase(unittest.TestCase): {"new": {"Package": {"version": "2.2", "name": "tmux"}}, "old": None}]} self.assertEqual(data, result) + + def test_projects_list(self): + """Test /api/v0/projects/list""" + resp = self.server.get("/api/v0/projects/list") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + projects = data.get("projects") + self.assertEqual(len(projects) > 10, True) + + def test_projects_info(self): + """Test /api/v0/projects/info/""" + resp = self.server.get("/api/v0/projects/info/bash") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + projects = data.get("projects") + self.assertEqual(len(projects), 1) + self.assertEqual(projects[0]["name"], "bash") + self.assertEqual(projects[0]["builds"][0]["source"]["license"], "GPLv3+") + + def test_projects_depsolve(self): + """Test /api/v0/projects/depsolve/""" + resp = self.server.get("/api/v0/projects/depsolve/bash") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + deps = data.get("projects") + self.assertEqual(len(deps) > 10, True) + self.assertEqual(deps[0]["name"], "basesystem") + + def test_modules_list(self): + """Test /api/v0/modules/list""" + resp = self.server.get("/api/v0/modules/list") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + print(data) + modules = data.get("modules") + self.assertEqual(len(modules) > 10, True) + self.assertEqual(modules[0]["group_type"], "rpm") + + def test_modules_info(self): + """Test /api/v0/modules/info""" + resp = self.server.get("/api/v0/modules/info/bash") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + modules = data.get("modules") + self.assertEqual(len(modules), 1) + self.assertEqual(modules[0]["name"], "bash") + self.assertEqual(modules[0]["dependencies"][0]["name"], "basesystem") +