Example #1
0
 def get_info(self):
     i = messages.InfoResponse()
     i['response_type'] = 73
     i['protocol'] = 17
     i['server_name'] = u'A test server'
     i['map'] = u'ctf_2fort'
     i['folder'] = u'tf'
     i['game'] = u'Team Fortress'
     i['app_id'] = 440
     i['player_count'] = 31
     i['max_players'] = 31
     i['bot_count'] = 0
     i['server_type'] = util.ServerType(100)
     i['platform'] = util.Platform(108)
     i['password_protected'] = 0
     i['vac_enabled'] = 1
     i['version'] = u'3200676'
     return i
Example #2
0
 def test_to_integer(self, identifier):
     server_type = util.ServerType(identifier)
     assert int(server_type) == identifier
Example #3
0
 def test_to_bytestring(self, identifier, string):
     server_type = util.ServerType(identifier)
     assert bytes(server_type) == string
Example #4
0
 def test_to_unicode(self, identifier, string):
     server_type = util.ServerType(identifier)
     assert six.text_type(server_type) == string
Example #5
0
 def test_invalid_string_identifier(self):
     with pytest.raises(ValueError):
         util.ServerType("snowman")
Example #6
0
 def test_valid_string_identifier(self, identifier, expected):
     server_type = util.ServerType(identifier)
     assert server_type.value == expected
Example #7
0
 def test_invalid_character_identifier(self):
     with pytest.raises(ValueError):
         util.ServerType("a")
Example #8
0
 def test_invalid_numeric_identifier(self):
     with pytest.raises(ValueError):
         util.ServerType(42)
Example #9
0
 def test_valid_numeric_identifer(self, identifier):
     server_type = util.ServerType(identifier)
     assert server_type.value == identifier
Example #10
0
class TestServerType(object):
    @pytest.mark.parametrize("identifier", [100, 108, 112])
    def test_valid_numeric_identifer(self, identifier):
        server_type = util.ServerType(identifier)
        assert server_type.value == identifier

    def test_invalid_numeric_identifier(self):
        with pytest.raises(ValueError):
            util.ServerType(42)

    @pytest.mark.parametrize(("identifier", "expected"), [
        ("D", 68),
        ("d", 100),
        ("l", 108),
        ("p", 112),
    ])
    def test_valid_character_identifier(self, identifier, expected):
        server_type = util.ServerType(identifier)
        assert server_type.value == expected

    def test_invalid_character_identifier(self):
        with pytest.raises(ValueError):
            util.ServerType("a")

    @pytest.mark.parametrize(("identifier", "expected"), [
        ("dedicated", 100),
        ("Dedicated", 100),
        ("DEDICATED", 100),
        ("non-dedicated", 108),
        ("Non-Dedicated", 108),
        ("NON-DEDICATED", 108),
        ("sourcetv", 112),
        ("SourceTV", 112),
        ("SOURCETV", 112),
    ])
    def test_valid_string_identifier(self, identifier, expected):
        server_type = util.ServerType(identifier)
        assert server_type.value == expected

    def test_invalid_string_identifier(self):
        with pytest.raises(ValueError):
            util.ServerType("snowman")

    def test_empty_string_identifier(self):
        with pytest.raises(ValueError):
            util.Platform("")

    @pytest.mark.parametrize(("identifier", "string"), [
        (68, "Dedicated"),
        (100, "Dedicated"),
        (108, "Non-Dedicated"),
        (112, "SourceTV"),
    ])
    def test_to_unicode(self, identifier, string):
        server_type = util.ServerType(identifier)
        assert six.text_type(server_type) == string

    @pytest.mark.parametrize(("identifier", "string"), [
        (68, b"Dedicated"),
        (100, b"Dedicated"),
        (108, b"Non-Dedicated"),
        (112, b"SourceTV"),
    ])
    def test_to_bytestring(self, identifier, string):
        server_type = util.ServerType(identifier)
        assert bytes(server_type) == string

    @pytest.mark.parametrize("identifier", [68, 100, 108, 112])
    def test_to_integer(self, identifier):
        server_type = util.ServerType(identifier)
        assert int(server_type) == identifier

    @pytest.mark.parametrize(
        ("server_type", "other"),
        [
            (util.ServerType(68), util.ServerType(68)),
            (util.ServerType(68), util.ServerType(100)),  # Starbound
            (util.ServerType(100), util.ServerType(68)),  # Starbound
            (util.ServerType(100), util.ServerType(100)),
            (util.ServerType(108), util.ServerType(108)),
            (util.ServerType(112), util.ServerType(112)),
        ])
    def test_equality(self, server_type, other):
        assert server_type == other

    @pytest.mark.parametrize(
        ("server_type", "other"),
        [
            (util.ServerType(68), 68),
            (util.ServerType(100), 68),  # Starbound
            (util.ServerType(68), 100),  # Starbound
            (util.ServerType(100), 100),
            (util.ServerType(108), 108),
            (util.ServerType(112), 112),
        ])
    def test_equality_integer(self, server_type, other):
        assert server_type == other

    @pytest.mark.parametrize(
        ("server_type", "other"),
        [
            (util.ServerType(68), "D"),
            (util.ServerType(68), "D"),  # Starbound
            (util.ServerType(100), "d"),
            (util.ServerType(108), "l"),
            (util.ServerType(112), "p"),
        ])
    def test_equality_character(self, server_type, other):
        assert server_type == other

    @pytest.mark.parametrize(("server_type", "other"), [
        (util.ServerType(68), "Dedicated"),
        (util.ServerType(100), "Dedicated"),
        (util.ServerType(108), "Non-Dedicated"),
        (util.ServerType(112), "SourceTV"),
    ])
    def test_equality_string(self, server_type, other):
        assert server_type == other
Example #11
0
 def test_filter_type(self, _map_region, _query):
     msq = master_server.MasterServerQuerier()
     server_type = util.ServerType(108)
     list(msq.find(type=server_type))
     assert _query.called
     assert _query.call_args[0][1] == r"\type\{}".format(server_type.char)