Skip to content

Commit

Permalink
Test binary messages
Browse files Browse the repository at this point in the history
  • Loading branch information
vallsv authored and tiagocoutinho committed Oct 21, 2021
1 parent f5f1a63 commit b8fa502
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions multivisor/tests/test_multivisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from tests.conftest import *
from tests.functions import assert_fields_in_object
import contextlib


@pytest.mark.usefixtures("supervisor_test001")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b8fa502

Please sign in to comment.