Package
publish / publish (push) Successful in 10m29s

This commit is contained in:
khodowany
2026-09-30 19:45:17 -05:00
parent 83232175e3
commit 3efbe5020a
28 changed files with 641 additions and 188 deletions
+13 -54
View File
@@ -58,7 +58,7 @@ class upload_packages_test(unittest.TestCase):
"name": "sample",
},
}
return modulus.cli.build_context(repo_root or pathlib.Path(os.getcwd()), config)
return modulus.cli.build_context(repo_root or pathlib.Path(os.getcwd()), modulus.config.normalize(config))
def test_cli_import_does_not_import_conan_recipe_module(self):
repo = pathlib.Path(__file__).resolve().parents[1]
command = [
@@ -345,6 +345,17 @@ class upload_packages_test(unittest.TestCase):
def test_conan_remote_url_uses_config_by_default(self):
with unittest.mock.patch.dict(os.environ, {}, clear=True):
self.assertEqual(modulus.cli.conan_remote_url(self.context()), "https://example.test/conan")
@unittest.mock.patch.object(modulus.cli, "ensure_build_image", return_value=0)
@unittest.mock.patch.object(modulus.cli, "run", return_value=0)
@unittest.mock.patch.object(modulus.cli, "in_container", return_value=False)
def test_publish_forwards_credentials_but_python_does_not(self, in_container, run, ensure_image):
context = self.context()
with unittest.mock.patch.dict(os.environ, {"PACKAGE_REGISTRY_TOKEN": "secret"}, clear=True):
modulus.cli.docker_run(context, ["tools/publish.py"])
self.assertIn("PACKAGE_REGISTRY_TOKEN", run.call_args.args[1])
self.assertNotIn("secret", run.call_args.args[1])
modulus.cli.docker_run(context, ["tools/python.py", "-m", "generator"])
self.assertNotIn("PACKAGE_REGISTRY_TOKEN", run.call_args.args[1])
def test_conan_remote_url_uses_config_in_ci(self):
with unittest.mock.patch.dict(
os.environ,
@@ -905,7 +916,7 @@ class upload_packages_test(unittest.TestCase):
with unittest.mock.patch.object(modulus.cli, "run", side_effect=fake_run) as run:
status, artifacts = modulus.cli.create_artifact_package(context, context.default_target, update=False, no_remote=True)
self.assertEqual(status, 0)
archive = repo / "build" / "packages" / "sample-native.tar.gz"
archive = repo / "build" / "packages" / "sample_native.tar.gz"
checksum = archive.with_name(archive.name + ".sha256")
self.assertEqual(artifacts, [archive, checksum])
self.assertTrue(archive.is_file())
@@ -922,58 +933,6 @@ class upload_packages_test(unittest.TestCase):
cmake_command = run.call_args_list[1].args[1]
self.assertIn("-DSAMPLE_WITH_WEB=ON", cmake_command)
self.assertIn(f"-DCMAKE_INSTALL_PREFIX={repo / 'build' / 'build_common' / 'artifacts' / 'native' / 'stage' / 'usr'}", cmake_command)
@unittest.mock.patch.object(modulus.cli, "run", return_value=0)
@unittest.mock.patch.object(modulus.cli, "run_capture")
@unittest.mock.patch.object(pathlib.Path, "is_file", return_value=True)
def test_generic_artifact_upload_uses_package_registry_credentials(self, exists, capture, run):
context = self.context()
archive = pathlib.Path("build/packages/sample-native.tar.gz")
with unittest.mock.patch.dict(
os.environ,
{
"PACKAGE_REGISTRY_USER": "dev",
"PACKAGE_REGISTRY_TOKEN": "secret",
},
clear=True,
):
for response in ("204", "404"):
capture.return_value = subprocess.CompletedProcess([], 0, stdout=response, stderr="")
self.assertEqual(modulus.cli.upload_generic_artifact(context, archive), 0)
self.assertEqual(capture.call_args.args[1], ["curl", "--silent", "--show-error", "--user", "dev:secret", "--request", "DELETE", "--output", os.devnull, "--write-out", "%{http_code}", "https://example.test/api/packages/acme/generic/sample/latest/sample-native.tar.gz"])
self.assertEqual(capture.call_args.kwargs["display_command"][4], "dev:<hidden>")
self.assertEqual(
run.call_args.args[1],
[
"curl",
"--fail",
"--silent",
"--show-error",
"--user",
"dev:secret",
"--upload-file",
archive,
"https://example.test/api/packages/acme/generic/sample/latest/sample-native.tar.gz",
],
)
self.assertEqual(
run.call_args.kwargs["display_command"][5],
"dev:<hidden>",
)
@unittest.mock.patch.object(modulus.cli, "package_registry_credentials", return_value=("dev", "secret"))
@unittest.mock.patch.object(pathlib.Path, "is_file", return_value=True)
@unittest.mock.patch.object(modulus.cli, "run_capture")
@unittest.mock.patch.object(modulus.cli, "run")
def test_artifact_upload_stops_if_replacement_fails(self, run, capture, exists, credentials):
for status, response in ((0, "401"), (0, "500"), (7, "000")):
with self.subTest(status=status, response=response):
capture.return_value = subprocess.CompletedProcess([], status, stdout=response, stderr="")
self.assertNotEqual(modulus.cli.upload_generic_artifact(self.context(), pathlib.Path("sample-native.tar.gz")), 0)
run.assert_not_called()
@unittest.mock.patch.object(modulus.cli, "run_capture")
def test_missing_artifact_does_not_touch_registry(self, capture):
with tempfile.TemporaryDirectory() as temporary:
self.assertEqual(modulus.cli.upload_generic_artifact(self.context(), pathlib.Path(temporary) / "missing.tar.gz"), 1)
capture.assert_not_called()
@unittest.mock.patch.object(modulus.cli, "in_docker", return_value=True)
@unittest.mock.patch.object(modulus.cli, "create_artifact_package", return_value=(0, []))
def test_artifact_command_needs_no_release_argument(self, create, docker):