mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-05-12 10:57:58 +08:00
Refactor make_module for tests
The original motivation for this refactor is to reuse make_module and drop TestMMDResolver._make_mmd. Some tests require a modulemd created and some tests also require those modulemd to be stored into database as a module build. The problem is db_session has to be passed to make_module even if no need to store into database. Major changes in this patch: * Argument db_session is optional. * Arguments requires_list and build_requires_list are replaced by a single argument dependencies which is a list of group of requires and buildrequires * A new make_module_in_db is created for creating and storing the new modulemd into database conveniently. * Tests are updated with the new make_module and make_module_in_db. Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
@@ -29,7 +29,7 @@ import requests
|
||||
from module_build_service.models import ModuleBuild
|
||||
from module_build_service.scheduler import default_modules
|
||||
from module_build_service.utils.general import load_mmd, mmd_to_str
|
||||
from tests import clean_database, make_module, read_staged_data
|
||||
from tests import clean_database, make_module_in_db, read_staged_data
|
||||
|
||||
|
||||
@patch("module_build_service.scheduler.default_modules._handle_collisions")
|
||||
@@ -39,8 +39,8 @@ def test_add_default_modules(mock_requests_session, mock_hc, db_session):
|
||||
Test that default modules present in the database are added, and the others are ignored.
|
||||
"""
|
||||
clean_database()
|
||||
make_module(db_session, "python:3:12345:1")
|
||||
make_module(db_session, "nodejs:11:2345:2")
|
||||
make_module_in_db("python:3:12345:1", db_session=db_session)
|
||||
make_module_in_db("nodejs:11:2345:2", db_session=db_session)
|
||||
mmd = load_mmd(read_staged_data("formatted_testmodule.yaml"))
|
||||
xmd_brs = mmd.get_xmd()["mbs"]["buildrequires"]
|
||||
assert set(xmd_brs.keys()) == {"platform"}
|
||||
@@ -112,8 +112,8 @@ def test_add_default_modules_request_failed(mock_requests_session, connection_er
|
||||
Test that an exception is raised when the request to get the default modules failed.
|
||||
"""
|
||||
clean_database()
|
||||
make_module(db_session, "python:3:12345:1")
|
||||
make_module(db_session, "nodejs:11:2345:2")
|
||||
make_module_in_db("python:3:12345:1", db_session=db_session)
|
||||
make_module_in_db("nodejs:11:2345:2", db_session=db_session)
|
||||
mmd = load_mmd(read_staged_data("formatted_testmodule.yaml"))
|
||||
xmd_brs = mmd.get_xmd()["mbs"]["buildrequires"]
|
||||
assert set(xmd_brs.keys()) == {"platform"}
|
||||
|
||||
Reference in New Issue
Block a user