Change yaps_to_module to proj_to_module

It now gets a project dict instead of a yum object, so change it to use
the dict's "name" and update the tests.

Related: rhbz#1657055
This commit is contained in:
Brian C. Lane 2018-12-07 14:41:23 -08:00
parent 0e54983be8
commit b449d1cd81
2 changed files with 9 additions and 9 deletions

View File

@ -137,17 +137,17 @@ def tm_to_dep(tm):
"arch": tm.arch}
def yaps_to_module(yaps):
def proj_to_module(proj):
"""Extract the name from a YumAvailablePackageSqlite object
:param yaps: Yum object with package details
:type yaps: YumAvailablePackageSqlite
:param proj: Project details
:type proj: dict
:returns: A dict with name, and group_type
:rtype: dict
group_type is hard-coded to "rpm"
"""
return {"name": yaps.name,
return {"name": proj["name"],
"group_type": "rpm"}
@ -405,7 +405,7 @@ def modules_list(yb, module_names):
and sets the type to "rpm"
"""
projs = _unique_dicts(projects_info(yb, module_names), key=lambda p: p["name"].lower())
return list(map(yaps_to_module, projs))
return list(map(proj_to_module, projs))
def _unique_dicts(lst, key):
"""Return a new list of dicts, only including one match of key(d)

View File

@ -28,7 +28,7 @@ from yum.packages import PackageObject
from pylorax.sysutils import joinpaths
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 tm_to_dep, proj_to_module, projects_list, projects_info, projects_depsolve
from pylorax.api.projects import modules_list, modules_info, ProjectsError, dep_evra, dep_nevra
from pylorax.api.projects import repo_to_source, get_repo_sources, delete_repo_source, source_to_repo
from pylorax.api.projects import yum_repo_to_file_repo, filterVersionGlob, projects_depsolve_with_size
@ -140,12 +140,12 @@ class ProjectsTest(unittest.TestCase):
tm = TM()
self.assertEqual(tm_to_dep(tm), result)
def test_yaps_to_module(self):
def test_proj_to_module(self):
result = {"name":"name",
"group_type":"rpm"}
y = Yaps()
self.assertEqual(yaps_to_module(y), result)
p = yaps_to_project_info(Yaps())
self.assertEqual(proj_to_module(p), result)
def test_dep_evra(self):
dep = {"arch": "noarch",