forked from rpms/leapp-repository
83 lines
2.9 KiB
Diff
83 lines
2.9 KiB
Diff
From ae9a953dc111c0b14a8b86b3f0aee26cea1f08b4 Mon Sep 17 00:00:00 2001
|
|
From: Matej Matuska <mmatuska@redhat.com>
|
|
Date: Mon, 1 Sep 2025 23:43:53 +0200
|
|
Subject: [PATCH 18/55] lib/distro: Add tests for existing
|
|
get_distribution_data() function
|
|
|
|
---
|
|
.../common/libraries/tests/test_distro.py | 47 ++++++++++++++++++-
|
|
1 file changed, 46 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/repos/system_upgrade/common/libraries/tests/test_distro.py b/repos/system_upgrade/common/libraries/tests/test_distro.py
|
|
index 3a8f174f..8e866455 100644
|
|
--- a/repos/system_upgrade/common/libraries/tests/test_distro.py
|
|
+++ b/repos/system_upgrade/common/libraries/tests/test_distro.py
|
|
@@ -1,3 +1,4 @@
|
|
+import json
|
|
import os
|
|
|
|
import pytest
|
|
@@ -5,7 +6,7 @@ import pytest
|
|
from leapp.actors import StopActorExecutionError
|
|
from leapp.libraries.common import distro, repofileutils, rhsm
|
|
from leapp.libraries.common.config.architecture import ARCH_ACCEPTED, ARCH_ARM64, ARCH_PPC64LE, ARCH_S390X, ARCH_X86_64
|
|
-from leapp.libraries.common.distro import _get_distro_repofiles, get_distro_repoids
|
|
+from leapp.libraries.common.distro import _get_distro_repofiles, get_distribution_data, get_distro_repoids
|
|
from leapp.libraries.common.testutils import CurrentActorMocked
|
|
from leapp.libraries.stdlib import api
|
|
from leapp.models import RepositoryData, RepositoryFile
|
|
@@ -15,6 +16,50 @@ _CENTOS_REPOFILES = [
|
|
"/etc/yum.repos.d/centos.repo", "/etc/yum.repos.d/centos-addons.repo"
|
|
]
|
|
|
|
+_CUR_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
+
|
|
+
|
|
+@pytest.mark.parametrize('distro', ['rhel', 'centos'])
|
|
+def test_get_distribution_data(monkeypatch, distro):
|
|
+ common_path = os.path.join(_CUR_DIR, "../../files/", 'distro')
|
|
+ monkeypatch.setattr(
|
|
+ api,
|
|
+ "get_common_folder_path",
|
|
+ lambda folder: common_path
|
|
+ )
|
|
+ data_path = os.path.join(common_path, distro, "gpg-signatures.json")
|
|
+
|
|
+ def exists_mocked(path):
|
|
+ assert path == data_path
|
|
+ return True
|
|
+
|
|
+ monkeypatch.setattr(os.path, 'exists', exists_mocked)
|
|
+ ret = get_distribution_data(distro)
|
|
+
|
|
+ with open(data_path) as fp:
|
|
+ assert ret == json.load(fp)
|
|
+
|
|
+
|
|
+@pytest.mark.parametrize('distro', ['rhel', 'centos'])
|
|
+def test_get_distribution_data_not_exists(monkeypatch, distro):
|
|
+ common_path = os.path.join(_CUR_DIR, "../../files/", 'distro')
|
|
+ monkeypatch.setattr(
|
|
+ api,
|
|
+ "get_common_folder_path",
|
|
+ lambda folder: common_path
|
|
+ )
|
|
+ data_path = os.path.join(common_path, distro, "gpg-signatures.json")
|
|
+
|
|
+ def exists_mocked(path):
|
|
+ assert path == data_path
|
|
+ return False
|
|
+
|
|
+ monkeypatch.setattr(os.path, 'exists', exists_mocked)
|
|
+
|
|
+ with pytest.raises(StopActorExecutionError) as err:
|
|
+ get_distribution_data(distro)
|
|
+ assert 'Cannot find distribution signature configuration.' in err
|
|
+
|
|
|
|
def test_get_distro_repofiles(monkeypatch):
|
|
"""
|
|
--
|
|
2.51.1
|
|
|