Fix tests in order to run with PostgreSQL

Most of the issues are caused by the use of SQLAlchemy database session. Some
inline comments describe the issues in detail.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
Chenxiong Qi
2019-06-27 12:12:50 +08:00
parent 302c76b90f
commit e49f69f7b5
18 changed files with 758 additions and 634 deletions

View File

@@ -24,11 +24,17 @@
import json
from mock import patch, Mock
import pytest
from module_build_service import conf
from module_build_service.models import make_session
from module_build_service.utils.greenwave import greenwave
from tests import make_module
from tests import clean_database, make_module
class TestGreenwaveQuery():
def setup_method(self, method):
clean_database()
@patch("module_build_service.utils.greenwave.requests")
def test_greenwave_query_decision(self, mock_requests):
resp_status = 200
@@ -55,9 +61,9 @@ class TestGreenwaveQuery():
response.status_code = resp_status
mock_requests.post.return_value = response
fake_build = make_module("pkg:0.1:1:c1", requires_list={"platform": "el8"})
got_response = greenwave.query_decision(fake_build, prod_version="xxxx-8")
with make_session(conf) as db_session:
fake_build = make_module(db_session, "pkg:0.1:1:c1", requires_list={"platform": "el8"})
got_response = greenwave.query_decision(fake_build, prod_version="xxxx-8")
assert got_response == resp_content
assert json.loads(mock_requests.post.call_args_list[0][1]["data"]) == {
@@ -173,7 +179,8 @@ class TestGreenwaveQuery():
mock_requests.get.return_value = responses[0]
mock_requests.post.side_effect = responses[1:]
fake_build = make_module("pkg:0.1:1:c1", requires_list={"platform": "el8"})
result = greenwave.check_gating(fake_build)
with make_session(conf) as db_session:
fake_build = make_module(db_session, "pkg:0.1:1:c1", requires_list={"platform": "el8"})
result = greenwave.check_gating(fake_build)
assert result == policies_satisfied

View File

@@ -20,6 +20,7 @@
from mock import patch, Mock
from module_build_service import conf
from module_build_service.models import make_session
from module_build_service.utils import ursine
from tests import make_module, clean_database
@@ -172,20 +173,31 @@ class TestGetModulemdsFromUrsineContent:
# Defaults to DB resolver, so create fake module builds and store them
# into database to ensure they can be queried.
mmd_name1s2020c = make_module(
"name1:s:2020:c", xmd={"mbs": {"koji_tag": "module-name1-s-2020-c"}})
mmd_name2s2021c = make_module(
"name2:s:2021:c", xmd={"mbs": {"koji_tag": "module-name2-s-2021-c"}})
#
# Switched to call function make_session to create a
# SQLAlchemy database session. Calling db.session causes failure to
# read attributes from a ModuleBuild object at following line calling
# mmd(). The error is ModuleBuild object is not bound to a Session.
# From the behavior of following code, the reason of the error is
# mixing use of db.session and make_session, the latter one is called
# from function ``get_modulemds_from_ursine_content``.
with make_session(conf) as db_session:
mmd_name1s2020c = make_module(
db_session,
"name1:s:2020:c", xmd={"mbs": {"koji_tag": "module-name1-s-2020-c"}})
mmd_name2s2021c = make_module(
db_session,
"name2:s:2021:c", xmd={"mbs": {"koji_tag": "module-name2-s-2021-c"}})
koji_tag = "tag" # It's ok to use arbitrary tag name.
with patch.object(conf, "koji_external_repo_url_prefix", new="http://example.com/"):
modulemds = ursine.get_modulemds_from_ursine_content(koji_tag)
koji_tag = "tag" # It's ok to use arbitrary tag name.
with patch.object(conf, "koji_external_repo_url_prefix", new="http://example.com/"):
modulemds = ursine.get_modulemds_from_ursine_content(koji_tag)
test_nsvcs = [item.get_nsvc() for item in modulemds]
test_nsvcs.sort()
test_nsvcs = [item.get_nsvc() for item in modulemds]
test_nsvcs.sort()
expected_nsvcs = [mmd_name1s2020c.mmd().get_nsvc(), mmd_name2s2021c.mmd().get_nsvc()]
expected_nsvcs.sort()
expected_nsvcs = [mmd_name1s2020c.mmd().get_nsvc(), mmd_name2s2021c.mmd().get_nsvc()]
expected_nsvcs.sort()
session.getExternalRepoList.assert_called_once_with(koji_tag)
assert expected_nsvcs == test_nsvcs
@@ -197,10 +209,10 @@ class TestRecordStreamCollisionModules:
@patch.object(conf, "base_module_names", new=["platform"])
@patch.object(ursine, "find_stream_collision_modules")
def test_nothing_changed_if_no_base_module_is_in_buildrequires(
self, find_stream_collision_modules
self, find_stream_collision_modules, db_session
):
xmd = {"mbs": {"buildrequires": {"modulea": {"stream": "master"}}}}
fake_mmd = make_module("name1:s:2020:c", xmd=xmd, store_to_db=False)
fake_mmd = make_module(db_session, "name1:s:2020:c", xmd=xmd, store_to_db=False)
original_xmd = fake_mmd.get_xmd()
with patch.object(ursine, "log") as log:
@@ -213,7 +225,7 @@ class TestRecordStreamCollisionModules:
@patch.object(conf, "base_module_names", new=["platform"])
@patch("module_build_service.utils.ursine.get_modulemds_from_ursine_content")
def test_mark_handled_even_if_no_modules_in_ursine_content(
self, get_modulemds_from_ursine_content
self, get_modulemds_from_ursine_content, db_session
):
xmd = {
"mbs": {
@@ -223,7 +235,7 @@ class TestRecordStreamCollisionModules:
}
}
}
fake_mmd = make_module("name1:s:2020:c", xmd=xmd, store_to_db=False)
fake_mmd = make_module(db_session, "name1:s:2020:c", xmd=xmd, store_to_db=False)
expected_xmd = fake_mmd.get_xmd()
get_modulemds_from_ursine_content.return_value = []
@@ -242,7 +254,7 @@ class TestRecordStreamCollisionModules:
@patch("module_build_service.resolver.GenericResolver.create")
@patch("module_build_service.builder.KojiModuleBuilder.KojiClientSession")
def test_add_collision_modules(
self, ClientSession, resolver_create, get_modulemds_from_ursine_content
self, ClientSession, resolver_create, get_modulemds_from_ursine_content, db_session
):
xmd = {
"mbs": {
@@ -258,20 +270,24 @@ class TestRecordStreamCollisionModules:
}
}
}
fake_mmd = make_module("name1:s:2020:c", xmd=xmd, store_to_db=False)
fake_mmd = make_module(db_session, "name1:s:2020:c", xmd=xmd, store_to_db=False)
def mock_get_ursine_modulemds(koji_tag):
if koji_tag == "module-rhel-8.0-build":
return [
# This is the one
make_module("modulea:10:20180813041838:5ea3b708", store_to_db=False),
make_module("moduleb:1.0:20180113042038:6ea3b105", store_to_db=False),
make_module(
db_session, "modulea:10:20180813041838:5ea3b708", store_to_db=False),
make_module(
db_session, "moduleb:1.0:20180113042038:6ea3b105", store_to_db=False),
]
if koji_tag == "module-project-1.0-build":
return [
# Both of them are the collided modules
make_module("bar:6:20181013041838:817fa3a8", store_to_db=False),
make_module("foo:2:20180113041838:95f078a1", store_to_db=False),
make_module(
db_session, "bar:6:20181013041838:817fa3a8", store_to_db=False),
make_module(
db_session, "foo:2:20180113041838:95f078a1", store_to_db=False),
]
get_modulemds_from_ursine_content.side_effect = mock_get_ursine_modulemds
@@ -335,22 +351,22 @@ class TestFindStreamCollisionModules:
assert not ursine.find_stream_collision_modules({}, "koji_tag")
@patch("module_build_service.utils.ursine.get_modulemds_from_ursine_content")
def test_no_collisions_found(self, get_modulemds_from_ursine_content):
def test_no_collisions_found(self, get_modulemds_from_ursine_content, db_session):
xmd_mbs_buildrequires = {"modulea": {"stream": "master"}, "moduleb": {"stream": "10"}}
get_modulemds_from_ursine_content.return_value = [
make_module("moduler:1:1:c1", store_to_db=False),
make_module("modules:2:1:c2", store_to_db=False),
make_module("modulet:3:1:c3", store_to_db=False),
make_module(db_session, "moduler:1:1:c1", store_to_db=False),
make_module(db_session, "modules:2:1:c2", store_to_db=False),
make_module(db_session, "modulet:3:1:c3", store_to_db=False),
]
assert [] == ursine.find_stream_collision_modules(xmd_mbs_buildrequires, "koji_tag")
@patch("module_build_service.utils.ursine.get_modulemds_from_ursine_content")
def test_collision_modules_are_found(self, get_modulemds_from_ursine_content):
def test_collision_modules_are_found(self, get_modulemds_from_ursine_content, db_session):
xmd_mbs_buildrequires = {"modulea": {"stream": "master"}, "moduleb": {"stream": "10"}}
fake_modules = [
make_module("moduler:1:1:c1", store_to_db=False),
make_module("moduleb:6:1:c2", store_to_db=False),
make_module("modulet:3:1:c3", store_to_db=False),
make_module(db_session, "moduler:1:1:c1", store_to_db=False),
make_module(db_session, "moduleb:6:1:c2", store_to_db=False),
make_module(db_session, "modulet:3:1:c3", store_to_db=False),
]
get_modulemds_from_ursine_content.return_value = fake_modules

View File

@@ -446,26 +446,30 @@ class TestUtils:
assert release_one == "module+2+b8645bbb"
assert release_two == "module+2+17e35784"
def test_get_rpm_release_platform_stream(self):
scheduler_init_data(1)
build_one = models.ModuleBuild.query.get(2)
def test_get_rpm_release_platform_stream(self, db_session):
scheduler_init_data(db_session, 1)
build_one = db_session.query(models.ModuleBuild).get(2)
release = module_build_service.utils.get_rpm_release(build_one)
assert release == "module+f28+2+814cfa39"
def test_get_rpm_release_platform_stream_override(self):
scheduler_init_data(1)
def test_get_rpm_release_platform_stream_override(self, db_session):
scheduler_init_data(db_session, 1)
# Set the disttag_marking override on the platform
platform = models.ModuleBuild.query.filter_by(name="platform", stream="f28").first()
platform = (
db_session.query(models.ModuleBuild)
.filter_by(name="platform", stream="f28")
.first()
)
platform_mmd = platform.mmd()
platform_xmd = platform_mmd.get_xmd()
platform_xmd["mbs"]["disttag_marking"] = "fedora28"
platform_mmd.set_xmd(platform_xmd)
platform.modulemd = mmd_to_str(platform_mmd)
db.session.add(platform)
db.session.commit()
db_session.add(platform)
db_session.commit()
build_one = models.ModuleBuild.query.get(2)
build_one = db_session.query(models.ModuleBuild).get(2)
release = module_build_service.utils.get_rpm_release(build_one)
assert release == "module+fedora28+2+814cfa39"
@@ -474,20 +478,20 @@ class TestUtils:
new_callable=mock.PropertyMock,
return_value=["build"],
)
def test_get_rpm_release_metadata_br_stream_override(self, mock_admmn):
def test_get_rpm_release_metadata_br_stream_override(self, mock_admmn, db_session):
"""
Test that when a module buildrequires a module in conf.allowed_privileged_module_names,
and that module has the xmd.mbs.disttag_marking field set, it should influence the disttag.
"""
scheduler_init_data(1)
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)
module_build_service.utils.import_mmd(db.session, metadata_mmd)
module_build_service.utils.import_mmd(db_session, metadata_mmd)
build_one = models.ModuleBuild.query.get(2)
build_one = db_session.query(models.ModuleBuild).get(2)
mmd = build_one.mmd()
deps = mmd.get_dependencies()[0]
deps.add_buildtime_stream("build", "product1.2")
@@ -501,8 +505,8 @@ class TestUtils:
}
mmd.set_xmd(xmd)
build_one.modulemd = mmd_to_str(mmd)
db.session.add(build_one)
db.session.commit()
db_session.add(build_one)
db_session.commit()
release = module_build_service.utils.get_rpm_release(build_one)
assert release == "module+product12+2+814cfa39"
@@ -516,19 +520,19 @@ class TestUtils:
assert release_one == "scrmod+2+b8645bbb"
assert release_two == "scrmod+2+17e35784"
def test_get_rpm_release_platform_stream_scratch(self):
scheduler_init_data(1, scratch=True)
build_one = models.ModuleBuild.query.get(2)
def test_get_rpm_release_platform_stream_scratch(self, db_session):
scheduler_init_data(db_session, 1, scratch=True)
build_one = db_session.query(models.ModuleBuild).get(2)
release = module_build_service.utils.get_rpm_release(build_one)
assert release == "scrmod+f28+2+814cfa39"
@patch("module_build_service.utils.submit.get_build_arches")
def test_record_module_build_arches(self, get_build_arches):
def test_record_module_build_arches(self, get_build_arches, db_session):
get_build_arches.return_value = ["x86_64", "i686"]
scheduler_init_data(1)
build = models.ModuleBuild.query.get(2)
scheduler_init_data(db_session, 1)
build = db_session.query(models.ModuleBuild).get(2)
build.arches = []
module_build_service.utils.record_module_build_arches(build.mmd(), build, db.session)
module_build_service.utils.record_module_build_arches(build.mmd(), build, db_session)
arches = set([arch.name for arch in build.arches])
assert arches == set(get_build_arches.return_value)
@@ -896,15 +900,15 @@ class TestUtils:
is_eol = module_build_service.utils.submit._is_eol_in_pdc("mariadb", "10.1")
assert is_eol
def test_get_prefixed_version_f28(self):
scheduler_init_data(1)
build_one = models.ModuleBuild.query.get(2)
def test_get_prefixed_version_f28(self, db_session):
scheduler_init_data(db_session, 1)
build_one = db_session.query(models.ModuleBuild).get(2)
v = module_build_service.utils.submit.get_prefixed_version(build_one.mmd())
assert v == 2820180205135154
def test_get_prefixed_version_fl701(self):
scheduler_init_data(1)
build_one = models.ModuleBuild.query.get(2)
def test_get_prefixed_version_fl701(self, db_session):
scheduler_init_data(db_session, 1)
build_one = db_session.query(models.ModuleBuild).get(2)
mmd = build_one.mmd()
xmd = mmd.get_xmd()
xmd["mbs"]["buildrequires"]["platform"]["stream"] = "fl7.0.1-beta"
@@ -919,18 +923,19 @@ class TestUtils:
build adds new MSE build (it means there are new expanded
buildrequires).
"""
build = make_module("foo:stream:0:c1", {}, {})
assert build.state == models.BUILD_STATES["ready"]
with models.make_session(conf) as db_session:
build = make_module(db_session, "foo:stream:0:c1", {}, {})
assert build.state == models.BUILD_STATES["ready"]
mmd1 = build.mmd()
mmd2 = build.mmd()
mmd1 = build.mmd()
mmd2 = build.mmd()
mmd2.set_context("c2")
generate_expanded_mmds.return_value = [mmd1, mmd2]
# Create a copy of mmd1 without xmd.mbs, since that will cause validate_mmd to fail
mmd1_copy = mmd1.copy()
mmd1_copy.set_xmd({})
builds = module_build_service.utils.submit_module_build("foo", mmd1_copy, {})
ret = {b.mmd().get_context(): b.state for b in builds}
assert ret == {"c1": models.BUILD_STATES["ready"], "c2": models.BUILD_STATES["init"]}
@@ -1268,7 +1273,6 @@ class TestBatches:
# The component was reused when the batch first started
building_component = module_build.current_batch()[0]
building_component.state = koji.BUILD_STATES["BUILDING"]
building_component.reused_component_id = 123
db.session.commit()
builder = mock.MagicMock()

View File

@@ -51,28 +51,30 @@ class TestUtilsModuleStreamExpansion:
]
return nsvcs
def _generate_default_modules(self):
def _generate_default_modules(self, db_session):
"""
Generates gtk:1, gtk:2, foo:1 and foo:2 modules requiring the
platform:f28 and platform:f29 modules.
"""
platform_f28 = make_module("platform:f28:0:c10", {}, {})
platform_f29 = make_module("platform:f29:0:c11", {}, {})
make_module("gtk:1:0:c2", {"platform": ["f28"]}, {}, platform_f28)
make_module("gtk:1:0:c3", {"platform": ["f29"]}, {}, platform_f29)
make_module("gtk:2:0:c4", {"platform": ["f28"]}, {}, platform_f28)
make_module("gtk:2:0:c5", {"platform": ["f29"]}, {}, platform_f29)
make_module("foo:1:0:c2", {"platform": ["f28"]}, {}, platform_f28)
make_module("foo:1:0:c3", {"platform": ["f29"]}, {}, platform_f29)
make_module("foo:2:0:c4", {"platform": ["f28"]}, {}, platform_f28)
make_module("foo:2:0:c5", {"platform": ["f29"]}, {}, platform_f29)
make_module("app:1:0:c6", {"platform": ["f29"]}, {}, platform_f29)
platform_f28 = make_module(db_session, "platform:f28:0:c10", {}, {})
platform_f29 = make_module(db_session, "platform:f29:0:c11", {}, {})
make_module(db_session, "gtk:1:0:c2", {"platform": ["f28"]}, {}, platform_f28)
make_module(db_session, "gtk:1:0:c3", {"platform": ["f29"]}, {}, platform_f29)
make_module(db_session, "gtk:2:0:c4", {"platform": ["f28"]}, {}, platform_f28)
make_module(db_session, "gtk:2:0:c5", {"platform": ["f29"]}, {}, platform_f29)
make_module(db_session, "foo:1:0:c2", {"platform": ["f28"]}, {}, platform_f28)
make_module(db_session, "foo:1:0:c3", {"platform": ["f29"]}, {}, platform_f29)
make_module(db_session, "foo:2:0:c4", {"platform": ["f28"]}, {}, platform_f28)
make_module(db_session, "foo:2:0:c5", {"platform": ["f29"]}, {}, platform_f29)
make_module(db_session, "app:1:0:c6", {"platform": ["f29"]}, {}, platform_f29)
def test_generate_expanded_mmds_context(self):
self._generate_default_modules()
def test_generate_expanded_mmds_context(self, db_session):
self._generate_default_modules(db_session)
module_build = make_module(
"app:1:0:c1", {"gtk": ["1", "2"]}, {"platform": ["f28"], "gtk": ["1", "2"]})
mmds = module_build_service.utils.generate_expanded_mmds(db.session, module_build.mmd())
db_session, "app:1:0:c1", {"gtk": ["1", "2"]}, {"platform": ["f28"], "gtk": ["1", "2"]}
)
mmds = module_build_service.utils.generate_expanded_mmds(
db_session, module_build.mmd())
contexts = set([mmd.get_context() for mmd in mmds])
assert set(["e1e005fb", "ce132a1e"]) == contexts
@@ -153,10 +155,11 @@ class TestUtilsModuleStreamExpansion:
],
)
def test_generate_expanded_mmds_buildrequires(
self, requires, build_requires, stream_ambigous, expected_xmd, expected_buildrequires
self, requires, build_requires, stream_ambigous, expected_xmd, expected_buildrequires,
db_session
):
self._generate_default_modules()
module_build = make_module("app:1:0:c1", requires, build_requires)
self._generate_default_modules(db_session)
module_build = make_module(db_session, "app:1:0:c1", requires, build_requires)
# Check that generate_expanded_mmds raises an exception if stream is ambigous
# and also that it does not raise an exception otherwise.
@@ -236,10 +239,10 @@ class TestUtilsModuleStreamExpansion:
),
],
)
def test_generate_expanded_mmds_requires(self, requires, build_requires, expected):
self._generate_default_modules()
module_build = make_module("app:1:0:c1", requires, build_requires)
mmds = module_build_service.utils.generate_expanded_mmds(db.session, module_build.mmd())
def test_generate_expanded_mmds_requires(self, requires, build_requires, expected, db_session):
self._generate_default_modules(db_session)
module_build = make_module(db_session, "app:1:0:c1", requires, build_requires)
mmds = module_build_service.utils.generate_expanded_mmds(db_session, module_build.mmd())
requires_per_mmd = set()
for mmd in mmds:
@@ -318,28 +321,28 @@ class TestUtilsModuleStreamExpansion:
),
],
)
def test_get_required_modules_simple(self, requires, build_requires, expected):
module_build = make_module("app:1:0:c1", requires, build_requires)
self._generate_default_modules()
def test_get_required_modules_simple(self, requires, build_requires, expected, db_session):
module_build = make_module(db_session, "app:1:0:c1", requires, build_requires)
self._generate_default_modules(db_session)
nsvcs = self._get_mmds_required_by_module_recursively(module_build)
assert set(nsvcs) == set(expected)
def _generate_default_modules_recursion(self):
def _generate_default_modules_recursion(self, db_session):
"""
Generates the gtk:1 module requiring foo:1 module requiring bar:1
and lorem:1 modules which require base:f29 module requiring
platform:f29 module :).
"""
base_module = make_module("platform:f29:0:c11", {}, {})
make_module("gtk:1:0:c2", {"foo": ["unknown"]}, {}, base_module)
make_module("gtk:1:1:c2", {"foo": ["1"]}, {}, base_module)
make_module("foo:1:0:c2", {"bar": ["unknown"]}, {}, base_module)
make_module("foo:1:1:c2", {"bar": ["1"], "lorem": ["1"]}, {}, base_module)
make_module("bar:1:0:c2", {"base": ["unknown"]}, {}, base_module)
make_module("bar:1:1:c2", {"base": ["f29"]}, {}, base_module)
make_module("lorem:1:0:c2", {"base": ["unknown"]}, {}, base_module)
make_module("lorem:1:1:c2", {"base": ["f29"]}, {}, base_module)
make_module("base:f29:0:c3", {"platform": ["f29"]}, {}, base_module)
base_module = make_module(db_session, "platform:f29:0:c11", {}, {})
make_module(db_session, "gtk:1:0:c2", {"foo": ["unknown"]}, {}, base_module)
make_module(db_session, "gtk:1:1:c2", {"foo": ["1"]}, {}, base_module)
make_module(db_session, "foo:1:0:c2", {"bar": ["unknown"]}, {}, base_module)
make_module(db_session, "foo:1:1:c2", {"bar": ["1"], "lorem": ["1"]}, {}, base_module)
make_module(db_session, "bar:1:0:c2", {"base": ["unknown"]}, {}, base_module)
make_module(db_session, "bar:1:1:c2", {"base": ["f29"]}, {}, base_module)
make_module(db_session, "lorem:1:0:c2", {"base": ["unknown"]}, {}, base_module)
make_module(db_session, "lorem:1:1:c2", {"base": ["f29"]}, {}, base_module)
make_module(db_session, "base:f29:0:c3", {"platform": ["f29"]}, {}, base_module)
@pytest.mark.parametrize(
"requires,build_requires,expected",
@@ -363,25 +366,25 @@ class TestUtilsModuleStreamExpansion:
),
],
)
def test_get_required_modules_recursion(self, requires, build_requires, expected):
module_build = make_module("app:1:0:c1", requires, build_requires)
self._generate_default_modules_recursion()
def test_get_required_modules_recursion(self, requires, build_requires, expected, db_session):
module_build = make_module(db_session, "app:1:0:c1", requires, build_requires)
self._generate_default_modules_recursion(db_session)
nsvcs = self._get_mmds_required_by_module_recursively(module_build)
assert set(nsvcs) == set(expected)
def _generate_default_modules_modules_multiple_stream_versions(self):
def _generate_default_modules_modules_multiple_stream_versions(self, db_session):
"""
Generates the gtk:1 module requiring foo:1 module requiring bar:1
and lorem:1 modules which require base:f29 module requiring
platform:f29 module :).
"""
f290000 = make_module("platform:f29.0.0:0:c11", {}, {}, virtual_streams=["f29"])
f290100 = make_module("platform:f29.1.0:0:c11", {}, {}, virtual_streams=["f29"])
f290200 = make_module("platform:f29.2.0:0:c11", {}, {}, virtual_streams=["f29"])
make_module("gtk:1:0:c2", {"platform": ["f29"]}, {}, f290000)
make_module("gtk:1:1:c2", {"platform": ["f29"]}, {}, f290100)
make_module("gtk:1:2:c2", {"platform": ["f29"]}, {}, f290100)
make_module("gtk:1:3:c2", {"platform": ["f29"]}, {}, f290200)
f290000 = make_module(db_session, "platform:f29.0.0:0:c11", {}, {}, virtual_streams=["f29"])
f290100 = make_module(db_session, "platform:f29.1.0:0:c11", {}, {}, virtual_streams=["f29"])
f290200 = make_module(db_session, "platform:f29.2.0:0:c11", {}, {}, virtual_streams=["f29"])
make_module(db_session, "gtk:1:0:c2", {"platform": ["f29"]}, {}, f290000)
make_module(db_session, "gtk:1:1:c2", {"platform": ["f29"]}, {}, f290100)
make_module(db_session, "gtk:1:2:c2", {"platform": ["f29"]}, {}, f290100)
make_module(db_session, "gtk:1:3:c2", {"platform": ["f29"]}, {}, f290200)
@pytest.mark.parametrize(
"requires,build_requires,expected",
@@ -393,9 +396,11 @@ class TestUtilsModuleStreamExpansion:
)
],
)
def test_get_required_modules_stream_versions(self, requires, build_requires, expected):
module_build = make_module("app:1:0:c1", requires, build_requires)
self._generate_default_modules_modules_multiple_stream_versions()
def test_get_required_modules_stream_versions(
self, requires, build_requires, expected, db_session
):
module_build = make_module(db_session, "app:1:0:c1", requires, build_requires)
self._generate_default_modules_modules_multiple_stream_versions(db_session)
nsvcs = self._get_mmds_required_by_module_recursively(module_build)
assert set(nsvcs) == set(expected)
@@ -424,7 +429,7 @@ class TestUtilsModuleStreamExpansion:
assert actual == expected
@pytest.mark.parametrize("virtual_streams", (None, ["f29"], ["lp29"]))
def test__get_base_module_mmds_virtual_streams(self, virtual_streams):
def test__get_base_module_mmds_virtual_streams(self, virtual_streams, db_session):
"""Ensure the correct results are returned without duplicates."""
init_data(data_size=1, multiple_stream_versions=True)
mmd = module_build_service.utils.load_mmd_file(
@@ -437,7 +442,7 @@ class TestUtilsModuleStreamExpansion:
mmd.remove_dependencies(deps)
mmd.add_dependencies(new_deps)
make_module("platform:lp29.1.1:12:c11", {}, {}, virtual_streams=virtual_streams)
make_module(db_session, "platform:lp29.1.1:12:c11", {}, {}, virtual_streams=virtual_streams)
mmds = module_build_service.utils.mse._get_base_module_mmds(mmd)
if virtual_streams == ["f29"]: