From b8fa5027d517ac444e87e8bf7c53ca4ba188eb6b Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Tue, 19 Oct 2021 17:40:50 +0200 Subject: [PATCH] Test binary messages --- multivisor/tests/test_multivisor.py | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/multivisor/tests/test_multivisor.py b/multivisor/tests/test_multivisor.py index 0e3621c..a66af6e 100644 --- a/multivisor/tests/test_multivisor.py +++ b/multivisor/tests/test_multivisor.py @@ -2,6 +2,7 @@ from tests.conftest import * from tests.functions import assert_fields_in_object +import contextlib @pytest.mark.usefixtures("supervisor_test001") @@ -36,6 +37,52 @@ def test_supervisor_info(multivisor_instance): assert info["identification"] == "supervisor" +@pytest.mark.usefixtures("supervisor_test001") +def test_supervisor_info_from_bytes(multivisor_instance): + supervisor = multivisor_instance.get_supervisor("test001") + + @contextlib.contextmanager + def patched_getAllProcessInfo(s): + try: + getAllProcessInfo = s.server.getAllProcessInfo + + def mockedAllProcessInfo(): + processesInfo = getAllProcessInfo() + for info in processesInfo: + info[b"name"] = info.pop("name").encode("ascii") + info[b"description"] = info.pop("description").encode("ascii") + return processesInfo + + s.server.getAllProcessInfo = mockedAllProcessInfo + yield + finally: + s.server.getAllProcessInfo = getAllProcessInfo + + # Mock getAllProcessInfo with binary data + with patched_getAllProcessInfo(supervisor): + info = supervisor.read_info() + assert_fields_in_object( + [ + "running", + "host", + "version", + "identification", + "name", + "url", + "supervisor_version", + "pid", + "processes", + "api_version", + ], + info, + ) + assert info["running"] + assert info["host"] == "localhost" + assert len(info["processes"]) == 10 + assert info["name"] == "test001" + assert info["identification"] == "supervisor" + + @pytest.mark.usefixtures("supervisor_test001") def test_processes_attr(multivisor_instance): multivisor_instance.refresh() # processes are empty before calling this