Skip to content

Commit

Permalink
Add enforces_secure_chat to JavaStatusResponse (#675)
Browse files Browse the repository at this point in the history
* Added enforces_secure_chat

* Add tests

---------

Co-authored-by: Perchun Pak <[email protected]>
  • Loading branch information
Nixuge and PerchunPak authored Nov 21, 2023
1 parent c8fcbbf commit 1a2badd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions mcstatus/status_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class JavaStatusResponse(BaseStatusResponse):
"""
players: JavaStatusPlayers
version: JavaStatusVersion
enforces_secure_chat: bool
icon: str | None
"""The icon of the server. In `Base64 <https://en.wikipedia.org/wiki/Base64>`_ encoded PNG image format.
Expand All @@ -132,6 +133,7 @@ def build(cls, raw: RawJavaResponse, latency: float = 0) -> Self:
players=JavaStatusPlayers.build(raw["players"]),
version=JavaStatusVersion.build(raw["version"]),
motd=Motd.parse(raw["description"], bedrock=False),
enforces_secure_chat=raw.get("enforcesSecureChat", False),
icon=raw.get("favicon"),
latency=latency,
)
Expand Down
16 changes: 11 additions & 5 deletions tests/status_response/test_java.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pytest import fixture
import pytest

from mcstatus.motd import Motd
from mcstatus.status_response import JavaStatusPlayer, JavaStatusPlayers, JavaStatusResponse, JavaStatusVersion
Expand Down Expand Up @@ -29,10 +29,16 @@ class TestJavaStatusResponse(BaseStatusResponseTest):
"favicon": "data:image/png;base64,foo",
}

@fixture(scope="class")
@pytest.fixture(scope="class")
def build(self):
return JavaStatusResponse.build(self.RAW) # type: ignore # dict[str, Unknown] cannot be assigned to TypedDict

@pytest.mark.parametrize("value", (True, False, object()))
def test_enforces_secure_chat(self, value):
raw = self.RAW.copy()
raw["enforcesSecureChat"] = value
assert JavaStatusResponse.build(raw, 0).enforces_secure_chat is value # type: ignore # dict[str, Unknown] cannot be assigned to TypedDict


@BaseStatusResponseTest.construct
class TestJavaStatusPlayers(BaseStatusResponseTest):
Expand All @@ -58,7 +64,7 @@ class TestJavaStatusPlayers(BaseStatusResponseTest):
],
}

@fixture(scope="class")
@pytest.fixture(scope="class")
def build(self):
return JavaStatusPlayers.build(
{
Expand All @@ -80,7 +86,7 @@ def test_empty_sample_turns_into_empty_list(self):
class TestJavaStatusPlayer(BaseStatusResponseTest):
EXPECTED_VALUES = [("name", "foo"), ("id", "0b3717c4-f45d-47c8-b8e2-3d9ff6f93a89")]

@fixture(scope="class")
@pytest.fixture(scope="class")
def build(self):
return JavaStatusPlayer.build({"name": "foo", "id": "0b3717c4-f45d-47c8-b8e2-3d9ff6f93a89"})

Expand All @@ -96,6 +102,6 @@ def test_id_field_the_same_as_uuid(self):
class TestJavaStatusVersion(BaseStatusResponseTest):
EXPECTED_VALUES = [("name", "1.8-pre1"), ("protocol", 44)]

@fixture(scope="class")
@pytest.fixture(scope="class")
def build(self):
return JavaStatusVersion.build({"name": "1.8-pre1", "protocol": 44})

0 comments on commit 1a2badd

Please sign in to comment.