From 6b9ec43794aefbf36c977387d71f11c02816fdc6 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Mar 19 2019 07:09:27 +0000 Subject: Avoid long modulemd embedded into fake data for tests Signed-off-by: Chenxiong Qi --- diff --git a/tests/__init__.py b/tests/__init__.py index 239e89b..748f8bd 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -37,6 +37,55 @@ TESTS_DIR = os.path.dirname(os.path.realpath(__file__)) TEST_DATA_DIR = os.path.join(TESTS_DIR, 'test_data') +def make_mmd(name, stream, version, context, requires=None, buildrequires=None): + """Creates new Modulemd.Module instance + + :param name: module name + :param stream: module stream + :param version: module version + :param context: module context + :param requires: Dict of requires, example: + {'platform': ['rhel-8.0'], 'python3': 'master'} + :param buildrequires: Dict of build_requires, example: + {'platform': 'rhel-8.0', 'bootstrap': ['rhel-8.0']} + :rtype: Modulemd.Module instance + """ + mmd = Modulemd.Module() + mmd.set_name(name) + mmd.set_stream(stream) + mmd.set_version(int(version)) + mmd.set_context(context) + # required options + mmd.set_mdversion(2) + mmd.set_summary("A test module in all its beautiful beauty.") + description = ("This module demonstrates how to write simple " + "modulemd files And can be used for testing " + "the build and release pipeline.") + mmd.set_description(description) + licenses = Modulemd.SimpleSet() + licenses.add("GPL") + mmd.set_module_licenses(licenses) + + deps_list = [] + requires = requires or {} + buildrequires = buildrequires or {} + + deps = Modulemd.Dependencies() + for req_name, req_streams in requires.items(): + if not isinstance(req_streams, list): + req_streams = [req_streams] + deps.add_requires(req_name, req_streams) + + for req_name, req_streams in buildrequires.items(): + if not isinstance(req_streams, list): + req_streams = [req_streams] + deps.add_buildrequires(req_name, req_streams) + deps_list.append(deps) + mmd.set_dependencies(deps_list) + + return mmd + + class MockResponse: def __init__(self, json_data, status_code): self.json_data = json_data @@ -52,55 +101,6 @@ class UrsaMajorTestCase(unittest.TestCase): with open(test_data_file, 'r') as f: return json.load(f) - def make_mmd(self, name, stream, version, context, - requires=None, buildrequires=None): - """Creates new Modulemd.Module instance - - :param name: module name - :param stream: module stream - :param version: module version - :param context: module context - :param requires: Dict of requires, example: - {'platform': ['rhel-8.0'], 'python3': 'master'} - :param buildrequires: Dict of build_requires, example: - {'platform': 'rhel-8.0', 'bootstrap': ['rhel-8.0']} - :rtype: Modulemd.Module instance - """ - mmd = Modulemd.Module() - mmd.set_name(name) - mmd.set_stream(stream) - mmd.set_version(int(version)) - mmd.set_context(context) - # required options - mmd.set_mdversion(2) - mmd.set_summary("A test module in all its beautiful beauty.") - description = ("This module demonstrates how to write simple " - "modulemd files And can be used for testing " - "the build and release pipeline.") - mmd.set_description(description) - licenses = Modulemd.SimpleSet() - licenses.add("GPL") - mmd.set_module_licenses(licenses) - - deps_list = [] - requires = requires or {} - buildrequires = buildrequires or {} - - deps = Modulemd.Dependencies() - for req_name, req_streams in requires.items(): - if not isinstance(req_streams, list): - req_streams = [req_streams] - deps.add_requires(req_name, req_streams) - - for req_name, req_streams in buildrequires.items(): - if not isinstance(req_streams, list): - req_streams = [req_streams] - deps.add_buildrequires(req_name, req_streams) - deps_list.append(deps) - mmd.set_dependencies(deps_list) - - return mmd - def make_mbs_response(module_builds): """Helper function to make fake MBS response JSON diff --git a/tests/test_add_module.py b/tests/test_add_module.py index c3b3258..7a1ad6a 100644 --- a/tests/test_add_module.py +++ b/tests/test_add_module.py @@ -26,8 +26,7 @@ import os import tempfile from mock import patch, Mock -from tests import TEST_DATA_DIR -from tests import make_mbs_response +from tests import TEST_DATA_DIR, make_mbs_response, make_mmd from ursa_major.cli import main @@ -94,11 +93,17 @@ class TestAddModule: self.mock_get.return_value.json.return_value = make_mbs_response(mock_mbs_modules or [ { 'koji_tag': 'module-mariadb-10.4-3020190313091759-a5b0195c', - 'modulemd': "---\ndocument: modulemd\nversion: 2\ndata:\n name: mariadb\n stream: 10.4\n version: 3020190313091759\n context: a5b0195c\n summary: 'MariaDB: a very fast and robust SQL database server'\n description: >-\n MariaDB is a community developed branch of MySQL. MariaDB is a multi-user, multi-threaded\n SQL database server. It is a client/server implementation consisting of a server\n daemon (mysqld) and many different client programs and libraries. The base package\n contains the standard MariaDB/MySQL client programs and generic MySQL files.\n license:\n module:\n - MIT\n xmd:\n mbs:\n scmurl: https://src.fedoraproject.org/modules/mariadb.git?#253aec1ecde2bcdb308cf796098f0255c13c46d8\n buildrequires:\n platform:\n stream: f30\n ursine_rpms: \n filtered_rpms: []\n version: 6\n koji_tag: module-f30-build\n context: 00000000\n stream_collision_modules: \n ref: f30\n mse: TRUE\n rpms:\n galera:\n ref: d3badbee4bef85128e4d8849f2a9fb433ac4d9a5\n mariadb:\n ref: ff6cb12c8c560d09cf69b02b89008d3de3a39edf\n commit: 253aec1ecde2bcdb308cf796098f0255c13c46d8\n dependencies:\n - buildrequires:\n platform: [f30]\n requires:\n platform: [f30]\n profiles:\n client:\n description: Client.\n rpms:\n - mariadb\n devel:\n description: Devel package.\n rpms:\n - mariadb-devel\n galera:\n description: Server plus replication engine.\n rpms:\n - mariadb-server\n - mariadb-server-galera\n server:\n description: Base server.\n rpms:\n - mariadb-server\n api:\n rpms:\n - mariadb\n - mariadb-server\n buildopts:\n rpms:\n macros: |\n %runselftest 0\n %ignore_testsuite_result 1\n components:\n rpms:\n galera:\n rationale: Galera package for replication.\n repository: git+https://src.fedoraproject.org/rpms/galera\n cache: https://src.fedoraproject.org/repo/pkgs/galera\n ref: d3badbee4bef85128e4d8849f2a9fb433ac4d9a5\n arches: [aarch64, armv7hl, i686, ppc64le, s390x, x86_64]\n mariadb:\n rationale: The main component.\n repository: git+https://src.fedoraproject.org/rpms/mariadb\n cache: https://src.fedoraproject.org/repo/pkgs/mariadb\n ref: 10.4\n arches: [aarch64, armv7hl, i686, ppc64le, s390x, x86_64]\n...\n", # noqa + 'modulemd': make_mmd(name='mariadb', stream='10.4', + version='3020190313091759', context='a5b0195c', + requires={'platform': 'f30'}, + buildrequires={'platform': 'f30'}).dumps(), }, { 'koji_tag': 'module-mariadb-10.4-3020190304180835-a5b0195c', - 'modulemd': "---\ndocument: modulemd\nversion: 2\ndata:\n name: mariadb\n stream: 10.4\n version: 3020190304180835\n context: a5b0195c\n summary: 'MariaDB: a very fast and robust SQL database server'\n description: >-\n MariaDB is a community developed branch of MySQL. MariaDB is a multi-user, multi-threaded\n SQL database server. It is a client/server implementation consisting of a server\n daemon (mysqld) and many different client programs and libraries. The base package\n contains the standard MariaDB/MySQL client programs and generic MySQL files.\n license:\n module:\n - MIT\n xmd:\n mbs:\n scmurl: git+https://src.fedoraproject.org/modules/mariadb.git?#b1a86ef04dfc1772ecd4646c91938e535c24e7db\n buildrequires:\n platform:\n stream: f30\n ursine_rpms: \n filtered_rpms: []\n version: 6\n koji_tag: module-f30-build\n context: 00000000\n stream_collision_modules: \n ref: f30\n mse: TRUE\n rpms:\n mariadb:\n ref: ff6cb12c8c560d09cf69b02b89008d3de3a39edf\n commit: b1a86ef04dfc1772ecd4646c91938e535c24e7db\n dependencies:\n - buildrequires:\n platform: [f30]\n requires:\n platform: [f30]\n profiles:\n client:\n description: Client.\n rpms:\n - mariadb\n devel:\n description: Devel package.\n rpms:\n - mariadb-devel\n galera:\n description: Server plus replication engine.\n rpms:\n - mariadb-server\n - mariadb-server-galera\n server:\n description: Base server.\n rpms:\n - mariadb-server\n api:\n rpms:\n - mariadb\n - mariadb-server\n buildopts:\n rpms:\n macros: |\n %runselftest 0\n %ignore_testsuite_result 1\n components:\n rpms:\n mariadb:\n rationale: The main component.\n repository: git+https://src.fedoraproject.org/rpms/mariadb\n cache: https://src.fedoraproject.org/repo/pkgs/mariadb\n ref: 10.4\n arches: [aarch64, armv7hl, i686, ppc64le, s390x, x86_64]\n...\n", # noqa + 'modulemd': make_mmd(name='mariadb', stream='10.4', + version='3020190304180835', context='a5b0195c', + requires={'platform': 'f30'}, + buildrequires={'platform': 'f30'}).dumps(), }, ]) diff --git a/tests/test_add_tag_handler.py b/tests/test_add_tag_handler.py index aeeafba..01a8b52 100644 --- a/tests/test_add_tag_handler.py +++ b/tests/test_add_tag_handler.py @@ -29,7 +29,7 @@ import shutil import tempfile from argparse import Namespace -from tests import UrsaMajorTestCase, MockResponse +from tests import UrsaMajorTestCase, MockResponse, make_mmd from ursa_major.mbs import MBS from ursa_major.handlers.add_tag import ModuleInfo, AddTagHandler @@ -139,7 +139,7 @@ class TestAddTagHandler(AddTagHandlerTestCase): session = koji.ClientSession.return_value session.getInheritanceData.side_effect = self.fake_get_inheritance_data - self.handler._mbs.get_module_mmd.return_value = self.make_mmd( + self.handler._mbs.get_module_mmd.return_value = make_mmd( 'autotools', 'rhel-8.0', '20180101', '123456', {'platform': ['rhel-8.0']}) @@ -215,8 +215,7 @@ class TestAddTagHandler(AddTagHandlerTestCase): koji_tag='module-d243299e85d7e9aa' )) mock_mbs = mock.MagicMock() - fake_mmd = self.make_mmd("testmodule", "master", - "20180101", "1234567") + fake_mmd = make_mmd("testmodule", "master", "20180101", "1234567") mock_mbs.get_module_mmd.return_value = fake_mmd self.handler.connect_koji = mock.MagicMock() self.handler.connect_mbs = mock.MagicMock() @@ -239,10 +238,10 @@ class TestAddTagHandler(AddTagHandlerTestCase): message = self.load_json_from_file(message_file) mock_mbs = mock.MagicMock() fake_requires = {"platform": ["el8"]} - fake_mmd = self.make_mmd("testmodule", "rhel-8.0", - "20180409051516", "9e5fe74b", - requires=fake_requires, - buildrequires=fake_requires) + fake_mmd = make_mmd("testmodule", "rhel-8.0", + "20180409051516", "9e5fe74b", + requires=fake_requires, + buildrequires=fake_requires) mock_mbs.get_module_mmd.return_value = fake_mmd modinfo = ModuleInfo.from_mbs_message(mock_mbs, message) matched_config = AddTagHandler.get_module_config(fake_configs, modinfo) @@ -420,9 +419,9 @@ class TestAddTagHandler(AddTagHandlerTestCase): message = self.load_json_from_file("testmodule_ready_message.json") mock_mbs = mock.MagicMock() fake_requires = {"platform": ["el8"]} - fake_mmd = self.make_mmd("testmodule", "rhel-8.0", - "20180409051516", "9e5fe74b", - requires=fake_requires) + fake_mmd = make_mmd("testmodule", "rhel-8.0", + "20180409051516", "9e5fe74b", + requires=fake_requires) mock_mbs.get_module_mmd.return_value = fake_mmd modinfo = ModuleInfo.from_mbs_message(mock_mbs, message) diff --git a/tests/test_check_config.py b/tests/test_check_config.py index 030731c..740a622 100644 --- a/tests/test_check_config.py +++ b/tests/test_check_config.py @@ -27,8 +27,7 @@ import pytest import tempfile from mock import call, patch, Mock -from tests import TEST_DATA_DIR -from tests import make_mbs_response +from tests import TEST_DATA_DIR, make_mbs_response, make_mmd from ursa_major.cli import main @@ -149,13 +148,19 @@ class TestCheckConfig: 'id': 3617, 'name': 'mariadb', 'koji_tag': 'module-mariadb-10.4-3020190313091759-a5b0195c', - 'modulemd': "---\ndocument: modulemd\nversion: 2\ndata:\n name: mariadb\n stream: 10.4\n version: 3020190313091759\n context: a5b0195c\n summary: 'MariaDB: a very fast and robust SQL database server'\n description: >-\n MariaDB is a community developed branch of MySQL. MariaDB is a multi-user, multi-threaded\n SQL database server. It is a client/server implementation consisting of a server\n daemon (mysqld) and many different client programs and libraries. The base package\n contains the standard MariaDB/MySQL client programs and generic MySQL files.\n license:\n module:\n - MIT\n xmd:\n mbs:\n mse: TRUE\n scmurl: https://src.fedoraproject.org/modules/mariadb.git?#253aec1ecde2bcdb308cf796098f0255c13c46d8\n commit: 253aec1ecde2bcdb308cf796098f0255c13c46d8\n buildrequires:\n platform:\n stream_collision_modules: \n stream: f30\n ref: f30\n filtered_rpms: []\n ursine_rpms: \n koji_tag: module-f30-build\n version: 6\n context: 00000000\n rpms:\n galera:\n ref: d3badbee4bef85128e4d8849f2a9fb433ac4d9a5\n mariadb:\n ref: ff6cb12c8c560d09cf69b02b89008d3de3a39edf\n dependencies:\n - buildrequires:\n platform: [f30]\n requires:\n platform: [f30]\n...\n", # noqa + 'modulemd': make_mmd(name='mariadb', stream='10.4', + version='3020190313091759', context='a5b0195c', + requires={'platform': 'f30'}, + buildrequires={'platform': 'f30'}).dumps(), }, { 'id': 3640, 'name': 'ffsend', 'koji_tag': 'module-ffsend-latest-3020190316024948-a5b0195c', - 'modulemd': '---\ndocument: modulemd\nversion: 2\ndata:\n name: ffsend\n stream: latest\n version: 3020190316024948\n context: a5b0195c\n summary: Easily and securely share files from the command line\n description: >-\n Easily and securely share files from the command line.\n\n A fully featured Firefox Send client.\n license:\n module:\n - MIT\n dependencies:\n - buildrequires:\n platform: [f30]\n requires:\n platform: [f30]\n references:\n community: https://github.com/timvisee/ffsend\n documentation: https://github.com/timvisee/ffsend/blob/master/LICENSE\n tracker: https://github.com/timvisee/ffsend/issues\n profiles:\n default:\n rpms:\n - ffsend\n api:\n rpms:\n - ffsend\n...\n', # noqa + 'modulemd': make_mmd(name='mariadb', stream='10.4', + version='3020190316024948', context='a5b0195c', + requires={'platform': 'f30'}, + buildrequires={'platform': 'f30'}).dumps(), } ]) diff --git a/tests/test_remove_module.py b/tests/test_remove_module.py index 0765528..e7f17bd 100644 --- a/tests/test_remove_module.py +++ b/tests/test_remove_module.py @@ -27,8 +27,7 @@ import tempfile from mock import patch, Mock from ursa_major.cli import main -from tests import TEST_DATA_DIR -from tests import make_mbs_response +from tests import TEST_DATA_DIR, make_mbs_response, make_mmd class TestRemoveModule: @@ -68,7 +67,10 @@ class TestRemoveModule: # This koji_tag is not present in the tag inheritance, so # no tag is going to be removed. 'koji_tag': 'module-python-3.6', - 'modulemd': "---\ndocument: modulemd\nversion: 2\ndata:\n name: mariadb\n stream: 10.4\n version: 3020190313091759\n context: a5b0195c\n summary: 'MariaDB: a very fast and robust SQL database server'\n description: >-\n MariaDB is a community developed branch of MySQL. MariaDB is a multi-user, multi-threaded\n SQL database server. It is a client/server implementation consisting of a server\n daemon (mysqld) and many different client programs and libraries. The base package\n contains the standard MariaDB/MySQL client programs and generic MySQL files.\n license:\n module:\n - MIT\n xmd:\n mbs:\n scmurl: https://src.fedoraproject.org/modules/mariadb.git?#253aec1ecde2bcdb308cf796098f0255c13c46d8\n buildrequires:\n platform:\n stream: f30\n ursine_rpms: \n filtered_rpms: []\n version: 6\n koji_tag: module-f30-build\n context: 00000000\n stream_collision_modules: \n ref: f30\n mse: TRUE\n rpms:\n galera:\n ref: d3badbee4bef85128e4d8849f2a9fb433ac4d9a5\n mariadb:\n ref: ff6cb12c8c560d09cf69b02b89008d3de3a39edf\n commit: 253aec1ecde2bcdb308cf796098f0255c13c46d8\n dependencies:\n - buildrequires:\n platform: [f30]\n requires:\n platform: [f30]\n profiles:\n client:\n description: Client.\n rpms:\n - mariadb\n devel:\n description: Devel package.\n rpms:\n - mariadb-devel\n galera:\n description: Server plus replication engine.\n rpms:\n - mariadb-server\n - mariadb-server-galera\n server:\n description: Base server.\n rpms:\n - mariadb-server\n api:\n rpms:\n - mariadb\n - mariadb-server\n buildopts:\n rpms:\n macros: |\n %runselftest 0\n %ignore_testsuite_result 1\n components:\n rpms:\n galera:\n rationale: Galera package for replication.\n repository: git+https://src.fedoraproject.org/rpms/galera\n cache: https://src.fedoraproject.org/repo/pkgs/galera\n ref: d3badbee4bef85128e4d8849f2a9fb433ac4d9a5\n arches: [aarch64, armv7hl, i686, ppc64le, s390x, x86_64]\n mariadb:\n rationale: The main component.\n repository: git+https://src.fedoraproject.org/rpms/mariadb\n cache: https://src.fedoraproject.org/repo/pkgs/mariadb\n ref: 10.4\n arches: [aarch64, armv7hl, i686, ppc64le, s390x, x86_64]\n...\n", # noqa + 'modulemd': make_mmd(name='mariadb', stream='10.4', + version='3020190313091759', context='a5b0195c', + requires={'platform': 'f30'}, + buildrequires={'platform': 'f30'}).dumps(), }, ], 'meta': { @@ -114,12 +116,18 @@ class TestRemoveModule: get.return_value.json.return_value = make_mbs_response([ { 'koji_tag': 'module-mariadb-10.4-3020190313091759-a5b0195c', - 'modulemd': "---\ndocument: modulemd\nversion: 2\ndata:\n name: mariadb\n stream: 10.4\n version: 3020190313091759\n context: a5b0195c\n summary: 'MariaDB: a very fast and robust SQL database server'\n description: >-\n MariaDB is a community developed branch of MySQL. MariaDB is a multi-user, multi-threaded\n SQL database server. It is a client/server implementation consisting of a server\n daemon (mysqld) and many different client programs and libraries. The base package\n contains the standard MariaDB/MySQL client programs and generic MySQL files.\n license:\n module:\n - MIT\n xmd:\n mbs:\n scmurl: https://src.fedoraproject.org/modules/mariadb.git?#253aec1ecde2bcdb308cf796098f0255c13c46d8\n buildrequires:\n platform:\n stream: f30\n ursine_rpms: \n filtered_rpms: []\n version: 6\n koji_tag: module-f30-build\n context: 00000000\n stream_collision_modules: \n ref: f30\n mse: TRUE\n rpms:\n galera:\n ref: d3badbee4bef85128e4d8849f2a9fb433ac4d9a5\n mariadb:\n ref: ff6cb12c8c560d09cf69b02b89008d3de3a39edf\n commit: 253aec1ecde2bcdb308cf796098f0255c13c46d8\n dependencies:\n - buildrequires:\n platform: [f30]\n requires:\n platform: [f30]\n profiles:\n client:\n description: Client.\n rpms:\n - mariadb\n devel:\n description: Devel package.\n rpms:\n - mariadb-devel\n galera:\n description: Server plus replication engine.\n rpms:\n - mariadb-server\n - mariadb-server-galera\n server:\n description: Base server.\n rpms:\n - mariadb-server\n api:\n rpms:\n - mariadb\n - mariadb-server\n buildopts:\n rpms:\n macros: |\n %runselftest 0\n %ignore_testsuite_result 1\n components:\n rpms:\n galera:\n rationale: Galera package for replication.\n repository: git+https://src.fedoraproject.org/rpms/galera\n cache: https://src.fedoraproject.org/repo/pkgs/galera\n ref: d3badbee4bef85128e4d8849f2a9fb433ac4d9a5\n arches: [aarch64, armv7hl, i686, ppc64le, s390x, x86_64]\n mariadb:\n rationale: The main component.\n repository: git+https://src.fedoraproject.org/rpms/mariadb\n cache: https://src.fedoraproject.org/repo/pkgs/mariadb\n ref: 10.4\n arches: [aarch64, armv7hl, i686, ppc64le, s390x, x86_64]\n...\n", # noqa + 'modulemd': make_mmd(name='mariadb', stream='10.4', + version='3020190313091759', context='a5b0195c', + requires={'platform': 'f30'}, + buildrequires={'platform': 'f30'}).dumps(), }, { # This koji_tag is present in the inheritance, so it should be removed. 'koji_tag': 'module-mariadb-10.4-3020190304180835-a5b0195c', - 'modulemd': "---\ndocument: modulemd\nversion: 2\ndata:\n name: mariadb\n stream: 10.4\n version: 3020190304180835\n context: a5b0195c\n summary: 'MariaDB: a very fast and robust SQL database server'\n description: >-\n MariaDB is a community developed branch of MySQL. MariaDB is a multi-user, multi-threaded\n SQL database server. It is a client/server implementation consisting of a server\n daemon (mysqld) and many different client programs and libraries. The base package\n contains the standard MariaDB/MySQL client programs and generic MySQL files.\n license:\n module:\n - MIT\n xmd:\n mbs:\n scmurl: git+https://src.fedoraproject.org/modules/mariadb.git?#b1a86ef04dfc1772ecd4646c91938e535c24e7db\n buildrequires:\n platform:\n stream: f30\n ursine_rpms: \n filtered_rpms: []\n version: 6\n koji_tag: module-f30-build\n context: 00000000\n stream_collision_modules: \n ref: f30\n mse: TRUE\n rpms:\n mariadb:\n ref: ff6cb12c8c560d09cf69b02b89008d3de3a39edf\n commit: b1a86ef04dfc1772ecd4646c91938e535c24e7db\n dependencies:\n - buildrequires:\n platform: [f30]\n requires:\n platform: [f30]\n profiles:\n client:\n description: Client.\n rpms:\n - mariadb\n devel:\n description: Devel package.\n rpms:\n - mariadb-devel\n galera:\n description: Server plus replication engine.\n rpms:\n - mariadb-server\n - mariadb-server-galera\n server:\n description: Base server.\n rpms:\n - mariadb-server\n api:\n rpms:\n - mariadb\n - mariadb-server\n buildopts:\n rpms:\n macros: |\n %runselftest 0\n %ignore_testsuite_result 1\n components:\n rpms:\n mariadb:\n rationale: The main component.\n repository: git+https://src.fedoraproject.org/rpms/mariadb\n cache: https://src.fedoraproject.org/repo/pkgs/mariadb\n ref: 10.4\n arches: [aarch64, armv7hl, i686, ppc64le, s390x, x86_64]\n...\n", # noqa + 'modulemd': make_mmd(name='mariadb', stream='10.4', + version='3020190304180835', context='a5b0195c', + requires={'platform': 'f30'}, + buildrequires={'platform': 'f30'}).dumps(), } ]) diff --git a/tests/test_utils.py b/tests/test_utils.py index d596ad1..8f6e85d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -24,76 +24,68 @@ from tests import UrsaMajorTestCase from ursa_major.utils import mmd_has_requires +from tests import make_mmd class TestMmdHasRequires(UrsaMajorTestCase): def test_mmd_has_neg_requires(self): requires = {'platform': 'f26'} - mmd = self.make_mmd('testmodule', 'master', '123', '00000000', - requires) + mmd = make_mmd('testmodule', 'master', '123', '00000000', requires) check_requires = {'platform': '-f26'} result = mmd_has_requires(mmd, check_requires) self.assertFalse(result) def test_mmd_missing_requires(self): requires = {'platform': 'f28'} - mmd = self.make_mmd('testmodule', 'master', '123', '00000000', - requires) + mmd = make_mmd('testmodule', 'master', '123', '00000000', requires) check_requires = {'platform': 'f28', 'python3': 'master'} result = mmd_has_requires(mmd, check_requires) self.assertFalse(result) def test_mmd_not_has_neg_requires(self): requires = {'platform': 'f28', 'python3': 'master'} - mmd = self.make_mmd('testmodule', 'master', '123', '00000000', - requires) + mmd = make_mmd('testmodule', 'master', '123', '00000000', requires) check_requires = {'platform': '-f26', 'python3': 'master'} result = mmd_has_requires(mmd, check_requires) self.assertTrue(result) def test_mmd_does_not_has_pos_requires(self): requires = {'platform': 'f28', 'python3': 'master'} - mmd = self.make_mmd('testmodule', 'master', '123', '00000000', - requires) + mmd = make_mmd('testmodule', 'master', '123', '00000000', requires) check_requires = {'platform': 'f28', 'python3': 'f28'} result = mmd_has_requires(mmd, check_requires) self.assertFalse(result) def test_mmd_has_more_requires_than_checks(self): requires = {'platform': 'f28', 'python3': 'master'} - mmd = self.make_mmd('testmodule', 'master', '123', '00000000', - requires) + mmd = make_mmd('testmodule', 'master', '123', '00000000', requires) check_requires = {'platform': 'f28'} result = mmd_has_requires(mmd, check_requires) self.assertTrue(result) def test_mmd_has_more_require_streams_than_checks(self): requires = {'platform': ['f28', 'f29'], 'python3': 'master'} - mmd = self.make_mmd('testmodule', 'master', '123', '00000000', - requires) + mmd = make_mmd('testmodule', 'master', '123', '00000000', requires) check_requires = {'platform': 'f28'} result = mmd_has_requires(mmd, check_requires) self.assertTrue(result) def test_mmd_has_a_neg_stream_in_streams_list(self): requires = {'platform': ['f28', 'f29'], 'python3': 'master'} - mmd = self.make_mmd('testmodule', 'master', '123', '00000000', - requires) + mmd = make_mmd('testmodule', 'master', '123', '00000000', requires) check_requires = {'platform': '-f28'} result = mmd_has_requires(mmd, check_requires) self.assertFalse(result) def test_mmd_has_a_neg_stream_in_multi_neg_streams(self): requires = {'platform': ['f27'], 'python3': 'master'} - mmd = self.make_mmd('testmodule', 'master', '123', '00000000', - requires) + mmd = make_mmd('testmodule', 'master', '123', '00000000', requires) check_requires = {'platform': ['-f26', '-f27']} result = mmd_has_requires(mmd, check_requires) self.assertFalse(result) def test_check_with_empty_requires(self): requires = {'platform': ['f27'], 'python3': 'master'} - mmd = self.make_mmd('testmodule', 'master', '123', '00000000', - requires) + mmd = make_mmd('testmodule', 'master', '123', '00000000', requires) result = mmd_has_requires(mmd, {}) self.assertTrue(result)