diff options
Diffstat (limited to 'packages/meshbay-cli/tests/test_cli_actions.py')
| -rw-r--r-- | packages/meshbay-cli/tests/test_cli_actions.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/meshbay-cli/tests/test_cli_actions.py b/packages/meshbay-cli/tests/test_cli_actions.py index 240ac67..bcbe0c4 100644 --- a/packages/meshbay-cli/tests/test_cli_actions.py +++ b/packages/meshbay-cli/tests/test_cli_actions.py @@ -8,6 +8,8 @@ to the parser without a run below. import io import json +import os +import sys import pytest from fake_hub import PASSPHRASE, USERNAME, FakeHub @@ -568,6 +570,32 @@ def test_chat_reads_the_last_messages_and_posts(node, monkeypatch, capsys): assert main("chat", "-0", "Family") == 1 +def test_stream_serves_a_film_to_the_player_it_starts(node, tmp_path, monkeypatch, capsys): + from meshbay_cli.commands import stream + + async def open_group(account, group): + return node.session() + monkeypatch.setattr(stream, "open_group", open_group) + film = os.urandom(1024 * 1024 + 7) + node.add("share/films", "Night Drive.mkv", film)["type"] = "video" + node.add("share", "notes.txt", b"hello") + + assert main("stream", "Family/share/notes.txt") == 1 + assert "not a video or a sound file" in capsys.readouterr().err + if sys.platform == "win32": + return # a script is not a program there + played = tmp_path / "played" + player = tmp_path / "player" + player.write_text(f"#!{sys.executable}\nimport sys, urllib.request\n" + "opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))\n" + f"open({str(played)!r}, 'wb').write(opener.open(sys.argv[1]).read())\n") + player.chmod(0o755) + assert main("stream", "--player", str(player), "Family/share/films/Night Drive.mkv") == 0 + assert played.read_bytes() == film + out = capsys.readouterr() + assert out.out.startswith("http://127.0.0.1:") and "player was closed" in out.err + + def test_every_action_is_run_here(): """Runs last in this module: every action the parser knows was run above.""" assert RUN == set(cli.ACTIONS), f"never run: {set(cli.ACTIONS) - RUN}" |