mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-23 18:59:56 +00:00
change method spelling
in order to sort method correctly we are going to use the following namiing schema: {subject}_{action}_{details} This schema still have some exceptions, e.g. single word methods, bool methods (is_) and getters in case if they are singular (i.e. there is no any other method with this subject)
This commit is contained in:
@ -9,6 +9,48 @@ from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import MissingArchitecture, MultipleArchitecture
|
||||
|
||||
|
||||
def test_architectures_extract(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate list of available architectures
|
||||
"""
|
||||
args.configuration = configuration.path
|
||||
known_architectures_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.known_architectures")
|
||||
|
||||
Handler.architectures_extract(args)
|
||||
known_architectures_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_architectures_extract_empty(args: argparse.Namespace, configuration: Configuration,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise exception if no available architectures found
|
||||
"""
|
||||
args.command = "config"
|
||||
args.configuration = configuration.path
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.known_architectures", return_value=set())
|
||||
|
||||
with pytest.raises(MissingArchitecture):
|
||||
Handler.architectures_extract(args)
|
||||
|
||||
|
||||
def test_architectures_extract_exception(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise exception on missing architectures
|
||||
"""
|
||||
args.command = "config"
|
||||
mocker.patch.object(Handler, "ALLOW_AUTO_ARCHITECTURE_RUN", False)
|
||||
with pytest.raises(MissingArchitecture):
|
||||
Handler.architectures_extract(args)
|
||||
|
||||
|
||||
def test_architectures_extract_specified(args: argparse.Namespace) -> None:
|
||||
"""
|
||||
must return architecture list if it has been specified
|
||||
"""
|
||||
architectures = args.architecture = ["i686", "x86_64"]
|
||||
assert Handler.architectures_extract(args) == set(architectures)
|
||||
|
||||
|
||||
def test_call(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call inside lock
|
||||
@ -67,48 +109,6 @@ def test_execute_single(args: argparse.Namespace, mocker: MockerFixture) -> None
|
||||
starmap_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_extract_architectures(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate list of available architectures
|
||||
"""
|
||||
args.configuration = configuration.path
|
||||
known_architectures_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.known_architectures")
|
||||
|
||||
Handler.extract_architectures(args)
|
||||
known_architectures_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_extract_architectures_empty(args: argparse.Namespace, configuration: Configuration,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise exception if no available architectures found
|
||||
"""
|
||||
args.command = "config"
|
||||
args.configuration = configuration.path
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.known_architectures", return_value=set())
|
||||
|
||||
with pytest.raises(MissingArchitecture):
|
||||
Handler.extract_architectures(args)
|
||||
|
||||
|
||||
def test_extract_architectures_exception(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise exception on missing architectures
|
||||
"""
|
||||
args.command = "config"
|
||||
mocker.patch.object(Handler, "ALLOW_AUTO_ARCHITECTURE_RUN", False)
|
||||
with pytest.raises(MissingArchitecture):
|
||||
Handler.extract_architectures(args)
|
||||
|
||||
|
||||
def test_extract_architectures_specified(args: argparse.Namespace) -> None:
|
||||
"""
|
||||
must return architecture list if it has been specified
|
||||
"""
|
||||
architectures = args.architecture = ["i686", "x86_64"]
|
||||
assert Handler.extract_architectures(args) == set(architectures)
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration) -> None:
|
||||
"""
|
||||
must raise NotImplemented for missing method
|
||||
|
@ -23,7 +23,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
"""
|
||||
args = _default_args(args)
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.core.sign.gpg.GPG.import_key")
|
||||
application_mock = mocker.patch("ahriman.core.sign.gpg.GPG.key_import")
|
||||
|
||||
KeyImport.run(args, "x86_64", configuration, True)
|
||||
application_mock.assert_called_once()
|
||||
|
@ -33,11 +33,11 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
"""
|
||||
args = _default_args(args)
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
ahriman_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.create_ahriman_configuration")
|
||||
devtools_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.create_devtools_configuration")
|
||||
makepkg_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.create_makepkg_configuration")
|
||||
sudo_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.create_sudo_configuration")
|
||||
executable_mock = mocker.patch("ahriman.application.handlers.setup.Setup.create_executable")
|
||||
ahriman_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_ahriman")
|
||||
devtools_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_devtools")
|
||||
makepkg_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_makepkg")
|
||||
sudo_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_sudo")
|
||||
executable_mock = mocker.patch("ahriman.application.handlers.setup.Setup.executable_create")
|
||||
|
||||
Setup.run(args, "x86_64", configuration, True)
|
||||
ahriman_configuration_mock.assert_called_once()
|
||||
@ -55,7 +55,7 @@ def test_build_command(args: argparse.Namespace) -> None:
|
||||
assert Setup.build_command(args.build_command, "x86_64").name == f"{args.build_command}-x86_64-build"
|
||||
|
||||
|
||||
def test_create_ahriman_configuration(args: argparse.Namespace, configuration: Configuration,
|
||||
def test_configuration_create_ahriman(args: argparse.Namespace, configuration: Configuration,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create configuration for the service
|
||||
@ -66,7 +66,7 @@ def test_create_ahriman_configuration(args: argparse.Namespace, configuration: C
|
||||
write_mock = mocker.patch("ahriman.core.configuration.Configuration.write")
|
||||
|
||||
command = Setup.build_command(args.build_command, "x86_64")
|
||||
Setup.create_ahriman_configuration(args, "x86_64", args.repository, configuration.include)
|
||||
Setup.configuration_create_ahriman(args, "x86_64", args.repository, configuration.include)
|
||||
set_option_mock.assert_has_calls([
|
||||
mock.call(Configuration.section_name("build", "x86_64"), "build_command", str(command)),
|
||||
mock.call("repository", "name", args.repository),
|
||||
@ -78,7 +78,7 @@ def test_create_ahriman_configuration(args: argparse.Namespace, configuration: C
|
||||
write_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_create_devtools_configuration(args: argparse.Namespace, repository_paths: RepositoryPaths,
|
||||
def test_configuration_create_devtools(args: argparse.Namespace, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create configuration for the devtools
|
||||
@ -89,7 +89,7 @@ def test_create_devtools_configuration(args: argparse.Namespace, repository_path
|
||||
add_section_mock = mocker.patch("ahriman.core.configuration.Configuration.add_section")
|
||||
write_mock = mocker.patch("ahriman.core.configuration.Configuration.write")
|
||||
|
||||
Setup.create_devtools_configuration(args.build_command, "x86_64", args.from_configuration,
|
||||
Setup.configuration_create_devtools(args.build_command, "x86_64", args.from_configuration,
|
||||
args.no_multilib, args.repository, repository_paths)
|
||||
add_section_mock.assert_has_calls([
|
||||
mock.call("multilib"),
|
||||
@ -98,7 +98,7 @@ def test_create_devtools_configuration(args: argparse.Namespace, repository_path
|
||||
write_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_create_devtools_configuration_no_multilib(args: argparse.Namespace, repository_paths: RepositoryPaths,
|
||||
def test_configuration_create_devtools_no_multilib(args: argparse.Namespace, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create configuration for the devtools without multilib
|
||||
@ -108,12 +108,12 @@ def test_create_devtools_configuration_no_multilib(args: argparse.Namespace, rep
|
||||
mocker.patch("ahriman.core.configuration.Configuration.set")
|
||||
write_mock = mocker.patch("ahriman.core.configuration.Configuration.write")
|
||||
|
||||
Setup.create_devtools_configuration(args.build_command, "x86_64", args.from_configuration,
|
||||
Setup.configuration_create_devtools(args.build_command, "x86_64", args.from_configuration,
|
||||
True, args.repository, repository_paths)
|
||||
write_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_create_makepkg_configuration(args: argparse.Namespace, repository_paths: RepositoryPaths,
|
||||
def test_configuration_create_makepkg(args: argparse.Namespace, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create makepkg configuration
|
||||
@ -121,11 +121,11 @@ def test_create_makepkg_configuration(args: argparse.Namespace, repository_paths
|
||||
args = _default_args(args)
|
||||
write_text_mock = mocker.patch("pathlib.Path.write_text")
|
||||
|
||||
Setup.create_makepkg_configuration(args.packager, repository_paths)
|
||||
Setup.configuration_create_makepkg(args.packager, repository_paths)
|
||||
write_text_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_create_sudo_configuration(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
def test_configuration_create_sudo(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create sudo configuration
|
||||
"""
|
||||
@ -133,12 +133,12 @@ def test_create_sudo_configuration(args: argparse.Namespace, mocker: MockerFixtu
|
||||
chmod_text_mock = mocker.patch("pathlib.Path.chmod")
|
||||
write_text_mock = mocker.patch("pathlib.Path.write_text")
|
||||
|
||||
Setup.create_sudo_configuration(args.build_command, "x86_64")
|
||||
Setup.configuration_create_sudo(args.build_command, "x86_64")
|
||||
chmod_text_mock.assert_called_once_with(0o400)
|
||||
write_text_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_create_executable(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
def test_executable_create(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create executable
|
||||
"""
|
||||
@ -146,7 +146,7 @@ def test_create_executable(args: argparse.Namespace, mocker: MockerFixture) -> N
|
||||
symlink_text_mock = mocker.patch("pathlib.Path.symlink_to")
|
||||
unlink_text_mock = mocker.patch("pathlib.Path.unlink")
|
||||
|
||||
Setup.create_executable(args.build_command, "x86_64")
|
||||
Setup.executable_create(args.build_command, "x86_64")
|
||||
symlink_text_mock.assert_called_once()
|
||||
unlink_text_mock.assert_called_once()
|
||||
|
||||
|
@ -34,17 +34,17 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
"""
|
||||
args = _default_args(args)
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
get_auth_configuration_mock = mocker.patch("ahriman.application.handlers.User.get_auth_configuration")
|
||||
create_configuration_mock = mocker.patch("ahriman.application.handlers.User.create_configuration")
|
||||
write_configuration_mock = mocker.patch("ahriman.application.handlers.User.write_configuration")
|
||||
create_user = mocker.patch("ahriman.application.handlers.User.create_user")
|
||||
get_auth_configuration_mock = mocker.patch("ahriman.application.handlers.User.configuration_get")
|
||||
create_configuration_mock = mocker.patch("ahriman.application.handlers.User.configuration_create")
|
||||
write_configuration_mock = mocker.patch("ahriman.application.handlers.User.configuration_write")
|
||||
create_user_mock = mocker.patch("ahriman.application.handlers.User.user_create")
|
||||
get_salt_mock = mocker.patch("ahriman.application.handlers.User.get_salt")
|
||||
reload_mock = mocker.patch("ahriman.core.status.client.Client.reload_auth")
|
||||
|
||||
User.run(args, "x86_64", configuration, True)
|
||||
get_auth_configuration_mock.assert_called_once()
|
||||
create_configuration_mock.assert_called_once()
|
||||
create_user.assert_called_once()
|
||||
create_user_mock.assert_called_once()
|
||||
get_salt_mock.assert_called_once()
|
||||
write_configuration_mock.assert_called_once()
|
||||
reload_mock.assert_called_once()
|
||||
@ -57,9 +57,9 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, mock
|
||||
args = _default_args(args)
|
||||
args.action = Action.Remove
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
get_auth_configuration_mock = mocker.patch("ahriman.application.handlers.User.get_auth_configuration")
|
||||
create_configuration_mock = mocker.patch("ahriman.application.handlers.User.create_configuration")
|
||||
write_configuration_mock = mocker.patch("ahriman.application.handlers.User.write_configuration")
|
||||
get_auth_configuration_mock = mocker.patch("ahriman.application.handlers.User.configuration_get")
|
||||
create_configuration_mock = mocker.patch("ahriman.application.handlers.User.configuration_create")
|
||||
write_configuration_mock = mocker.patch("ahriman.application.handlers.User.configuration_write")
|
||||
reload_mock = mocker.patch("ahriman.core.status.client.Client.reload_auth")
|
||||
|
||||
User.run(args, "x86_64", configuration, True)
|
||||
@ -75,41 +75,16 @@ def test_run_no_reload(args: argparse.Namespace, configuration: Configuration, m
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.no_reload = True
|
||||
mocker.patch("ahriman.application.handlers.User.get_auth_configuration")
|
||||
mocker.patch("ahriman.application.handlers.User.create_configuration")
|
||||
mocker.patch("ahriman.application.handlers.User.write_configuration")
|
||||
mocker.patch("ahriman.application.handlers.User.configuration_get")
|
||||
mocker.patch("ahriman.application.handlers.User.configuration_create")
|
||||
mocker.patch("ahriman.application.handlers.User.configuration_write")
|
||||
reload_mock = mocker.patch("ahriman.core.status.client.Client.reload_auth")
|
||||
|
||||
User.run(args, "x86_64", configuration, True)
|
||||
reload_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_clear_user(configuration: Configuration, user: MUser) -> None:
|
||||
"""
|
||||
must clear user from configuration
|
||||
"""
|
||||
section = Configuration.section_name("auth", user.access.value)
|
||||
configuration.set_option(section, user.username, user.password)
|
||||
|
||||
User.clear_user(configuration, user)
|
||||
assert configuration.get(section, user.username, fallback=None) is None
|
||||
|
||||
|
||||
def test_clear_user_multiple_sections(configuration: Configuration, user: MUser) -> None:
|
||||
"""
|
||||
must clear user from configuration from all sections
|
||||
"""
|
||||
for role in UserAccess:
|
||||
section = Configuration.section_name("auth", role.value)
|
||||
configuration.set_option(section, user.username, user.password)
|
||||
|
||||
User.clear_user(configuration, user)
|
||||
for role in UserAccess:
|
||||
section = Configuration.section_name("auth", role.value)
|
||||
assert configuration.get(section, user.username, fallback=None) is None
|
||||
|
||||
|
||||
def test_create_configuration(configuration: Configuration, user: MUser, mocker: MockerFixture) -> None:
|
||||
def test_configuration_create(configuration: Configuration, user: MUser, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must correctly create configuration file
|
||||
"""
|
||||
@ -117,14 +92,14 @@ def test_create_configuration(configuration: Configuration, user: MUser, mocker:
|
||||
mocker.patch("pathlib.Path.open")
|
||||
set_mock = mocker.patch("ahriman.core.configuration.Configuration.set_option")
|
||||
|
||||
User.create_configuration(configuration, user, "salt", False)
|
||||
User.configuration_create(configuration, user, "salt", False)
|
||||
set_mock.assert_has_calls([
|
||||
mock.call("auth", "salt", pytest.helpers.anyvar(str)),
|
||||
mock.call(section, user.username, pytest.helpers.anyvar(str))
|
||||
])
|
||||
|
||||
|
||||
def test_create_configuration_user_exists(configuration: Configuration, user: MUser, mocker: MockerFixture) -> None:
|
||||
def test_configuration_create_user_exists(configuration: Configuration, user: MUser, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must correctly update configuration file if user already exists
|
||||
"""
|
||||
@ -132,12 +107,12 @@ def test_create_configuration_user_exists(configuration: Configuration, user: MU
|
||||
configuration.set_option(section, user.username, "")
|
||||
mocker.patch("pathlib.Path.open")
|
||||
|
||||
User.create_configuration(configuration, user, "salt", False)
|
||||
User.configuration_create(configuration, user, "salt", False)
|
||||
generated = MUser.from_option(user.username, configuration.get(section, user.username))
|
||||
assert generated.check_credentials(user.password, configuration.get("auth", "salt"))
|
||||
|
||||
|
||||
def test_create_configuration_with_plain_password(
|
||||
def test_configuration_create_with_plain_password(
|
||||
configuration: Configuration,
|
||||
user: MUser,
|
||||
mocker: MockerFixture) -> None:
|
||||
@ -147,7 +122,7 @@ def test_create_configuration_with_plain_password(
|
||||
section = Configuration.section_name("auth", user.access.value)
|
||||
mocker.patch("pathlib.Path.open")
|
||||
|
||||
User.create_configuration(configuration, user, "salt", True)
|
||||
User.configuration_create(configuration, user, "salt", True)
|
||||
|
||||
generated = MUser.from_option(user.username, configuration.get(section, user.username))
|
||||
service = MUser.from_option(configuration.get("web", "username"), configuration.get("web", "password"))
|
||||
@ -155,28 +130,67 @@ def test_create_configuration_with_plain_password(
|
||||
assert generated.check_credentials(service.password, configuration.get("auth", "salt"))
|
||||
|
||||
|
||||
def test_create_user(args: argparse.Namespace, user: MUser) -> None:
|
||||
def test_configuration_get_exists(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create user
|
||||
must load configuration from filesystem
|
||||
"""
|
||||
args = _default_args(args)
|
||||
generated = User.create_user(args)
|
||||
assert generated.username == user.username
|
||||
assert generated.access == user.access
|
||||
mocker.patch("pathlib.Path.open")
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
read_mock = mocker.patch("ahriman.core.configuration.Configuration.read")
|
||||
|
||||
assert User.configuration_get(Path("path"))
|
||||
read_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_create_user_getpass(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
def test_configuration_get_not_exists(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create user and get password from command line
|
||||
must try to load configuration from filesystem
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.password = None
|
||||
mocker.patch("pathlib.Path.open")
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
read_mock = mocker.patch("ahriman.core.configuration.Configuration.read")
|
||||
|
||||
getpass_mock = mocker.patch("getpass.getpass", return_value="password")
|
||||
generated = User.create_user(args)
|
||||
assert User.configuration_get(Path("path"))
|
||||
read_mock.assert_called_once()
|
||||
|
||||
getpass_mock.assert_called_once()
|
||||
assert generated.password == "password"
|
||||
|
||||
def test_configuration_write(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must write configuration
|
||||
"""
|
||||
mocker.patch("pathlib.Path.open")
|
||||
write_mock = mocker.patch("ahriman.core.configuration.Configuration.write")
|
||||
chmod_mock = mocker.patch("pathlib.Path.chmod")
|
||||
|
||||
User.configuration_write(configuration, secure=True)
|
||||
write_mock.assert_called_once()
|
||||
chmod_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_configuration_write_insecure(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must write configuration without setting file permissions
|
||||
"""
|
||||
mocker.patch("pathlib.Path.open")
|
||||
mocker.patch("ahriman.core.configuration.Configuration.write")
|
||||
chmod_mock = mocker.patch("pathlib.Path.chmod")
|
||||
|
||||
User.configuration_write(configuration, secure=False)
|
||||
chmod_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_configuration_write_not_loaded(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must do nothing in case if configuration is not loaded
|
||||
"""
|
||||
configuration.path = None
|
||||
mocker.patch("pathlib.Path.open")
|
||||
write_mock = mocker.patch("ahriman.core.configuration.Configuration.write")
|
||||
chmod_mock = mocker.patch("pathlib.Path.chmod")
|
||||
|
||||
User.configuration_write(configuration, secure=True)
|
||||
write_mock.assert_not_called()
|
||||
chmod_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_get_salt_read(configuration: Configuration) -> None:
|
||||
@ -197,67 +211,53 @@ def test_get_salt_generate(configuration: Configuration) -> None:
|
||||
assert len(salt) == 16
|
||||
|
||||
|
||||
def test_get_auth_configuration_exists(mocker: MockerFixture) -> None:
|
||||
def test_user_clear(configuration: Configuration, user: MUser) -> None:
|
||||
"""
|
||||
must load configuration from filesystem
|
||||
must clear user from configuration
|
||||
"""
|
||||
mocker.patch("pathlib.Path.open")
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
read_mock = mocker.patch("ahriman.core.configuration.Configuration.read")
|
||||
section = Configuration.section_name("auth", user.access.value)
|
||||
configuration.set_option(section, user.username, user.password)
|
||||
|
||||
assert User.get_auth_configuration(Path("path"))
|
||||
read_mock.assert_called_once()
|
||||
User.user_clear(configuration, user)
|
||||
assert configuration.get(section, user.username, fallback=None) is None
|
||||
|
||||
|
||||
def test_get_auth_configuration_not_exists(mocker: MockerFixture) -> None:
|
||||
def test_user_clear_multiple_sections(configuration: Configuration, user: MUser) -> None:
|
||||
"""
|
||||
must try to load configuration from filesystem
|
||||
must clear user from configuration from all sections
|
||||
"""
|
||||
mocker.patch("pathlib.Path.open")
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
read_mock = mocker.patch("ahriman.core.configuration.Configuration.read")
|
||||
for role in UserAccess:
|
||||
section = Configuration.section_name("auth", role.value)
|
||||
configuration.set_option(section, user.username, user.password)
|
||||
|
||||
assert User.get_auth_configuration(Path("path"))
|
||||
read_mock.assert_called_once()
|
||||
User.user_clear(configuration, user)
|
||||
for role in UserAccess:
|
||||
section = Configuration.section_name("auth", role.value)
|
||||
assert configuration.get(section, user.username, fallback=None) is None
|
||||
|
||||
|
||||
def test_write_configuration(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
def test_user_create(args: argparse.Namespace, user: MUser) -> None:
|
||||
"""
|
||||
must write configuration
|
||||
must create user
|
||||
"""
|
||||
mocker.patch("pathlib.Path.open")
|
||||
write_mock = mocker.patch("ahriman.core.configuration.Configuration.write")
|
||||
chmod_mock = mocker.patch("pathlib.Path.chmod")
|
||||
|
||||
User.write_configuration(configuration, secure=True)
|
||||
write_mock.assert_called_once()
|
||||
chmod_mock.assert_called_once()
|
||||
args = _default_args(args)
|
||||
generated = User.user_create(args)
|
||||
assert generated.username == user.username
|
||||
assert generated.access == user.access
|
||||
|
||||
|
||||
def test_write_configuration_insecure(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
def test_user_create_getpass(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must write configuration without setting file permissions
|
||||
must create user and get password from command line
|
||||
"""
|
||||
mocker.patch("pathlib.Path.open")
|
||||
mocker.patch("ahriman.core.configuration.Configuration.write")
|
||||
chmod_mock = mocker.patch("pathlib.Path.chmod")
|
||||
args = _default_args(args)
|
||||
args.password = None
|
||||
|
||||
User.write_configuration(configuration, secure=False)
|
||||
chmod_mock.assert_not_called()
|
||||
getpass_mock = mocker.patch("getpass.getpass", return_value="password")
|
||||
generated = User.user_create(args)
|
||||
|
||||
|
||||
def test_write_configuration_not_loaded(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must do nothing in case if configuration is not loaded
|
||||
"""
|
||||
configuration.path = None
|
||||
mocker.patch("pathlib.Path.open")
|
||||
write_mock = mocker.patch("ahriman.core.configuration.Configuration.write")
|
||||
chmod_mock = mocker.patch("pathlib.Path.chmod")
|
||||
|
||||
User.write_configuration(configuration, secure=True)
|
||||
write_mock.assert_not_called()
|
||||
chmod_mock.assert_not_called()
|
||||
getpass_mock.assert_called_once()
|
||||
assert generated.password == "password"
|
||||
|
||||
|
||||
def test_disallow_auto_architecture_run() -> None:
|
||||
|
Reference in New Issue
Block a user