Reuse function read_staged_data

In addition, reuse staged_data_filename to construct file and directory name.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
Chenxiong Qi
2019-06-29 17:08:52 +08:00
parent a80f15a6d3
commit c15a7cadf3
13 changed files with 104 additions and 160 deletions

View File

@@ -31,6 +31,7 @@ import module_build_service.utils
import module_build_service.scm
from module_build_service import models, conf
from module_build_service.errors import ProgrammingError, ValidationError, UnprocessableEntity
from module_build_service.utils.general import load_mmd
from tests import (
reuse_component_init_data,
db,
@@ -39,7 +40,7 @@ from tests import (
init_data,
scheduler_init_data,
make_module,
)
read_staged_data, staged_data_filename)
import mock
import koji
import pytest
@@ -74,9 +75,7 @@ class FakeSCM(object):
def checkout(self, temp_dir):
self.sourcedir = path.join(temp_dir, self.name)
mkdir(self.sourcedir)
base_dir = path.abspath(path.dirname(__file__))
copyfile(
path.join(base_dir, "..", "staged_data", self.mmd_filename), self.get_module_yaml())
copyfile(staged_data_filename(self.mmd_filename), self.get_module_yaml())
return self.sourcedir
@@ -315,7 +314,7 @@ class TestUtils:
def test_get_build_arches(self, ClientSession):
session = ClientSession.return_value
session.getTag.return_value = {"arches": "ppc64le"}
mmd = load_mmd_file(path.join(BASE_DIR, "..", "staged_data", "formatted_testmodule.yaml"))
mmd = load_mmd(read_staged_data("formatted_testmodule"))
r = module_build_service.utils.get_build_arches(mmd, conf)
assert r == ["ppc64le"]
@@ -326,7 +325,7 @@ class TestUtils:
"""
session = ClientSession.return_value
session.getTag.return_value = {"arches": ""}
mmd = load_mmd_file(path.join(BASE_DIR, "..", "staged_data", "formatted_testmodule.yaml"))
mmd = load_mmd(read_staged_data("formatted_testmodule"))
r = module_build_service.utils.get_build_arches(mmd, conf)
assert set(r) == set(conf.arches)
@@ -336,7 +335,7 @@ class TestUtils:
return_value=["testmodule"],
)
def test_get_build_arches_koji_tag_arches(self, cfg):
mmd = load_mmd_file(path.join(BASE_DIR, "..", "staged_data", "formatted_testmodule.yaml"))
mmd = load_mmd(read_staged_data("formatted_testmodule"))
xmd = mmd.get_xmd()
xmd["mbs"]["koji_tag_arches"] = ["ppc64", "ppc64le"]
mmd.set_xmd(xmd)
@@ -346,7 +345,7 @@ class TestUtils:
@patch.object(conf, "base_module_arches", new={"platform:xx": ["x86_64", "i686"]})
def test_get_build_arches_base_module_override(self):
mmd = load_mmd_file(path.join(BASE_DIR, "..", "staged_data", "formatted_testmodule.yaml"))
mmd = load_mmd(read_staged_data("formatted_testmodule"))
xmd = mmd.get_xmd()
mbs_options = xmd["mbs"] if "mbs" in xmd.keys() else {}
mbs_options["buildrequires"] = {"platform": {"stream": "xx"}}
@@ -358,7 +357,7 @@ class TestUtils:
@pytest.mark.parametrize("context", ["c1", None])
def test_import_mmd_contexts(self, context):
mmd = load_mmd_file(path.join(BASE_DIR, "..", "staged_data", "formatted_testmodule.yaml"))
mmd = load_mmd(read_staged_data("formatted_testmodule"))
mmd.set_context(context)
xmd = mmd.get_xmd()
@@ -376,7 +375,7 @@ class TestUtils:
assert build.context == models.DEFAULT_MODULE_CONTEXT
def test_import_mmd_multiple_dependencies(self):
mmd = load_mmd_file(path.join(BASE_DIR, "..", "staged_data", "formatted_testmodule.yaml"))
mmd = load_mmd(read_staged_data("formatted_testmodule"))
mmd.add_dependencies(mmd.get_dependencies()[0].copy())
expected_error = "The imported module's dependencies list should contain just one element"
@@ -385,7 +384,7 @@ class TestUtils:
assert str(e.value) == expected_error
def test_import_mmd_no_xmd_buildrequires(self):
mmd = load_mmd_file(path.join(BASE_DIR, "..", "staged_data", "formatted_testmodule.yaml"))
mmd = load_mmd(read_staged_data("formatted_testmodule"))
xmd = mmd.get_xmd()
del xmd["mbs"]["buildrequires"]
mmd.set_xmd(xmd)
@@ -399,7 +398,7 @@ class TestUtils:
assert str(e.value) == expected_error
def test_import_mmd_minimal_xmd_from_local_repository(self):
mmd = load_mmd_file(path.join(BASE_DIR, "..", "staged_data", "formatted_testmodule.yaml"))
mmd = load_mmd(read_staged_data("formatted_testmodule"))
xmd = mmd.get_xmd()
xmd["mbs"] = {}
xmd["mbs"]["koji_tag"] = "repofile:///etc/yum.repos.d/fedora-modular.repo"
@@ -423,7 +422,7 @@ class TestUtils:
)
def test_import_mmd_base_module(self, stream, disttag_marking, error_msg):
clean_database(add_platform_module=False)
mmd = load_mmd_file(path.join(BASE_DIR, "..", "staged_data", "platform.yaml"))
mmd = load_mmd(read_staged_data("platform"))
mmd = mmd.copy(mmd.get_module_name(), stream)
if disttag_marking:
@@ -484,11 +483,7 @@ class TestUtils:
and that module has the xmd.mbs.disttag_marking field set, it should influence the disttag.
"""
scheduler_init_data(db_session, 1)
mmd_path = path.abspath(
path.join(
__file__, path.pardir, path.pardir, "staged_data", "build_metadata_module.yaml")
)
metadata_mmd = module_build_service.utils.load_mmd_file(mmd_path)
metadata_mmd = load_mmd(read_staged_data("build_metadata_module"))
module_build_service.utils.import_mmd(db_session, metadata_mmd)
build_one = db_session.query(models.ModuleBuild).get(2)
@@ -565,7 +560,7 @@ class TestUtils:
return hashes_returned[ref]
mocked_scm.return_value.get_latest = mocked_get_latest
mmd = load_mmd_file(path.join(BASE_DIR, "..", "staged_data", "testmodule.yaml"))
mmd = load_mmd(read_staged_data("testmodule"))
# Modify the component branches so we can identify them later on
mmd.get_rpm_component("perl-Tangerine").set_ref("f28")
mmd.get_rpm_component("tangerine").set_ref("f27")
@@ -724,8 +719,7 @@ class TestUtils:
"fbed359411a1baa08d4a88e0d12d426fbf8f602c",
]
testmodule_mmd_path = path.join(BASE_DIR, "..", "staged_data", "testmodule.yaml")
mmd = load_mmd_file(testmodule_mmd_path)
mmd = load_mmd(read_staged_data("testmodule"))
mmd = mmd.copy("testmodule-variant", "master")
module_build = module_build_service.models.ModuleBuild()
module_build.name = "testmodule-variant"
@@ -770,8 +764,7 @@ class TestUtils:
"dbed259411a1baa08d4a88e0d12d426fbf8f6037",
]
testmodule_mmd_path = path.join(BASE_DIR, "..", "staged_data", "testmodule.yaml")
mmd = load_mmd_file(testmodule_mmd_path)
mmd = load_mmd(read_staged_data("testmodule"))
# Set the module name and stream
mmd = mmd.copy("testmodule", "master")
module_build = module_build_service.models.ModuleBuild()
@@ -811,7 +804,7 @@ class TestUtils:
"dbed259411a1baa08d4a88e0d12d426fbf8f6037",
]
testmodule_mmd_path = path.join(BASE_DIR, "..", "staged_data", "testmodule.yaml")
testmodule_mmd_path = staged_data_filename("testmodule.yaml")
test_archs = ["powerpc", "i486"]
mmd1 = load_mmd_file(testmodule_mmd_path)
@@ -848,13 +841,11 @@ class TestUtils:
test_datetime = datetime(2019, 2, 14, 11, 11, 45, 42968)
testmodule_mmd_path = path.join(BASE_DIR, "..", "staged_data", "testmodule.yaml")
mmd1 = load_mmd_file(testmodule_mmd_path)
mmd = load_mmd(read_staged_data("testmodule"))
with patch("module_build_service.utils.submit.datetime") as dt:
dt.utcnow.return_value = test_datetime
module_build_service.utils.format_mmd(mmd1, None, build, db.session)
module_build_service.utils.format_mmd(mmd, None, build, db.session)
assert build.time_modified == test_datetime
@@ -1304,7 +1295,7 @@ class TestBatches:
@patch(
"module_build_service.config.Config.mock_resultsdir",
new_callable=mock.PropertyMock,
return_value=path.join(BASE_DIR, "..", "staged_data", "local_builds"),
return_value=staged_data_filename("local_builds")
)
@patch(
"module_build_service.config.Config.system", new_callable=mock.PropertyMock, return_value="mock"
@@ -1404,8 +1395,7 @@ class TestOfflineLocalBuilds:
with patch("dnf.Base") as dnf_base:
repo = mock.MagicMock()
repo.repofile = "/etc/yum.repos.d/foo.repo"
tm_path = path.join(BASE_DIR, "..", "staged_data", "formatted_testmodule.yaml")
mmd = load_mmd_file(tm_path)
mmd = load_mmd(read_staged_data("formatted_testmodule"))
repo.get_metadata_content.return_value = mmd_to_str(mmd)
base = dnf_base.return_value
base.repos = {"reponame": repo}