Import Upstream version 4.12.4
This commit is contained in:
63
ipatests/test_ipaplatform/test_constants.py
Normal file
63
ipatests/test_ipaplatform/test_constants.py
Normal file
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# Copyright (C) 2020 FreeIPA Contributors see COPYING for license
|
||||
#
|
||||
import pytest
|
||||
|
||||
from ipaplatform.base.constants import User, Group
|
||||
|
||||
|
||||
def test_user_root():
|
||||
user = User("root")
|
||||
assert user == "root"
|
||||
assert str(user) == "root"
|
||||
assert type(str(user)) is str
|
||||
assert repr(user) == '<User "root">'
|
||||
assert user.uid == 0
|
||||
assert user.pgid == 0
|
||||
assert user.entity.pw_uid == 0
|
||||
|
||||
assert User(user) is user
|
||||
assert User(str(user)) is not user
|
||||
|
||||
|
||||
def test_user_invalid():
|
||||
invalid = User("invalid")
|
||||
with pytest.raises(ValueError) as e:
|
||||
assert invalid.uid
|
||||
assert str(e.value) == "user 'invalid' not found"
|
||||
|
||||
|
||||
def test_group():
|
||||
group = Group("root")
|
||||
assert group == "root"
|
||||
assert str(group) == "root"
|
||||
assert type(str(group)) is str
|
||||
assert repr(group) == '<Group "root">'
|
||||
assert group.gid == 0
|
||||
assert group.entity.gr_gid == 0
|
||||
|
||||
assert Group(group) is group
|
||||
assert Group(str(group)) is not group
|
||||
|
||||
|
||||
def test_group_invalid():
|
||||
invalid = Group("invalid")
|
||||
with pytest.raises(ValueError) as e:
|
||||
assert invalid.gid
|
||||
assert str(e.value) == "group 'invalid' not found"
|
||||
|
||||
|
||||
@pytest.mark.skip_if_platform("debian", reason="test is Fedora specific")
|
||||
@pytest.mark.skip_if_platform("suse", reason="test is Fedora specific")
|
||||
def test_user_group_daemon():
|
||||
# daemon user / group are always defined
|
||||
user = User("daemon")
|
||||
assert user == "daemon"
|
||||
assert user.uid == 2
|
||||
assert user.pgid == 2
|
||||
|
||||
group = Group("daemon")
|
||||
assert group == "daemon"
|
||||
assert group.gid == 2
|
||||
|
||||
assert Group(user) is not user
|
||||
41
ipatests/test_ipaplatform/test_platforms.py
Normal file
41
ipatests/test_ipaplatform/test_platforms.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#
|
||||
# Copyright (C) 2020 FreeIPA Contributors see COPYING for license
|
||||
#
|
||||
"""Test import and basic properties of platforms
|
||||
"""
|
||||
from importlib import import_module
|
||||
|
||||
import pytest
|
||||
|
||||
from ipaplatform.base.constants import BaseConstantsNamespace, User, Group
|
||||
from ipaplatform.base.paths import BasePathNamespace
|
||||
from ipaplatform.base.services import KnownServices
|
||||
from ipaplatform.base.tasks import BaseTaskNamespace
|
||||
|
||||
PLATFORMS = [
|
||||
"debian",
|
||||
"fedora",
|
||||
"fedora_container",
|
||||
"rhel",
|
||||
"rhel_container",
|
||||
"suse",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", PLATFORMS)
|
||||
def test_import_platform(name):
|
||||
constants = import_module(f"ipaplatform.{name}.constants")
|
||||
assert isinstance(constants.constants, BaseConstantsNamespace)
|
||||
assert issubclass(constants.User, User)
|
||||
assert issubclass(constants.Group, Group)
|
||||
|
||||
paths = import_module(f"ipaplatform.{name}.paths")
|
||||
assert isinstance(paths.paths, BasePathNamespace)
|
||||
|
||||
services = import_module(f"ipaplatform.{name}.services")
|
||||
assert isinstance(services.knownservices, KnownServices)
|
||||
assert isinstance(services.timedate_services, list)
|
||||
assert callable(services.service)
|
||||
|
||||
tasks = import_module(f"ipaplatform.{name}.tasks")
|
||||
assert isinstance(tasks.tasks, BaseTaskNamespace)
|
||||
@@ -4,10 +4,14 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from ipaplatform.tasks import tasks
|
||||
|
||||
|
||||
@pytest.mark.skip_if_platform(
|
||||
"debian", reason="Test is specific to platforms using RPM"
|
||||
)
|
||||
def test_ipa_version():
|
||||
v3 = tasks.parse_ipa_version('3.0')
|
||||
assert v3.version == u'3.0'
|
||||
@@ -47,10 +51,10 @@ def test_detect_container():
|
||||
k, v = item.split('=', 1)
|
||||
if k == 'container':
|
||||
container = v
|
||||
elif os.path.isfile("/run/.containerenv"):
|
||||
container = "podman"
|
||||
elif os.path.isfile("/.dockerenv"):
|
||||
container = "docker"
|
||||
|
||||
detected = tasks.detect_container()
|
||||
if container == 'oci':
|
||||
# systemd doesn't know about podman
|
||||
assert detected in {'container-other', container}
|
||||
else:
|
||||
assert detected == container
|
||||
assert detected == container
|
||||
|
||||
Reference in New Issue
Block a user