mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-24 02:32:26 +08:00
Format the coding style across the codebase using "black" and manual tweaks
The main benefit of this commit is that the use of double quotes is now consistent.
This commit is contained in:
@@ -27,7 +27,7 @@ from mock import patch
|
||||
from module_build_service import conf, Modulemd
|
||||
from module_build_service.models import ComponentBuild, ModuleBuild, make_session
|
||||
from module_build_service.utils import to_text_type
|
||||
from tests import (init_data as init_data_contexts, clean_database, make_module)
|
||||
from tests import init_data as init_data_contexts, clean_database, make_module
|
||||
from tests.test_models import init_data, module_build_from_modulemd
|
||||
|
||||
|
||||
@@ -38,15 +38,16 @@ class TestModels:
|
||||
def test_app_sqlalchemy_events(self):
|
||||
with make_session(conf) as session:
|
||||
component_build = ComponentBuild()
|
||||
component_build.package = 'before_models_committed'
|
||||
component_build.scmurl = \
|
||||
('git://pkgs.domain.local/rpms/before_models_committed?'
|
||||
'#9999999999999999999999999999999999999999')
|
||||
component_build.format = 'rpms'
|
||||
component_build.package = "before_models_committed"
|
||||
component_build.scmurl = (
|
||||
"git://pkgs.domain.local/rpms/before_models_committed?"
|
||||
"#9999999999999999999999999999999999999999"
|
||||
)
|
||||
component_build.format = "rpms"
|
||||
component_build.task_id = 999999999
|
||||
component_build.state = 1
|
||||
component_build.nvr = ('before_models_committed-0.0.0-0'
|
||||
'.module_before_models_committed_0_0')
|
||||
component_build.nvr = \
|
||||
"before_models_committed-0.0.0-0.module_before_models_committed_0_0"
|
||||
component_build.batch = 1
|
||||
component_build.module_id = 1
|
||||
|
||||
@@ -66,16 +67,20 @@ class TestModels:
|
||||
determined"""
|
||||
build = ModuleBuild.query.filter_by(id=1).one()
|
||||
yaml_path = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'staged_data', 'testmodule_dependencies.yaml')
|
||||
os.path.dirname(__file__), "..", "staged_data", "testmodule_dependencies.yaml")
|
||||
mmd = Modulemd.Module.new_from_file(yaml_path)
|
||||
mmd.upgrade()
|
||||
build.modulemd = to_text_type(mmd.dumps())
|
||||
(build.ref_build_context, build.build_context, build.runtime_context,
|
||||
build.context) = ModuleBuild.contexts_from_mmd(build.modulemd)
|
||||
assert build.ref_build_context == 'f6e2aeec7576196241b9afa0b6b22acf2b6873d7'
|
||||
assert build.build_context == '089df24993c037e10174f3fa7342ab4dc191a4d4'
|
||||
assert build.runtime_context == 'bbc84c7b817ab3dd54916c0bcd6c6bdf512f7f9c'
|
||||
assert build.context == '3ee22b28'
|
||||
(
|
||||
build.ref_build_context,
|
||||
build.build_context,
|
||||
build.runtime_context,
|
||||
build.context,
|
||||
) = ModuleBuild.contexts_from_mmd(build.modulemd)
|
||||
assert build.ref_build_context == "f6e2aeec7576196241b9afa0b6b22acf2b6873d7"
|
||||
assert build.build_context == "089df24993c037e10174f3fa7342ab4dc191a4d4"
|
||||
assert build.runtime_context == "bbc84c7b817ab3dd54916c0bcd6c6bdf512f7f9c"
|
||||
assert build.context == "3ee22b28"
|
||||
|
||||
def test_siblings_property(self):
|
||||
""" Tests that the siblings property returns the ID of all modules with
|
||||
@@ -83,73 +88,75 @@ class TestModels:
|
||||
"""
|
||||
clean_database()
|
||||
yaml_path = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'staged_data', 'formatted_testmodule.yaml')
|
||||
os.path.dirname(__file__), "..", "staged_data", "formatted_testmodule.yaml")
|
||||
mmd = Modulemd.Module.new_from_file(yaml_path)
|
||||
mmd.upgrade()
|
||||
with make_session(conf) as session:
|
||||
for i in range(3):
|
||||
build = module_build_from_modulemd(to_text_type(mmd.dumps()))
|
||||
build.build_context = 'f6e2aeec7576196241b9afa0b6b22acf2b6873d' + str(i)
|
||||
build.runtime_context = 'bbc84c7b817ab3dd54916c0bcd6c6bdf512f7f9c' + str(i)
|
||||
build.build_context = "f6e2aeec7576196241b9afa0b6b22acf2b6873d" + str(i)
|
||||
build.runtime_context = "bbc84c7b817ab3dd54916c0bcd6c6bdf512f7f9c" + str(i)
|
||||
session.add(build)
|
||||
session.commit()
|
||||
build_one = ModuleBuild.query.get(2)
|
||||
assert build_one.siblings == [3, 4]
|
||||
|
||||
@pytest.mark.parametrize('stream,right_pad,expected', [
|
||||
['f27', True, 270000.0],
|
||||
['f27.02.30', True, 270230.0],
|
||||
['f27', False, 27.0],
|
||||
['f27.02.30', False, 270230.0],
|
||||
['el8', True, 080000.0],
|
||||
['el8.1.0', True, 080100.0],
|
||||
['el8.z', True, 080000.2],
|
||||
['el8.1.0.z', True, 080100.3],
|
||||
])
|
||||
@patch.object(conf, 'stream_suffixes', new={
|
||||
r'el\d+\.z': 0.2, r'el\d+\.\d+\.\d+\.z': 0.3
|
||||
})
|
||||
@pytest.mark.parametrize(
|
||||
"stream,right_pad,expected",
|
||||
[
|
||||
["f27", True, 270000.0],
|
||||
["f27.02.30", True, 270230.0],
|
||||
["f27", False, 27.0],
|
||||
["f27.02.30", False, 270230.0],
|
||||
["el8", True, 080000.0],
|
||||
["el8.1.0", True, 080100.0],
|
||||
["el8.z", True, 080000.2],
|
||||
["el8.1.0.z", True, 080100.3],
|
||||
],
|
||||
)
|
||||
@patch.object(conf, "stream_suffixes", new={r"el\d+\.z": 0.2, r"el\d+\.\d+\.\d+\.z": 0.3})
|
||||
def test_get_stream_version(self, stream, right_pad, expected):
|
||||
assert expected == ModuleBuild.get_stream_version(stream, right_pad)
|
||||
|
||||
|
||||
class TestModelsGetStreamsContexts:
|
||||
|
||||
def test_get_last_build_in_all_streams(self):
|
||||
init_data_contexts(contexts=True)
|
||||
with make_session(conf) as session:
|
||||
builds = ModuleBuild.get_last_build_in_all_streams(
|
||||
session, "nginx")
|
||||
builds = ["%s:%s:%s" % (build.name, build.stream, str(build.version))
|
||||
for build in builds]
|
||||
builds = ModuleBuild.get_last_build_in_all_streams(session, "nginx")
|
||||
builds = [
|
||||
"%s:%s:%s" % (build.name, build.stream, str(build.version)) for build in builds
|
||||
]
|
||||
assert builds == ["nginx:%d:%d" % (i, i + 2) for i in range(10)]
|
||||
|
||||
def test_get_last_build_in_all_stream_last_version(self):
|
||||
init_data_contexts(contexts=False)
|
||||
with make_session(conf) as session:
|
||||
builds = ModuleBuild.get_last_build_in_all_streams(
|
||||
session, "nginx")
|
||||
builds = ["%s:%s:%s" % (build.name, build.stream, str(build.version))
|
||||
for build in builds]
|
||||
builds = ModuleBuild.get_last_build_in_all_streams(session, "nginx")
|
||||
builds = [
|
||||
"%s:%s:%s" % (build.name, build.stream, str(build.version)) for build in builds
|
||||
]
|
||||
assert builds == ["nginx:1:11"]
|
||||
|
||||
def test_get_last_builds_in_stream(self):
|
||||
init_data_contexts(contexts=True)
|
||||
with make_session(conf) as session:
|
||||
builds = ModuleBuild.get_last_builds_in_stream(
|
||||
session, "nginx", "1")
|
||||
builds = ["%s:%s:%s:%s" % (build.name, build.stream, str(build.version),
|
||||
build.context) for build in builds]
|
||||
assert builds == ['nginx:1:3:d5a6c0fa', 'nginx:1:3:795e97c1']
|
||||
builds = ModuleBuild.get_last_builds_in_stream(session, "nginx", "1")
|
||||
builds = [
|
||||
"%s:%s:%s:%s" % (build.name, build.stream, str(build.version), build.context)
|
||||
for build in builds
|
||||
]
|
||||
assert builds == ["nginx:1:3:d5a6c0fa", "nginx:1:3:795e97c1"]
|
||||
|
||||
def test_get_last_builds_in_stream_version_lte(self):
|
||||
init_data_contexts(1, multiple_stream_versions=True)
|
||||
with make_session(conf) as session:
|
||||
builds = ModuleBuild.get_last_builds_in_stream_version_lte(
|
||||
session, "platform", 290100)
|
||||
builds = set(["%s:%s:%s:%s" % (build.name, build.stream, str(build.version),
|
||||
build.context) for build in builds])
|
||||
assert builds == set(['platform:f29.0.0:3:00000000', 'platform:f29.1.0:3:00000000'])
|
||||
builds = ModuleBuild.get_last_builds_in_stream_version_lte(session, "platform", 290100)
|
||||
builds = set([
|
||||
"%s:%s:%s:%s" % (build.name, build.stream, str(build.version), build.context)
|
||||
for build in builds
|
||||
])
|
||||
assert builds == set(["platform:f29.0.0:3:00000000", "platform:f29.1.0:3:00000000"])
|
||||
|
||||
def test_get_last_builds_in_stream_version_lte_different_versions(self):
|
||||
"""
|
||||
@@ -166,12 +173,16 @@ class TestModelsGetStreamsContexts:
|
||||
make_module("platform:f29.3.0:20:c11", {}, {}, virtual_streams=["f29"])
|
||||
|
||||
with make_session(conf) as session:
|
||||
builds = ModuleBuild.get_last_builds_in_stream_version_lte(
|
||||
session, "platform", 290200)
|
||||
builds = set(["%s:%s:%s:%s" % (build.name, build.stream, str(build.version),
|
||||
build.context) for build in builds])
|
||||
assert builds == set(['platform:f29.1.0:15:c11', 'platform:f29.1.0:15:c11.another',
|
||||
'platform:f29.2.0:1:c11'])
|
||||
builds = ModuleBuild.get_last_builds_in_stream_version_lte(session, "platform", 290200)
|
||||
builds = set([
|
||||
"%s:%s:%s:%s" % (build.name, build.stream, str(build.version), build.context)
|
||||
for build in builds
|
||||
])
|
||||
assert builds == set([
|
||||
"platform:f29.1.0:15:c11",
|
||||
"platform:f29.1.0:15:c11.another",
|
||||
"platform:f29.2.0:1:c11",
|
||||
])
|
||||
|
||||
def test_get_module_count(self):
|
||||
clean_database(False)
|
||||
|
||||
Reference in New Issue
Block a user