Skip to content

Commit 8acbf9e

Browse files
author
Michael Barr
committedAug 6, 2013
Completed ISteamUser() tests (Issue #4).
1 parent 8fa823c commit 8acbf9e

File tree

1 file changed

+250
-52
lines changed

1 file changed

+250
-52
lines changed
 

‎tests/test_user.py

+250-52
Original file line numberDiff line numberDiff line change
@@ -7,111 +7,309 @@
77
# Third-Party Python Imports
88
from requests import HTTPError
99

10+
# User Imports
11+
from steamwebapi.user import ISteamUser
12+
13+
# Util Imports
14+
from steamwebapi.util.exceptions import APIKeyRequiredError
1015

1116
# =============================================================================
1217
# >> GLOBALS
1318
# =============================================================================
14-
VANITY_URL = 'http://steamcommunity.com/id/XE_ManUp/'
19+
VANITY_URL = 'XE_ManUp'
1520
PUBLIC_PROFILE = '76561197970309043'
16-
PRIVATE_PROFILE = '76561198061223360'
17-
FRIENDSONLY_PROFILE = '76561198013559637'
18-
VAC_BANNED = '76561197970309043'
19-
COMMUNITY_BANNED = ''
20-
ECONOMY_BANNED = ''
21-
22-
class ISteamUserTest(TestCase):
23-
PUBLIC_PROFILE = '76561197970309043'
24-
PRIVATE_PROFILE = '76561198069962646'
25-
FRIENDSONLY_PROFILE = '76561198061223360'
21+
PUBLIC_PROFILE_INT = int(PUBLIC_PROFILE)
22+
PRIVATE_PROFILE = '76561198069962646'
23+
FRIENDSONLY_PROFILE = '76561198061223360'
2624

25+
# =============================================================================
26+
# >> ISteamUser Tests
27+
# =============================================================================
28+
class ISteamUserNoAPIKeyTest(TestCase):
2729
def setUp(self):
28-
from steamwebapi.user import ISteamUser
29-
self.iSteamUser = ISteamUser()
30+
self.iSteamUser = ISteamUser(key='')
3031

3132
def test_GetFriendList_no_api_key(self):
3233
"""Make sure that APIKeyRequiredError is raised without a Steam Web API
3334
key.
3435
3536
"""
36-
from steamwebapi.util.exceptions import APIKeyRequiredError
3737
with self.assertRaises(APIKeyRequiredError):
38-
# Modify the ISteamUser() instance with an empty Steam Web API Key
39-
self.iSteamUser.key = ''
4038
self.iSteamUser.GetFriendList(
41-
steamid=ISteamUserTest.PUBLIC_PROFILE
39+
steamid=PUBLIC_PROFILE
40+
)
41+
42+
def test_GetPlayerBans_no_api_key(self):
43+
"""Make sure that APIKeyRequiredError is raised without a Steam Web API
44+
key.
45+
46+
"""
47+
with self.assertRaises(APIKeyRequiredError):
48+
self.iSteamUser.GetPlayerBans(
49+
steamids=[PUBLIC_PROFILE]
50+
)
51+
52+
def test_GetPlayerSummaries_no_api_key(self):
53+
"""Make sure that APIKeyRequiredError is raised without a Steam Web API
54+
key.
55+
56+
"""
57+
with self.assertRaises(APIKeyRequiredError):
58+
self.iSteamUser.GetPlayerSummaries(
59+
steamids=[PUBLIC_PROFILE]
60+
)
61+
62+
def test_GetUserGroupList_no_api_key(self):
63+
"""Make sure that APIKeyRequiredError is raised without a Steam Web API
64+
key.
65+
66+
"""
67+
with self.assertRaises(APIKeyRequiredError):
68+
self.iSteamUser.GetUserGroupList(
69+
steamid=PUBLIC_PROFILE
70+
)
71+
72+
def test_ResolveVanityURL_no_api_key(self):
73+
"""Make sure that APIKeyRequiredError is raised without a Steam Web API
74+
key.
75+
76+
"""
77+
with self.assertRaises(APIKeyRequiredError):
78+
self.iSteamUser.ResolveVanityURL(
79+
vanityURL=VANITY_URL,
4280
)
81+
82+
83+
class ISteamUserTest(TestCase):
84+
def setUp(self):
85+
self.iSteamUser = ISteamUser()
4386

4487
def test_GetFriendList_valid(self):
4588
"""Test to make sure we get a response code of 200 OK from a public
4689
profile.
4790
4891
"""
92+
# Retrieve the status code
93+
status = self.iSteamUser.GetFriendList(
94+
steamid=PUBLIC_PROFILE
95+
).json.status_code
96+
97+
# Run the test
4998
self.assertEqual(
50-
self.iSteamUser.GetFriendList(
51-
steamid=ISteamUserTest.PUBLIC_PROFILE
52-
).json.status_code,
99+
status,
53100
200,
54-
'Error retrieving friends list from a valid public profile.',
101+
'Error retrieving friends list from a valid public profile. ' +
102+
'Received Status ({0}) instead of Status (401).'.format(status),
55103
)
56104

57105
def test_GetFriendList_private(self):
58106
"""Test to make sure we get a response code of 401 Unauthorized from a
59107
public profile.
60108
61109
"""
110+
# Retrieve the status code
111+
status = self.iSteamUser.GetFriendList(
112+
steamid=PRIVATE_PROFILE
113+
).json.status_code
114+
115+
# Run the test
62116
self.assertEqual(
63-
self.iSteamUser.GetFriendList(
64-
steamid=ISteamUserTest.PRIVATE_PROFILE
65-
).json.status_code,
117+
status,
66118
401,
67-
'Error retrieving friends list from a valid public profile.',
119+
'Error retrieving friends list from a valid private profile. ' +
120+
'Received Status ({0}) instead of Status (401).'.format(status),
68121
)
69122

70123
def test_GetFriendList_friends_only(self):
71124
"""Test to make sure we get a response code of 401 Unauthorized from a
72125
friends only profile.
73126
74127
"""
128+
# Retrieve the status code
129+
status = self.iSteamUser.GetFriendList(
130+
steamid=FRIENDSONLY_PROFILE
131+
).json.status_code
132+
133+
# Run the test
75134
self.assertEqual(
76-
self.iSteamUser.GetFriendList(
77-
steamid=ISteamUserTest.FRIENDSONLY_PROFILE
78-
).json.status_code,
135+
status,
79136
200,
80-
'Error retrieving friends list from a valid friends only profile.',
137+
'Error retrieving friends list from a valid friends only ' +
138+
'profile. Received Status ({0}) instead of '.format(status) +
139+
'Status (200).',
81140
)
82141

83-
def test_GetPlayerBans_no_api_key(self):
84-
"""Make sure that APIKeyRequiredError is raised without a Steam Web API
85-
key.
142+
def test_GetPlayerBans_list_valid(self):
143+
"""Test to make sure we get a response code of 200 OK from a public
144+
profile.
86145
87146
"""
88-
from steamwebapi.util.exceptions import APIKeyRequiredError
89-
with self.assertRaises(APIKeyRequiredError):
90-
# Modify the ISteamUser() instance with an empty Steam Web API Key
91-
self.iSteamUser.key = ''
92-
self.iSteamUser.GetPlayerBans(
93-
steamids=ISteamUserTest.PUBLIC_PROFILE
94-
)
147+
# Retrieve the status code
148+
status = self.iSteamUser.GetPlayerBans(
149+
steamids=[PUBLIC_PROFILE],
150+
).json.status_code
95151

96-
def test_GetPlayerBans_valid(self):
97-
"""Make sure that APIKeyRequiredError is raised without a Steam Web API
98-
key.
152+
# Run the test
153+
self.assertEqual(
154+
status,
155+
200,
156+
'Error retrieving player bans. Received Status ' +
157+
' ({0}) instead of Status (200).'.format(status),
158+
)
159+
160+
def test_GetPlayerBans_str_valid(self):
161+
"""Test to make sure we get a response code of 200 OK from a public
162+
profile.
99163
100164
"""
165+
# Retrieve the status code
166+
status = self.iSteamUser.GetPlayerBans(
167+
steamids=PUBLIC_PROFILE,
168+
).json.status_code
169+
170+
# Run the test
101171
self.assertEqual(
102-
self.iSteamUser.GetPlayerBans(
103-
steamids=ISteamUserTest.PUBLIC_PROFILE,
104-
).json.status_code,
172+
status,
173+
200,
174+
'Error retrieving player bans. Received Status ' +
175+
' ({0}) instead of Status (200).'.format(status),
176+
)
177+
178+
def test_GetPlayerBans_int_valid(self):
179+
"""Test to make sure we get a response code of 200 OK from a public
180+
profile.
181+
182+
"""
183+
# Retrieve the status code
184+
status = self.iSteamUser.GetPlayerBans(
185+
steamids=PUBLIC_PROFILE,
186+
).json.status_code
187+
188+
# Run the test
189+
self.assertEqual(
190+
status,
191+
200,
192+
'Error retrieving player bans. Received Status ' +
193+
' ({0}) instead of Status (200).'.format(status),
194+
)
195+
196+
def test_GetPlayerBans_multiple_steamids_valid(self):
197+
"""Test to make sure we get a response code of 200 OK from multiple
198+
public profiles.
199+
200+
"""
201+
# Retrieve the status code
202+
status = self.iSteamUser.GetPlayerBans(
203+
steamids=PUBLIC_PROFILE,
204+
).json.status_code
205+
206+
# Run the test
207+
self.assertEqual(
208+
status,
209+
200,
210+
'Error retrieving player bans. Received Status ' +
211+
' ({0}) instead of Status (200).'.format(status),
212+
)
213+
214+
def test_GetPlayerSummaries_list_valid(self):
215+
"""Test to make sure we get a response code of 200 OK from a public
216+
profile.
217+
218+
"""
219+
# Retrieve the status code
220+
status = self.iSteamUser.GetPlayerSummaries(
221+
steamids=[PUBLIC_PROFILE],
222+
).json.status_code
223+
224+
# Run the test
225+
self.assertEqual(
226+
status,
227+
200,
228+
'Error retrieving player summary. Received Status ' +
229+
' ({0}) instead of Status (200).'.format(status),
230+
)
231+
232+
def test_GetPlayerSummaries_str_valid(self):
233+
"""Test to make sure we get a response code of 200 OK from a public
234+
profile.
235+
236+
"""
237+
# Retrieve the status code
238+
status = self.iSteamUser.GetPlayerSummaries(
239+
steamids=PUBLIC_PROFILE,
240+
).json.status_code
241+
242+
# Run the test
243+
self.assertEqual(
244+
status,
245+
200,
246+
'Error retrieving player summary. Received Status ' +
247+
' ({0}) instead of Status (200).'.format(status),
248+
)
249+
250+
def test_GetPlayerSummaries_int_valid(self):
251+
"""Test to make sure we get a response code of 200 OK from a public
252+
profile.
253+
254+
"""
255+
# Retrieve the status code
256+
status = self.iSteamUser.GetPlayerSummaries(
257+
steamids=PUBLIC_PROFILE_INT,
258+
).json.status_code
259+
260+
# Run the test
261+
self.assertEqual(
262+
status,
105263
200,
106-
'Error retrieving player bans.',
264+
'Error retrieving player summary. Received Status ' +
265+
' ({0}) instead of Status (200).'.format(status),
107266
)
108267

109-
#def test_GetPlayerSummaries_no_api_key(self):
110-
#def test_GetPlayerSummaries_valid(self):
111-
#def test_GetUserGroupList_no_api_key(self):
112-
#def test_GetUserGroupList_valid(self):
113-
#def test_ResolveVanityURL_no_api_key(self):
114-
#def test_ResolveVanityURL_valid(self):
268+
def test_GetPlayerSummaries_multiple_steamids_valid(self):
269+
"""Test to make sure we get a response code of 200 OK from multiple
270+
public profiles.
271+
272+
"""
273+
# Retrieve the status code
274+
status = self.iSteamUser.GetPlayerSummaries(
275+
steamids=[PUBLIC_PROFILE, PUBLIC_PROFILE],
276+
).json.status_code
277+
278+
# Run the test
279+
self.assertEqual(
280+
status,
281+
200,
282+
'Error retrieving player summary. Received Status ' +
283+
' ({0}) instead of Status (200).'.format(status),
284+
)
285+
286+
def test_GetUserGroupList_valid(self):
287+
# Retrieve the status code
288+
status = self.iSteamUser.GetUserGroupList(
289+
steamid=PUBLIC_PROFILE,
290+
).json.status_code
291+
292+
# Run the test
293+
self.assertEqual(
294+
status,
295+
200,
296+
'Error retrieving user group list. Received Status ' +
297+
' ({0}) instead of Status (200).'.format(status),
298+
)
299+
300+
def test_ResolveVanityURL_valid(self):
301+
# Retrieve the status code
302+
status = self.iSteamUser.ResolveVanityURL(
303+
vanityURL=VANITY_URL,
304+
).json.status_code
305+
306+
# Run the test
307+
self.assertEqual(
308+
status,
309+
200,
310+
'Error retrieving vanity URL. Received Status ' +
311+
'({0}) instead of Status (200)'.format(status),
312+
)
115313

116314

117315
if __name__ == '__main__':

0 commit comments

Comments
 (0)
Please sign in to comment.