mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-03 05:03:43 +08:00
Remove the sys.modules patches in the tests
This is no longer needed since https://pagure.io/fm-orchestrator/pull-request/1563
This commit is contained in:
@@ -209,8 +209,7 @@ class TestBuild:
|
||||
koji_session.getUser.return_value = GET_USER_RV
|
||||
koji_session.getTag.return_value = {"id": 123}
|
||||
|
||||
with patch.dict("sys.modules", krbV=Mock()):
|
||||
self.cg._tag_cg_build()
|
||||
self.cg._tag_cg_build()
|
||||
|
||||
koji_session.getTag.assert_called_once_with(self.cg.module.cg_build_koji_tag)
|
||||
koji_session.tagBuild.assert_called_once_with(123, "nginx-0-2.10e50d06")
|
||||
@@ -225,8 +224,7 @@ class TestBuild:
|
||||
koji_session.getUser.return_value = GET_USER_RV
|
||||
koji_session.getTag.side_effect = [{}, {"id": 123}]
|
||||
|
||||
with patch.dict("sys.modules", krbV=Mock()):
|
||||
self.cg._tag_cg_build()
|
||||
self.cg._tag_cg_build()
|
||||
|
||||
assert koji_session.getTag.mock_calls == [
|
||||
call(self.cg.module.cg_build_koji_tag),
|
||||
@@ -245,8 +243,7 @@ class TestBuild:
|
||||
koji_session.getTag.side_effect = [{}, {"id": 123}]
|
||||
|
||||
self.cg.module.cg_build_koji_tag = None
|
||||
with patch.dict("sys.modules", krbV=Mock()):
|
||||
self.cg._tag_cg_build()
|
||||
self.cg._tag_cg_build()
|
||||
|
||||
koji_session.tagBuild.assert_not_called()
|
||||
# tagBuild requires logging into a session in advance.
|
||||
@@ -259,8 +256,7 @@ class TestBuild:
|
||||
koji_session.getUser.return_value = GET_USER_RV
|
||||
koji_session.getTag.side_effect = [{}, {}]
|
||||
|
||||
with patch.dict("sys.modules", krbV=Mock()):
|
||||
self.cg._tag_cg_build()
|
||||
self.cg._tag_cg_build()
|
||||
|
||||
koji_session.tagBuild.assert_not_called()
|
||||
# tagBuild requires logging into a session in advance.
|
||||
@@ -970,8 +966,7 @@ class TestBuild:
|
||||
""" Tests whether build is still tagged even if there's an exception in CGImport """
|
||||
cl_session.return_value.CGImport = Mock(
|
||||
side_effect=koji.GenericError("Build already exists asdv"))
|
||||
with patch.dict("sys.modules", krbV=Mock()):
|
||||
self.cg.koji_import()
|
||||
self.cg.koji_import()
|
||||
tagger.assert_called()
|
||||
|
||||
def test_fill_in_rpms_list_debuginfo_deps(self):
|
||||
|
||||
@@ -430,8 +430,7 @@ class TestKojiBuilder:
|
||||
],
|
||||
]
|
||||
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
assert weights == {"httpd": 2, "apr": 2}
|
||||
|
||||
expected_calls = [mock.call(456), mock.call(789)]
|
||||
@@ -454,8 +453,7 @@ class TestKojiBuilder:
|
||||
]
|
||||
session.getAverageBuildDuration.return_value = None
|
||||
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
assert weights == {"httpd": 2, "apr": 1.5}
|
||||
|
||||
expected_calls = [mock.call(456)]
|
||||
@@ -476,8 +474,7 @@ class TestKojiBuilder:
|
||||
]
|
||||
session.getAverageBuildDuration.return_value = None
|
||||
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
assert weights == {"httpd": 2, "apr": 1.5}
|
||||
|
||||
expected_calls = [mock.call(456)]
|
||||
@@ -491,8 +488,7 @@ class TestKojiBuilder:
|
||||
session.multiCall.side_effect = [[[1], [2]], []]
|
||||
session.getAverageBuildDuration.return_value = None
|
||||
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
assert weights == {"httpd": 1.5, "apr": 1.5}
|
||||
|
||||
expected_calls = [
|
||||
@@ -511,8 +507,7 @@ class TestKojiBuilder:
|
||||
session.multiCall.side_effect = [[], []]
|
||||
session.getAverageBuildDuration.return_value = None
|
||||
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
assert weights == {"httpd": 1.5, "apr": 1.5}
|
||||
|
||||
expected_calls = [mock.call("httpd"), mock.call("apr")]
|
||||
@@ -524,8 +519,7 @@ class TestKojiBuilder:
|
||||
def test_get_build_weights_getLoggedInUser_failed(self, ClientSession):
|
||||
session = ClientSession.return_value
|
||||
session.getAverageBuildDuration.return_value = None
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"])
|
||||
assert weights == {"httpd": 1.5, "apr": 1.5}
|
||||
session.krb_login.assert_called_once()
|
||||
|
||||
@@ -908,8 +902,7 @@ class TestKojiBuilder:
|
||||
@patch("koji.ClientSession")
|
||||
def test_ensure_builder_use_a_logged_in_koji_session(self, ClientSession):
|
||||
module_build = module_build_service.common.models.ModuleBuild.get_by_id(db_session, 2)
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
builder = KojiModuleBuilder(db_session, "owner", module_build, conf, "module-tag", [])
|
||||
builder = KojiModuleBuilder(db_session, "owner", module_build, conf, "module-tag", [])
|
||||
builder.koji_session.krb_login.assert_called_once()
|
||||
|
||||
@patch("koji.ClientSession")
|
||||
@@ -918,8 +911,7 @@ class TestKojiBuilder:
|
||||
arches = "x86_64 i686 ppc64le aarch64 s390x"
|
||||
session = ClientSession.return_value
|
||||
session.getTag.return_value = {"arches": arches}
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
ret = KojiModuleBuilder.get_module_build_arches(module_build)
|
||||
ret = KojiModuleBuilder.get_module_build_arches(module_build)
|
||||
assert " ".join(ret) == arches
|
||||
|
||||
@patch("koji.ClientSession")
|
||||
@@ -927,8 +919,7 @@ class TestKojiBuilder:
|
||||
module_build = module_build_service.common.models.ModuleBuild.get_by_id(db_session, 2)
|
||||
session = ClientSession.return_value
|
||||
session.getTag.return_value = {"arches": ""}
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
ret = KojiModuleBuilder.get_module_build_arches(module_build)
|
||||
ret = KojiModuleBuilder.get_module_build_arches(module_build)
|
||||
assert ret == []
|
||||
|
||||
@patch("koji.ClientSession")
|
||||
@@ -936,8 +927,7 @@ class TestKojiBuilder:
|
||||
module_build = module_build_service.common.models.ModuleBuild.get_by_id(db_session, 2)
|
||||
module_build.koji_tag = None
|
||||
session = ClientSession.return_value
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
ret = KojiModuleBuilder.get_module_build_arches(module_build)
|
||||
ret = KojiModuleBuilder.get_module_build_arches(module_build)
|
||||
assert ret == []
|
||||
session.getTag.assert_not_called()
|
||||
session.assert_not_called()
|
||||
@@ -948,8 +938,7 @@ class TestKojiBuilder:
|
||||
session = ClientSession.return_value
|
||||
session.getTag.return_value = None
|
||||
with pytest.raises(ValueError, match="Unknown Koji tag .*"):
|
||||
with patch.dict("sys.modules", krbV=MagicMock()):
|
||||
KojiModuleBuilder.get_module_build_arches(module_build)
|
||||
KojiModuleBuilder.get_module_build_arches(module_build)
|
||||
|
||||
|
||||
class TestGetDistTagSRPM:
|
||||
|
||||
@@ -147,8 +147,7 @@ class TestPoller:
|
||||
module_build.new_repo_task_id = 123456
|
||||
db_session.commit()
|
||||
|
||||
with patch.dict("sys.modules", krbV=mock.MagicMock()):
|
||||
producer.retrigger_new_repo_on_failure()
|
||||
producer.retrigger_new_repo_on_failure()
|
||||
|
||||
koji_session.newRepo.assert_called_once_with(
|
||||
"module-testmodule-master-20170219191323-c40c156c-build")
|
||||
@@ -175,8 +174,7 @@ class TestPoller:
|
||||
module_build.new_repo_task_id = 123456
|
||||
db_session.commit()
|
||||
|
||||
with patch.dict("sys.modules", krbV=mock.MagicMock()):
|
||||
producer.retrigger_new_repo_on_failure()
|
||||
producer.retrigger_new_repo_on_failure()
|
||||
|
||||
module_build = models.ModuleBuild.get_by_id(db_session, 3)
|
||||
|
||||
@@ -219,8 +217,7 @@ class TestPoller:
|
||||
{"dest_tag_name": "module-yyy-2"},
|
||||
]
|
||||
|
||||
with patch.dict("sys.modules", krbV=mock.MagicMock()):
|
||||
producer.delete_old_koji_targets()
|
||||
producer.delete_old_koji_targets()
|
||||
|
||||
koji_session.deleteBuildTarget.assert_not_called()
|
||||
|
||||
@@ -237,8 +234,7 @@ class TestPoller:
|
||||
# If module build's name is one of base module names, build target
|
||||
# should not be deleted.
|
||||
with patch.object(conf, "base_module_names", new=[module_build.name]):
|
||||
with patch.dict("sys.modules", krbV=mock.MagicMock()):
|
||||
producer.delete_old_koji_targets()
|
||||
producer.delete_old_koji_targets()
|
||||
|
||||
koji_session.deleteBuildTarget.assert_not_called()
|
||||
|
||||
@@ -258,8 +254,7 @@ class TestPoller:
|
||||
module_build.state = state
|
||||
db_session.commit()
|
||||
|
||||
with patch.dict("sys.modules", krbV=mock.MagicMock()):
|
||||
producer.delete_old_koji_targets()
|
||||
producer.delete_old_koji_targets()
|
||||
|
||||
koji_session.deleteBuildTarget.assert_not_called()
|
||||
|
||||
@@ -290,8 +285,7 @@ class TestPoller:
|
||||
|
||||
with patch.object(conf, "koji_tag_prefixes", new=["module", "another-prefix"]):
|
||||
with patch.object(conf, "koji_target_delete_time", new=60):
|
||||
with patch.dict("sys.modules", krbV=mock.MagicMock()):
|
||||
producer.delete_old_koji_targets()
|
||||
producer.delete_old_koji_targets()
|
||||
|
||||
koji_session.deleteBuildTarget.assert_called_once_with(1)
|
||||
koji_session.krb_login.assert_called_once()
|
||||
@@ -317,10 +311,9 @@ class TestPoller:
|
||||
]
|
||||
|
||||
with patch.object(conf, "koji_tag_prefixes", new=["module"]):
|
||||
with patch.dict("sys.modules", krbV=mock.MagicMock()):
|
||||
# Use default koji_target_delete_time in config. That time is long
|
||||
# enough for test.
|
||||
producer.delete_old_koji_targets()
|
||||
# Use default koji_target_delete_time in config. That time is long
|
||||
# enough for test.
|
||||
producer.delete_old_koji_targets()
|
||||
|
||||
koji_session.deleteBuildTarget.assert_not_called()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user