fixed testpypi upload
This commit is contained in:
@@ -346,6 +346,63 @@ def test_publish_refuses_when_release_already_exists(tmp_path, monkeypatch, caps
|
||||
assert "already exists; nothing to publish" in capsys.readouterr().out
|
||||
|
||||
|
||||
def _synthetic_report_layout(tmp_path: Path, version: str) -> tuple[Path, Path]:
|
||||
"""A fake SDK checkout with wheels and a passing preflight report."""
|
||||
sdk = tmp_path / "sdk"
|
||||
wheel_dir = sdk / "SDK" / version
|
||||
wheel_dir.mkdir(parents=True)
|
||||
wheel = wheel_dir / f"orisys-{version}-cp310-cp310-win_amd64.whl"
|
||||
wheel.write_bytes(b"wheel")
|
||||
|
||||
report_dir = sdk / "build" / "release" / "reports" / version
|
||||
report_dir.mkdir(parents=True)
|
||||
(report_dir / "preflight.json").write_text(
|
||||
json.dumps(_report_payload(version, [wheel])), encoding="utf-8"
|
||||
)
|
||||
return sdk, wheel
|
||||
|
||||
|
||||
def test_upload_phases_default_is_testpypi_only():
|
||||
assert pypi.upload_phases(pypi.Options(version="1.2.3")) == ["testpypi"]
|
||||
|
||||
|
||||
def test_upload_phases_confirm_pypi_adds_the_real_index():
|
||||
options = pypi.Options(version="1.2.3", confirm_pypi=True)
|
||||
assert pypi.upload_phases(options) == ["testpypi", "pypi"]
|
||||
|
||||
|
||||
def test_upload_phases_pypi_only_skips_the_rehearsal():
|
||||
# The relevant case: a production token cannot be used against TestPyPI.
|
||||
assert pypi.upload_phases(pypi.Options(version="1.2.3", pypi_only=True)) == ["pypi"]
|
||||
|
||||
|
||||
def test_pypi_only_dry_run_targets_pypi_only(tmp_path, monkeypatch, capsys):
|
||||
sdk, wheel = _synthetic_report_layout(tmp_path, "1.2.3")
|
||||
monkeypatch.setattr(pypi, "REPO_ROOT", sdk)
|
||||
monkeypatch.setattr(pypi, "index_state", lambda index, **k: pypi.IndexState(versions=[]))
|
||||
from release import auth
|
||||
|
||||
auth.write_token("pypi", "pypi-" + "A" * 30, path=tmp_path / ".pypirc")
|
||||
monkeypatch.setattr(auth, "pypirc_path", lambda: tmp_path / ".pypirc")
|
||||
|
||||
exit_code = pypi.publish(
|
||||
pypi.Options(version="1.2.3", apply=False, pypi_only=True, skip_check=True)
|
||||
)
|
||||
output = capsys.readouterr().out
|
||||
assert exit_code == 0
|
||||
assert "--pypi-only" in output
|
||||
assert "upload 1 wheel(s) to pypi" in output
|
||||
assert "testpypi" not in output
|
||||
|
||||
|
||||
def test_pypi_only_and_confirm_pypi_are_mutually_exclusive():
|
||||
from release.cli import _cmd_pypi
|
||||
|
||||
with pytest.raises(SystemExit) as excinfo:
|
||||
_cmd_pypi(["--version", "1.2.3", "--pypi-only", "--confirm-pypi"])
|
||||
assert excinfo.value.code == 2
|
||||
|
||||
|
||||
def test_manifest_checks_use_the_python_placeholder():
|
||||
entry = github.manifest_entry()
|
||||
for command in entry["checks"]:
|
||||
@@ -367,27 +424,35 @@ def test_twine_upload_argv_defaults_to_pypi():
|
||||
assert "--repository" not in argv
|
||||
|
||||
|
||||
def test_credentials_hint_reports_missing(monkeypatch, tmp_path):
|
||||
def test_credentials_hint_points_at_the_setup_command(tmp_path, monkeypatch):
|
||||
from release import auth
|
||||
|
||||
monkeypatch.setattr(auth, "pypirc_path", lambda: tmp_path / ".pypirc")
|
||||
monkeypatch.delenv("TWINE_PASSWORD", raising=False)
|
||||
monkeypatch.delenv("TWINE_USERNAME", raising=False)
|
||||
monkeypatch.setattr(pypi.Path, "home", lambda: tmp_path)
|
||||
hint = pypi.credentials_hint()
|
||||
hint = pypi.credentials_hint("pypi")
|
||||
assert hint is not None
|
||||
assert "TWINE_PASSWORD" in hint
|
||||
assert "release auth --set-token pypi" in hint
|
||||
|
||||
|
||||
def test_credentials_hint_accepts_env(monkeypatch):
|
||||
monkeypatch.setenv("TWINE_USERNAME", "__token__")
|
||||
monkeypatch.setenv("TWINE_PASSWORD", "pypi-secret")
|
||||
assert pypi.credentials_hint() is None
|
||||
def test_credentials_hint_for_testpypi_mentions_pypi_only(tmp_path, monkeypatch):
|
||||
from release import auth
|
||||
|
||||
|
||||
def test_credentials_hint_accepts_pypirc(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(auth, "pypirc_path", lambda: tmp_path / ".pypirc")
|
||||
monkeypatch.delenv("TWINE_PASSWORD", raising=False)
|
||||
monkeypatch.delenv("TWINE_USERNAME", raising=False)
|
||||
(tmp_path / ".pypirc").write_text("[pypi]\n", encoding="utf-8")
|
||||
monkeypatch.setattr(pypi.Path, "home", lambda: tmp_path)
|
||||
assert pypi.credentials_hint() is None
|
||||
hint = pypi.credentials_hint("testpypi")
|
||||
assert hint is not None
|
||||
assert "--set-token testpypi" in hint
|
||||
assert "--pypi-only" in hint
|
||||
|
||||
|
||||
def test_credentials_hint_silent_when_configured(tmp_path, monkeypatch):
|
||||
from release import auth
|
||||
|
||||
path = tmp_path / ".pypirc"
|
||||
auth.write_token("pypi", "pypi-" + "A" * 30, path=path)
|
||||
monkeypatch.setattr(auth, "pypirc_path", lambda: path)
|
||||
monkeypatch.delenv("TWINE_PASSWORD", raising=False)
|
||||
assert pypi.credentials_hint("pypi") is None
|
||||
|
||||
|
||||
def test_index_state_parses_versions(monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user