-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fbff2a
commit 455759b
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...unit_tests/pyanaconda_tests/modules/payloads/payload/test_module_payload_flatpak_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# | ||
# Copyright (C) 2025 Red Hat, Inc. | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# the GNU General Public License v.2, or (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY expressed or implied, including the implied warranties of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. You should have received a copy of the | ||
# GNU General Public License along with this program; if not, write to the | ||
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the | ||
# source code or documentation are not subject to the GNU General Public | ||
# License and may only be used or replicated with the express permission of | ||
# Red Hat, Inc. | ||
# | ||
# Red Hat Author(s): Jiri Konecny <[email protected]> | ||
# | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from pyanaconda.modules.payloads.payload.flatpak.utils import ( | ||
canonicalize_flatpak_ref, | ||
get_container_arch, | ||
) | ||
|
||
|
||
class FlatpakUtilsTestCase(unittest.TestCase): | ||
"""Test flatpak module utility functions.""" | ||
|
||
@patch("pyanaconda.modules.payloads.payload.flatpak.utils.get_arch") | ||
def test_get_container_arch(self, get_arch): | ||
"""Test get_container_arch function.""" | ||
|
||
get_arch.return_value = "x86_64" | ||
assert get_container_arch() == "amd64" | ||
|
||
get_arch.return_value = "aarch64" | ||
assert get_container_arch() == "arm64" | ||
|
||
# Assisted by watsonx Code Assistant | ||
@patch("pyanaconda.modules.payloads.payload.flatpak.utils.get_container_arch") | ||
def test_canonicalize_flatpak_ref(self, get_container_arch_mock): | ||
"""Test canonicalize_flatpak_ref function.""" | ||
get_container_arch_mock.return_value = "amd64" | ||
|
||
ref = "org.fedoraproject.Stable:app/org.example.Foo//stable" | ||
collection, ref = canonicalize_flatpak_ref(ref) | ||
assert collection == "org.fedoraproject.Stable" | ||
assert ref == "app/org.example.Foo/amd64/stable" | ||
|
||
ref = "app/org.example.Foo//stable" | ||
collection, ref = canonicalize_flatpak_ref(ref) | ||
assert collection is None | ||
assert ref == "app/org.example.Foo/amd64/stable" | ||
|
||
ref = "app/org.example.Foo/arm64/stable" | ||
collection, ref = canonicalize_flatpak_ref(ref) | ||
assert collection is None | ||
assert ref == "app/org.example.Foo/arm64/stable" | ||
|
||
ref = "org.example.Foo//stable" | ||
with pytest.raises(RuntimeError): | ||
canonicalize_flatpak_ref(ref) |