|
| 1 | +import pytest |
| 2 | + |
| 3 | +from .test_helpers import DummyContext |
| 4 | +import services.tools.manage_gameobject as manage_go_mod |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.asyncio |
| 8 | +async def test_manage_gameobject_is_static_true(monkeypatch): |
| 9 | + """Test that is_static=True is passed as isStatic in params.""" |
| 10 | + captured = {} |
| 11 | + |
| 12 | + async def fake_send(cmd, params, **kwargs): |
| 13 | + captured["params"] = params |
| 14 | + return {"success": True, "data": {}} |
| 15 | + |
| 16 | + monkeypatch.setattr( |
| 17 | + manage_go_mod, |
| 18 | + "async_send_command_with_retry", |
| 19 | + fake_send, |
| 20 | + ) |
| 21 | + |
| 22 | + resp = await manage_go_mod.manage_gameobject( |
| 23 | + ctx=DummyContext(), |
| 24 | + action="modify", |
| 25 | + target="Ground", |
| 26 | + is_static=True, |
| 27 | + ) |
| 28 | + |
| 29 | + assert resp.get("success") is True |
| 30 | + assert captured["params"]["action"] == "modify" |
| 31 | + assert captured["params"]["target"] == "Ground" |
| 32 | + assert captured["params"]["isStatic"] is True |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.asyncio |
| 36 | +async def test_manage_gameobject_is_static_false(monkeypatch): |
| 37 | + """Test that is_static=False is passed as isStatic in params.""" |
| 38 | + captured = {} |
| 39 | + |
| 40 | + async def fake_send(cmd, params, **kwargs): |
| 41 | + captured["params"] = params |
| 42 | + return {"success": True, "data": {}} |
| 43 | + |
| 44 | + monkeypatch.setattr( |
| 45 | + manage_go_mod, |
| 46 | + "async_send_command_with_retry", |
| 47 | + fake_send, |
| 48 | + ) |
| 49 | + |
| 50 | + resp = await manage_go_mod.manage_gameobject( |
| 51 | + ctx=DummyContext(), |
| 52 | + action="modify", |
| 53 | + target="Ground", |
| 54 | + is_static=False, |
| 55 | + ) |
| 56 | + |
| 57 | + assert resp.get("success") is True |
| 58 | + assert captured["params"]["isStatic"] is False |
| 59 | + |
| 60 | + |
| 61 | +@pytest.mark.asyncio |
| 62 | +async def test_manage_gameobject_is_static_string_coercion(monkeypatch): |
| 63 | + """Test that string 'true' is coerced to bool for is_static.""" |
| 64 | + captured = {} |
| 65 | + |
| 66 | + async def fake_send(cmd, params, **kwargs): |
| 67 | + captured["params"] = params |
| 68 | + return {"success": True, "data": {}} |
| 69 | + |
| 70 | + monkeypatch.setattr( |
| 71 | + manage_go_mod, |
| 72 | + "async_send_command_with_retry", |
| 73 | + fake_send, |
| 74 | + ) |
| 75 | + |
| 76 | + resp = await manage_go_mod.manage_gameobject( |
| 77 | + ctx=DummyContext(), |
| 78 | + action="modify", |
| 79 | + target="Ground", |
| 80 | + is_static="true", |
| 81 | + ) |
| 82 | + |
| 83 | + assert resp.get("success") is True |
| 84 | + assert captured["params"]["isStatic"] is True |
| 85 | + |
| 86 | + |
| 87 | +@pytest.mark.asyncio |
| 88 | +async def test_manage_gameobject_is_static_string_false_coercion(monkeypatch): |
| 89 | + """Test that string 'false' is coerced to bool for is_static.""" |
| 90 | + captured = {} |
| 91 | + |
| 92 | + async def fake_send(cmd, params, **kwargs): |
| 93 | + captured["params"] = params |
| 94 | + return {"success": True, "data": {}} |
| 95 | + |
| 96 | + monkeypatch.setattr( |
| 97 | + manage_go_mod, |
| 98 | + "async_send_command_with_retry", |
| 99 | + fake_send, |
| 100 | + ) |
| 101 | + |
| 102 | + resp = await manage_go_mod.manage_gameobject( |
| 103 | + ctx=DummyContext(), |
| 104 | + action="modify", |
| 105 | + target="Ground", |
| 106 | + is_static="false", |
| 107 | + ) |
| 108 | + |
| 109 | + assert resp.get("success") is True |
| 110 | + assert captured["params"]["isStatic"] is False |
| 111 | + |
| 112 | + |
| 113 | +@pytest.mark.asyncio |
| 114 | +async def test_manage_gameobject_is_static_omitted(monkeypatch): |
| 115 | + """Test that omitting is_static does not include isStatic in params.""" |
| 116 | + captured = {} |
| 117 | + |
| 118 | + async def fake_send(cmd, params, **kwargs): |
| 119 | + captured["params"] = params |
| 120 | + return {"success": True, "data": {}} |
| 121 | + |
| 122 | + monkeypatch.setattr( |
| 123 | + manage_go_mod, |
| 124 | + "async_send_command_with_retry", |
| 125 | + fake_send, |
| 126 | + ) |
| 127 | + |
| 128 | + resp = await manage_go_mod.manage_gameobject( |
| 129 | + ctx=DummyContext(), |
| 130 | + action="modify", |
| 131 | + target="Ground", |
| 132 | + ) |
| 133 | + |
| 134 | + assert resp.get("success") is True |
| 135 | + assert "isStatic" not in captured["params"] |
0 commit comments