mirror of
https://github.com/d9pouces/id_configurator.git
synced 2026-11-09 01:47:21 +01:00
feat: new configurations for APK/Java/Python/Yum
Signed-off-by: d9pouces <github@19pouces.net>
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
from id_configurator.config import Configuration
|
||||
from id_configurator.context import Context
|
||||
from id_configurator.modules.python import PythonModule
|
||||
|
||||
ONE_REPO_CONFIG = {
|
||||
"uuid": "12345678-1234-5678-1234-567812345678",
|
||||
"organisation": "InterDiode",
|
||||
"configurations": {
|
||||
"python": {
|
||||
"repositories": [
|
||||
{"name": "interdiode", "index-url": "https://example.invalid/simple"}
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
TWO_REPOS_CONFIG = {
|
||||
"uuid": "12345678-1234-5678-1234-567812345678",
|
||||
"organisation": "InterDiode",
|
||||
"configurations": {
|
||||
"python": {
|
||||
"repositories": [
|
||||
{"name": "interdiode", "index-url": "https://example.invalid/simple"},
|
||||
{
|
||||
"name": "interdiode-extra",
|
||||
"index-url": "https://example2.invalid/simple",
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_is_relevant_false_without_repositories(tmp_path) -> None:
|
||||
config = Configuration.model_validate(
|
||||
{"uuid": "12345678-1234-5678-1234-567812345678", "organisation": "InterDiode"}
|
||||
)
|
||||
context = Context(config=config, dst=tmp_path / "dst", src=None)
|
||||
assert PythonModule().is_relevant(context) is False
|
||||
|
||||
|
||||
def test_is_relevant_true_with_repositories(tmp_path) -> None:
|
||||
config = Configuration.model_validate(ONE_REPO_CONFIG)
|
||||
context = Context(config=config, dst=tmp_path / "dst", src=None)
|
||||
assert PythonModule().is_relevant(context) is True
|
||||
|
||||
|
||||
def test_apply_single_repository(tmp_path) -> None:
|
||||
config = Configuration.model_validate(ONE_REPO_CONFIG)
|
||||
dst = tmp_path / "dst"
|
||||
context = Context(config=config, dst=dst, src=None)
|
||||
|
||||
PythonModule().apply(context)
|
||||
|
||||
pip_conf = (dst / "etc/pip.conf").read_text(encoding="utf-8")
|
||||
assert pip_conf == (
|
||||
"[global]\nindex-url = https://example.invalid/simple\ncert = /etc/ssl/certs/ca-certificates.crt\n"
|
||||
)
|
||||
|
||||
uv_toml = (dst / "etc/uv/uv.toml").read_text(encoding="utf-8")
|
||||
assert uv_toml == (
|
||||
'native-tls = true\n\n[[index]]\nname = "interdiode"\nurl = "https://example.invalid/simple"\ndefault = true\n'
|
||||
)
|
||||
|
||||
poetry_config = (dst / "root/.config/pypoetry/config.toml").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
assert poetry_config == (
|
||||
"[repositories.interdiode]\n"
|
||||
'url = "https://example.invalid/simple"\n'
|
||||
"\n"
|
||||
"[certificates.interdiode]\n"
|
||||
'cert = "/etc/ssl/certs/ca-certificates.crt"\n'
|
||||
)
|
||||
|
||||
assert not (dst / "usr/lib").exists()
|
||||
|
||||
|
||||
def test_apply_multiple_repositories(tmp_path) -> None:
|
||||
config = Configuration.model_validate(TWO_REPOS_CONFIG)
|
||||
dst = tmp_path / "dst"
|
||||
context = Context(config=config, dst=dst, src=None)
|
||||
|
||||
PythonModule().apply(context)
|
||||
|
||||
pip_conf = (dst / "etc/pip.conf").read_text(encoding="utf-8")
|
||||
assert pip_conf == (
|
||||
"[global]\n"
|
||||
"index-url = https://example.invalid/simple\n"
|
||||
"extra-index-url =\n"
|
||||
" https://example2.invalid/simple\n"
|
||||
"cert = /etc/ssl/certs/ca-certificates.crt\n"
|
||||
)
|
||||
|
||||
uv_toml = (dst / "etc/uv/uv.toml").read_text(encoding="utf-8")
|
||||
assert uv_toml == (
|
||||
"native-tls = true\n\n"
|
||||
"[[index]]\n"
|
||||
'name = "interdiode"\n'
|
||||
'url = "https://example.invalid/simple"\n'
|
||||
"default = true\n\n"
|
||||
"[[index]]\n"
|
||||
'name = "interdiode-extra"\n'
|
||||
'url = "https://example2.invalid/simple"\n'
|
||||
)
|
||||
|
||||
|
||||
def test_apply_writes_distutils_cfg_for_detected_python_prefixes(tmp_path) -> None:
|
||||
config = Configuration.model_validate(ONE_REPO_CONFIG)
|
||||
src = tmp_path / "src"
|
||||
(src / "usr/lib/python3.11").mkdir(parents=True)
|
||||
(src / "usr/local/lib/python3.12").mkdir(parents=True)
|
||||
(src / "usr/lib/not-python").mkdir(parents=True)
|
||||
dst = tmp_path / "dst"
|
||||
context = Context(config=config, dst=dst, src=src)
|
||||
|
||||
PythonModule().apply(context)
|
||||
|
||||
content_311 = (dst / "usr/lib/python3.11/distutils/distutils.cfg").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
assert content_311 == "[easy_install]\nindex_url = https://example.invalid/simple\n"
|
||||
|
||||
content_312 = (dst / "usr/local/lib/python3.12/distutils/distutils.cfg").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
assert content_312 == "[easy_install]\nindex_url = https://example.invalid/simple\n"
|
||||
|
||||
assert not (dst / "usr/lib/not-python").exists()
|
||||
|
||||
|
||||
def test_apply_without_src_skips_distutils_cfg(tmp_path) -> None:
|
||||
config = Configuration.model_validate(ONE_REPO_CONFIG)
|
||||
dst = tmp_path / "dst"
|
||||
context = Context(config=config, dst=dst, src=None)
|
||||
|
||||
PythonModule().apply(context)
|
||||
|
||||
assert not (dst / "usr").exists()
|
||||
Reference in New Issue
Block a user