diff --git a/mcstatus/pinger.py b/mcstatus/pinger.py index 9fcbf64..5fa6f73 100644 --- a/mcstatus/pinger.py +++ b/mcstatus/pinger.py @@ -103,6 +103,8 @@ class PingResponse: if type(raw["sample"]) is not list: raise ValueError("Invalid players object (expected 'sample' to be list, was %s)" % type(raw["max"])) self.sample = [PingResponse.Players.Player(p) for p in raw["sample"]] + else: + self.sample = None class Version: def __init__(self, raw): @@ -138,5 +140,7 @@ class PingResponse: if "favicon" in raw: self.favicon = raw["favicon"] + else: + self.favicon = None self.latency = None \ No newline at end of file diff --git a/mcstatus/tests/test_pinger.py b/mcstatus/tests/test_pinger.py index e42ad30..419fe9e 100644 --- a/mcstatus/tests/test_pinger.py +++ b/mcstatus/tests/test_pinger.py @@ -97,6 +97,11 @@ class TestPingResponse(TestCase): self.assertEqual(response.favicon, "data:image/png;base64,foo") + def test_favicon_missing(self): + response = PingResponse({"description":"A Minecraft Server","players":{"max":20,"online":0},"version":{"name":"1.8-pre1","protocol":44}}) + + self.assertIsNone(response.favicon) + class TestPingResponsePlayers(TestCase): def test_invalid(self): self.assertRaises(ValueError, PingResponse.Players, "foo") @@ -128,6 +133,10 @@ class TestPingResponsePlayers(TestCase): def test_sample_invalid(self): self.assertRaises(ValueError, PingResponse.Players, {"max":20,"online":1,"sample":"foo"}) + def test_sample_missing(self): + players = PingResponse.Players({"max":20,"online":1}) + self.assertIsNone(players.sample) + class TestPingResponsePlayersPlayer(TestCase): def test_invalid(self):