test_cmd_hub_collaborator_accept.py
python
sha256:f0e66c9b996b798fb99b1fe8cc7ef318784f5285940729f796e0f789fab79ea5
feat(musehub#193): muse hub collaborator accept
Sonnet 5
patch
3 days ago
| 1 | """Tests for `muse hub collaborator accept` — musehub#193. |
| 2 | |
| 3 | No prior test file existed for muse/cli/commands/hub/collaborators.py at |
| 4 | all; this covers the new `accept` verb specifically by mocking the three |
| 5 | hub-plumbing calls (_get_hub_and_identity / _resolve_repo_id / _hub_api), |
| 6 | which every verb in this module goes through. |
| 7 | """ |
| 8 | |
| 9 | from __future__ import annotations |
| 10 | |
| 11 | import argparse |
| 12 | import json |
| 13 | from unittest.mock import MagicMock, patch |
| 14 | |
| 15 | import pytest |
| 16 | |
| 17 | from muse.cli.commands.hub import collaborators |
| 18 | |
| 19 | |
| 20 | class TestRegisterFlags: |
| 21 | def _parse(self, *extra: str) -> argparse.Namespace: |
| 22 | p = argparse.ArgumentParser() |
| 23 | sub = p.add_subparsers() |
| 24 | collaborators.register(sub) |
| 25 | return p.parse_args(["collaborator", "accept", *extra]) |
| 26 | |
| 27 | def test_no_positional_arg_required(self) -> None: |
| 28 | ns = self._parse() |
| 29 | assert ns.func is collaborators.run_collaborator_accept |
| 30 | |
| 31 | def test_json_flag(self) -> None: |
| 32 | ns = self._parse("--json") |
| 33 | assert ns.json_output is True |
| 34 | |
| 35 | def test_hub_override_flag(self) -> None: |
| 36 | ns = self._parse("--hub", "https://staging.musehub.ai") |
| 37 | assert ns.hub == "https://staging.musehub.ai" |
| 38 | |
| 39 | |
| 40 | class TestRunCollaboratorAccept: |
| 41 | def test_calls_accept_endpoint(self, capsys: pytest.CaptureFixture[str]) -> None: |
| 42 | args = argparse.Namespace(json_output=True, hub=None, repo=None) |
| 43 | with ( |
| 44 | patch.object(collaborators, "_get_hub_and_identity", return_value=("https://hub.example", MagicMock())), |
| 45 | patch.object(collaborators, "_resolve_repo_id", return_value="sha256:repo123"), |
| 46 | patch.object(collaborators, "_hub_api") as mock_api, |
| 47 | ): |
| 48 | mock_api.return_value = {"handle": "carol", "accepted": True} |
| 49 | collaborators.run_collaborator_accept(args) |
| 50 | |
| 51 | mock_api.assert_called_once() |
| 52 | call_args = mock_api.call_args |
| 53 | assert call_args[0][2] == "POST" |
| 54 | assert call_args[0][3] == "/api/repos/sha256:repo123/collaborators/accept" |
| 55 | |
| 56 | def test_json_output_includes_envelope_and_data(self, capsys: pytest.CaptureFixture[str]) -> None: |
| 57 | args = argparse.Namespace(json_output=True, hub=None, repo=None) |
| 58 | with ( |
| 59 | patch.object(collaborators, "_get_hub_and_identity", return_value=("https://hub.example", MagicMock())), |
| 60 | patch.object(collaborators, "_resolve_repo_id", return_value="sha256:repo123"), |
| 61 | patch.object(collaborators, "_hub_api", return_value={"handle": "carol", "accepted": True}), |
| 62 | ): |
| 63 | collaborators.run_collaborator_accept(args) |
| 64 | |
| 65 | out = capsys.readouterr().out |
| 66 | data = json.loads(out) |
| 67 | assert data["handle"] == "carol" |
| 68 | assert data["accepted"] is True |
| 69 | assert "muse_version" in data |
| 70 | |
| 71 | def test_text_mode_prints_confirmation_to_stderr(self, capsys: pytest.CaptureFixture[str]) -> None: |
| 72 | args = argparse.Namespace(json_output=False, hub=None, repo=None) |
| 73 | with ( |
| 74 | patch.object(collaborators, "_get_hub_and_identity", return_value=("https://hub.example", MagicMock())), |
| 75 | patch.object(collaborators, "_resolve_repo_id", return_value="sha256:repo123"), |
| 76 | patch.object(collaborators, "_hub_api", return_value={"handle": "carol", "accepted": True}), |
| 77 | ): |
| 78 | collaborators.run_collaborator_accept(args) |
| 79 | |
| 80 | cap = capsys.readouterr() |
| 81 | assert cap.out == "" |
| 82 | assert "accepted" in cap.err.lower() |
File History
1 commit
sha256:f0e66c9b996b798fb99b1fe8cc7ef318784f5285940729f796e0f789fab79ea5
feat(musehub#193): muse hub collaborator accept
Sonnet 5
patch
3 days ago