mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-25 11:12:01 +08:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user