From 304ba8831fdf420344d132e20c051a67d24a1773 Mon Sep 17 00:00:00 2001
From: Daniel Mach <dmach@redhat.com>
Date: Mon, 17 Jul 2017 03:18:41 -0400
Subject: [PATCH 4/4] Add initial unit tests for modularity.
---
tests/test_modules.py | 249 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 247 insertions(+), 2 deletions(-)
diff --git a/tests/test_modules.py b/tests/test_modules.py
index e9d04227..bb9baa58 100644
--- a/tests/test_modules.py
+++ b/tests/test_modules.py
@@ -18,16 +18,23 @@
from __future__ import absolute_import
from __future__ import unicode_literals
+import os
+import shutil
+import sys
+import tempfile
import unittest
import hawkey
import modulemd
-from dnf.conf import ModuleConf
+import dnf.conf
from dnf.modules import RepoModuleDict, RepoModule, RepoModuleStream, RepoModuleVersion
from dnf.modules import ModuleSubject, NSVAP
+MODULES_DIR = os.path.join(os.path.dirname(__file__), "modules/etc/dnf/modules.d")
+REPOS_DIR = os.path.join(os.path.dirname(__file__), "modules/modules")
+
# with profile
MODULE_NSVAP = "module-name-stream-1.x86_64/profile"
MODULE_NSVP = "module-name-stream-1/profile"
@@ -211,7 +218,7 @@ class RepoModuleDictTest(unittest.TestCase):
self.assertEqual(rmv, None)
# set enabled stream
- conf = ModuleConf()
+ conf = dnf.conf.ModuleConf()
conf.enabled = 1
conf.stream = "enabled_stream"
rmd["module-name"].conf = conf
@@ -233,3 +240,241 @@ class RepoModuleDictTest(unittest.TestCase):
rmv = rmd.find_module_version(name="module-name")
# TODO: default from system profile
# self.assertEqual(rmv.full_version, "module-name-default_stream-1")
+
+
+class ModuleTest(unittest.TestCase):
+
+ def assertInstalls(self, nevras):
+ expected = sorted(set(nevras))
+ actual = sorted(set([str(i) for i in self.base._goal.list_installs()]))
+ self.assertEqual(expected, actual)
+
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp(prefix = "dnf_test_")
+ self.conf = dnf.conf.Conf()
+ self.conf.cachedir = os.path.join(self.tmpdir, "cache")
+ self.conf.installroot = os.path.join(self.tmpdir, "root")
+ self.conf.modulesdir = MODULES_DIR
+ self.conf.substitutions["arch"] = "x86_64"
+ self.conf.substitutions["basearch"] = dnf.rpm.basearch(self.conf.substitutions["arch"])
+ self.base = dnf.Base(conf=self.conf)
+
+ self._add_module_repo("_all")
+ self.base.fill_sack(load_system_repo=False, load_available_repos=True)
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ def _add_module_repo(self, repo_id, modules=True):
+ url = "file://" + os.path.join(REPOS_DIR, repo_id, self.conf.substitutions["arch"])
+ repo = self.base.repos.add_new_repo(repo_id, self.base.conf, baseurl=[url], modules=modules)
+ return repo
+
+ # dnf module enable
+
+ def test_enable_name(self):
+ # use default stream
+ self.base.repo_module_dict.enable("httpd", assumeyes=True)
+
+ def test_enable_name_stream(self):
+ self.base.repo_module_dict.enable("httpd-2.4", assumeyes=True)
+ # TODO: test conf presence and content
+
+ def test_enable_pkgspec(self):
+ pass
+
+ def test_enable_invalid(self):
+ self.base.repo_module_dict.enable("httpd-invalid", assumeyes=True)
+ # TODO: exit code? exception?
+
+ def test_enable_different_stream(self):
+ pass
+
+ def test_enable_different_stream_missing_profile(self):
+ pass
+
+ # dnf module disable
+
+ def test_disable_name(self):
+ pass
+
+ def test_disable_name_stream(self):
+ pass
+
+ def test_disable_pkgspec(self):
+ pass
+
+ def test_disable_invalid(self):
+ pass
+
+ # dnf module lock
+
+ def test_lock_name(self):
+ pass
+
+ def test_lock_name_stream(self):
+ pass
+
+ def test_lock_pkgspec(self):
+ pass
+
+ def test_lock_invalid(self):
+ pass
+
+ # dnf module unlock
+
+ def test_unlock_name(self):
+ pass
+
+ def test_unlock_name_stream(self):
+ pass
+
+ def test_unlock_pkgspec(self):
+ pass
+
+ def test_unlock_invalid(self):
+ pass
+
+ # dnf module info
+
+ def test_info_name(self):
+ pass
+
+ def test_info_name_stream(self):
+ pass
+
+ def test_info_pkgspec(self):
+ pass
+
+ # dnf module list
+
+ def test_list(self):
+ # show latest module versions
+ pass
+
+ def test_list_all(self):
+ # show all module versions
+ pass
+
+ def test_list_enabled(self):
+ pass
+
+ def test_list_installed(self):
+ pass
+
+ # dnf module install / dnf install @
+
+ def test_install_profile_latest(self):
+ self.test_enable_name_stream()
+ self.base.repo_module_dict.install(["httpd/default"])
+ self.base._goal.run()
+ expected = [
+ "basesystem-11-3.noarch",
+ "filesystem-3.2-40.x86_64",
+ "glibc-2.25.90-2.x86_64",
+ "glibc-common-2.25.90-2.x86_64",
+ "httpd-2.4.25-8.x86_64",
+ "libnghttp2-1.21.1-1.x86_64",
+ ]
+ self.assertInstalls(expected)
+
+ def test_install_profile(self):
+ self.test_enable_name_stream()
+ self.base.repo_module_dict.install(["httpd-2.4-1/default"])
+ self.base._goal.run()
+ expected = [
+ "basesystem-11-3.noarch",
+ "filesystem-3.2-40.x86_64",
+ "glibc-2.25.90-2.x86_64",
+ "glibc-common-2.25.90-2.x86_64",
+ "httpd-2.4.25-7.x86_64",
+ "libnghttp2-1.21.1-1.x86_64",
+ ]
+ self.assertInstalls(expected)
+
+ def test_install_two_profiles(self):
+ self.test_enable_name_stream()
+ self.base.repo_module_dict.install(["httpd-2.4-1/default", "httpd-2.4-1/doc"])
+ self.base._goal.run()
+ expected = [
+ "basesystem-11-3.noarch",
+ "filesystem-3.2-40.x86_64",
+ "glibc-2.25.90-2.x86_64",
+ "glibc-common-2.25.90-2.x86_64",
+ "httpd-2.4.25-7.x86_64",
+ "httpd-doc-2.4.25-7.x86_64",
+ "libnghttp2-1.21.1-1.x86_64",
+ ]
+ self.assertInstalls(expected)
+
+ def test_install_two_profiles_different_versions(self):
+ self.test_enable_name_stream()
+ self.base.repo_module_dict.install(["httpd-2.4-1/default", "httpd-2.4-2/doc"])
+ self.base._goal.run()
+ expected = [
+ "basesystem-11-3.noarch",
+ "filesystem-3.2-40.x86_64",
+ "glibc-2.25.90-2.x86_64",
+ "glibc-common-2.25.90-2.x86_64",
+ "httpd-2.4.25-7.x86_64",
+ "httpd-doc-2.4.25-8.x86_64",
+ "libnghttp2-1.21.1-1.x86_64",
+ ]
+ self.assertInstalls(expected)
+
+ def test_install_profile_updated(self):
+ return
+ """
+ # install profile1 from an old module version
+ # then install profile2 from latest module version
+ # -> dnf forces upgrade profile1 to the latest module version
+ """
+
+ self.test_install_profile()
+ self.base.repo_module_dict.install(["httpd-2.4-2/doc"])
+ self.base._goal.run()
+ expected = [
+ "basesystem-11-3.noarch",
+ "filesystem-3.2-40.x86_64",
+ "glibc-2.25.90-2.x86_64",
+ "glibc-common-2.25.90-2.x86_64",
+ "httpd-2.4.25-8.x86_64",
+ "httpd-doc-2.4.25-8.x86_64",
+ "libnghttp2-1.21.1-1.x86_64",
+ ]
+ self.assertInstalls(expected)
+
+ def test_install_deps_same_module_version(self):
+ pass
+
+ # dnf module upgrade / dnf upgrade @
+
+ def test_upgrade(self):
+ pass
+
+ def test_upgrade_lower_rpm_nevra(self):
+ pass
+
+ def test_upgrade_lower_module_nsvap(self):
+ pass
+
+ def test_upgrade_missing_profile(self):
+ pass
+
+ # dnf module downgrade / dnf downgrade @
+
+ def test_downgrade(self):
+ pass
+
+ # dnf module remove / dnf remove @
+
+ def test_remove(self):
+ pass
+
+ def test_remove_shared_rpms(self):
+ # don't remove RPMs that are part of another installed module / module profile
+ # also don't remove RPMs that are required by user-installed RPMs
+ pass
+
+ def test_remove_invalid(self):
+ pass
--
2.13.2