Browse Source

SteamID: invite_code_to_tuple() to SteamID.from_invite_code()

pull/321/head
Rossen Georgiev 4 years ago
committed by Rossen
parent
commit
f448646ca1
  1. 8
      steam/steamid.py
  2. 42
      tests/test_steamid.py

8
steam/steamid.py

@ -458,7 +458,7 @@ def steam3_to_tuple(value):
return (steam32, etype, universe, instance) return (steam32, etype, universe, instance)
def invite_code_to_tuple(code, universe=EUniverse.Public): def from_invite_code(code, universe=EUniverse.Public):
""" """
Invites urls can be generated at https://steamcommunity.com/my/friends/add Invites urls can be generated at https://steamcommunity.com/my/friends/add
@ -486,7 +486,9 @@ def invite_code_to_tuple(code, universe=EUniverse.Public):
accountid = int(re.sub("["+_icode_custom+"]", repl_mapper, code), 16) accountid = int(re.sub("["+_icode_custom+"]", repl_mapper, code), 16)
if 0 < accountid < 2**32: if 0 < accountid < 2**32:
return (accountid, EType(1), EUniverse(universe), 1) return SteamID(accountid, EType.Individual, EUniverse(universe), 1)
SteamID.from_invite_code = staticmethod(from_invite_code)
def from_csgo_friend_code(code, universe=EUniverse.Public): def from_csgo_friend_code(code, universe=EUniverse.Public):
""" """
@ -520,7 +522,7 @@ def from_csgo_friend_code(code, universe=EUniverse.Public):
result = result >> 4 result = result >> 4
accountid = (accountid << 4) | id_nib accountid = (accountid << 4) | id_nib
return SteamID(accountid, EType.Individual, EUniverse(universe)) return SteamID(accountid, EType.Individual, EUniverse(universe), 1)
SteamID.from_csgo_friend_code = staticmethod(from_csgo_friend_code) SteamID.from_csgo_friend_code = staticmethod(from_csgo_friend_code)

42
tests/test_steamid.py

@ -290,10 +290,12 @@ class SteamID_properties(unittest.TestCase):
def test_as_invite_code(self): def test_as_invite_code(self):
self.assertEqual(SteamID(0 , EType.Individual, EUniverse.Public, instance=1).as_invite_code, None) self.assertEqual(SteamID(0 , EType.Individual, EUniverse.Public, instance=1).as_invite_code, None)
self.assertEqual(SteamID(1 , EType.Invalid , EUniverse.Public, instance=1).as_invite_code, None)
self.assertEqual(SteamID(1 , EType.Clan , EUniverse.Public, instance=1).as_invite_code, None)
self.assertEqual(SteamID(1 , EType.Individual, EUniverse.Beta , instance=1).as_invite_code, 'c')
self.assertEqual(SteamID(1 , EType.Individual, EUniverse.Public, instance=1).as_invite_code, 'c')
self.assertEqual(SteamID(123456 , EType.Individual, EUniverse.Public, instance=1).as_invite_code, 'cv-dgb') self.assertEqual(SteamID(123456 , EType.Individual, EUniverse.Public, instance=1).as_invite_code, 'cv-dgb')
self.assertEqual(SteamID(123456, EType.Individual, EUniverse.Beta , instance=1).as_invite_code, 'cv-dgb') self.assertEqual(SteamID(4294967295, EType.Individual, EUniverse.Public, instance=1).as_invite_code, 'wwww-wwww')
self.assertEqual(SteamID(123456, EType.Invalid , EUniverse.Public, instance=1).as_invite_code, None)
self.assertEqual(SteamID(123456, EType.Clan , EUniverse.Public, instance=1).as_invite_code, None)
def test_as_csgo_friend_code(self): def test_as_csgo_friend_code(self):
self.assertEqual(SteamID(0 , EType.Individual, EUniverse.Public, instance=1).as_csgo_friend_code, None) self.assertEqual(SteamID(0 , EType.Individual, EUniverse.Public, instance=1).as_csgo_friend_code, None)
@ -444,20 +446,26 @@ class steamid_functions(unittest.TestCase):
(1234, EType.Chat, EUniverse.Public, EInstanceFlag.Clan) (1234, EType.Chat, EUniverse.Public, EInstanceFlag.Clan)
) )
def test_arg_invite_code(self): def test_from_invite_code(self):
self.assertIsNone(steamid.invite_code_to_tuple('invalid_format')) self.assertIsNone(steamid.from_invite_code('invalid_format'))
self.assertIsNone(steamid.invite_code_to_tuple('https://steamcommunity.com/p/cv-dgb')) self.assertIsNone(steamid.from_invite_code('https://steamcommunity.com/p/cv-dgb'))
self.assertIsNone(steamid.invite_code_to_tuple('b')) self.assertIsNone(steamid.from_invite_code('b'))
self.assertIsNone(steamid.invite_code_to_tuple('aaaaaaaaaaaaaaaaaaaaaaaaa')) self.assertIsNone(steamid.from_invite_code('aaaaaaaaaaaaaaaaaaaaaaaaa'))
self.assertEqual(steamid.invite_code_to_tuple('cv-dgb'), self.assertEqual(steamid.from_invite_code('c', EUniverse.Beta),
(123456, EType.Individual, EUniverse.Public, 1)) SteamID(1, EType.Individual, EUniverse.Beta, 1))
self.assertEqual(steamid.invite_code_to_tuple('http://s.team/p/cv-dgb'), self.assertEqual(steamid.from_invite_code('c'),
(123456, EType.Individual, EUniverse.Public, 1)) SteamID(1, EType.Individual, EUniverse.Public, 1))
self.assertEqual(steamid.invite_code_to_tuple('https://s.team/p/cv-dgb'), self.assertEqual(steamid.from_invite_code('http://s.team/p/c', EUniverse.Beta),
(123456, EType.Individual, EUniverse.Public, 1)) SteamID(1, EType.Individual, EUniverse.Beta, 1))
self.assertEqual(steamid.invite_code_to_tuple('https://s.team/p/cv-dgb/ABCDE12354'), self.assertEqual(steamid.from_invite_code('http://s.team/p/c'),
(123456, EType.Individual, EUniverse.Public, 1)) SteamID(1, EType.Individual, EUniverse.Public, 1))
self.assertEqual(steamid.from_invite_code('https://s.team/p/cv-dgb'),
SteamID(123456, EType.Individual, EUniverse.Public, 1))
self.assertEqual(steamid.from_invite_code('https://s.team/p/cv-dgb/ABCDE12354'),
SteamID(123456, EType.Individual, EUniverse.Public, 1))
self.assertEqual(steamid.from_invite_code('http://s.team/p/wwww-wwww'),
SteamID(4294967295, EType.Individual, EUniverse.Public, 1))
def test_from_csgo_friend_code(self): def test_from_csgo_friend_code(self):
self.assertIsNone(steamid.from_csgo_friend_code('')) self.assertIsNone(steamid.from_csgo_friend_code(''))

Loading…
Cancel
Save