Fix mmd.copy calls to support PackagerV3

Fixes #1685
This commit is contained in:
Brendan Reilly
2021-03-08 14:24:45 -05:00
parent 8f0e35abe4
commit d0579a16c1
5 changed files with 129 additions and 38 deletions

View File

@@ -4,7 +4,7 @@ document: modulemd-packager
version: 3
data:
name: foo
stream: latest
stream: master
summary: An example module
description: >-
A module for the demonstration of the metadata format. Also,

View File

@@ -4,7 +4,9 @@ from __future__ import absolute_import
import mock
from module_build_service.common.submit import _is_eol_in_pdc
from module_build_service.common.modulemd import Modulemd
from module_build_service.common.submit import _is_eol_in_pdc, fetch_mmd
from tests.test_web.test_views import FakeSCM
@mock.patch("module_build_service.common.submit.requests")
@@ -32,3 +34,31 @@ def test_pdc_eol_check(requests):
is_eol = _is_eol_in_pdc("mariadb", "10.1")
assert is_eol
@mock.patch("module_build_service.common.scm.SCM")
def test_fetch_mmd(mocked_scm):
""" Test behavior for fetch_mmd """
FakeSCM(
mocked_scm,
"testmodule",
"testmodule.yaml",
"620ec77321b2ea7b0d67d82992dda3e1d67055b4")
mmd, scm = fetch_mmd('testurl')
assert isinstance(mmd, Modulemd.ModuleStream)
@mock.patch("module_build_service.common.scm.SCM")
def test_fetch_mmd_packager_v3(mocked_scm):
""" Test PackagerV3 behavior for fetch_mmd """
FakeSCM(
mocked_scm,
"foo",
"v3/mmd_packager.yaml",
"620ec77321b2ea7b0d67d82992dda3e1d67055b4")
mmd, scm = fetch_mmd('testurl')
assert not isinstance(mmd, Modulemd.ModuleStream)

View File

@@ -300,6 +300,36 @@ class TestUtilsComponentReuse:
assert username_arg == username
rmtree(module_dir)
@mock.patch("module_build_service.web.submit.submit_module_build")
def test_submit_module_build_from_yaml_packager_v3(self, mock_submit):
"""
Tests local module build from a yaml file with the skiptests option
Args:
mock_submit (MagickMock): mocked function submit_module_build, which we then
inspect if it was called with correct arguments
"""
module_dir = tempfile.mkdtemp()
modulemd_yaml = read_staged_data("v3/mmd_packager")
modulemd_file_path = path.join(module_dir, "testmodule.yaml")
username = "test"
stream = "dev"
with io.open(modulemd_file_path, "w", encoding="utf-8") as fd:
fd.write(modulemd_yaml)
with open(modulemd_file_path, "rb") as fd:
handle = FileStorage(fd)
submit_module_build_from_yaml(
db_session, username, handle, {}, stream=stream, skiptests=False)
mock_submit_args = mock_submit.call_args[0]
username_arg = mock_submit_args[1]
mmd_arg = mock_submit_args[2]
assert mmd_arg.get_stream_name() == stream
assert username_arg == username
rmtree(module_dir)
@mock.patch("module_build_service.web.submit.generate_expanded_mmds")
def test_submit_build_new_mse_build(self, generate_expanded_mmds):
"""