Skip to content

Commit 98bad5f

Browse files
author
Michael Barr
committed
Coded more tests for the user.py per Issue #4. Updated the settings.py by removing DEFAULT_FORMAT, which will not be used.
1 parent e4f04a0 commit 98bad5f

File tree

2 files changed

+118
-7
lines changed

2 files changed

+118
-7
lines changed

steamwebapi/settings.py

-7
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,3 @@
3737
# default.
3838
DEFAULT_LANGUAGE = 'en'
3939

40-
# The data format to return output in. If left blank, the default that the
41-
# Steam Web API returns is JSON.
42-
# Support Formats:
43-
# json (JavaScript Object Notation Format)
44-
# xml (Standard XML)
45-
# vdf (Valve Data Format)
46-
DEFAULT_DATA_FORMAT = ''

tests/test_user.py

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# =============================================================================
2+
# >> IMPORTS
3+
# =============================================================================
4+
# Python Imports
5+
from unittest import TestCase, main
6+
7+
# Third-Party Python Imports
8+
from requests import HTTPError
9+
10+
11+
# =============================================================================
12+
# >> GLOBALS
13+
# =============================================================================
14+
VANITY_URL = 'http://steamcommunity.com/id/XE_ManUp/'
15+
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'
26+
27+
def setUp(self):
28+
from steamwebapi.user import ISteamUser
29+
self.iSteamUser = ISteamUser()
30+
31+
def test_GetFriendList_no_api_key(self):
32+
"""Make sure that APIKeyRequiredError is raised without a Steam Web API
33+
key.
34+
35+
"""
36+
from steamwebapi.util.exceptions import APIKeyRequiredError
37+
with self.assertRaises(APIKeyRequiredError):
38+
# Modify the ISteamUser() instance with an empty Steam Web API Key
39+
self.iSteamUser.key = ''
40+
self.iSteamUser.GetFriendList(
41+
steamid=ISteamUserTest.PUBLIC_PROFILE
42+
)
43+
44+
def test_GetFriendList_valid(self):
45+
"""Test to make sure we get a response code of 200 OK from a public
46+
profile.
47+
48+
"""
49+
self.assertEqual(
50+
self.iSteamUser.GetFriendList(
51+
steamid=ISteamUserTest.PUBLIC_PROFILE
52+
).json.status_code,
53+
200,
54+
'Error retrieving friends list from a valid public profile.',
55+
)
56+
57+
def test_GetFriendList_private(self):
58+
"""Test to make sure we get a response code of 401 Unauthorized from a
59+
public profile.
60+
61+
"""
62+
self.assertEqual(
63+
self.iSteamUser.GetFriendList(
64+
steamid=ISteamUserTest.PRIVATE_PROFILE
65+
).json.status_code,
66+
401,
67+
'Error retrieving friends list from a valid public profile.',
68+
)
69+
70+
def test_GetFriendList_friends_only(self):
71+
"""Test to make sure we get a response code of 401 Unauthorized from a
72+
friends only profile.
73+
74+
"""
75+
self.assertEqual(
76+
self.iSteamUser.GetFriendList(
77+
steamid=ISteamUserTest.FRIENDSONLY_PROFILE
78+
).json.status_code,
79+
200,
80+
'Error retrieving friends list from a valid friends only profile.',
81+
)
82+
83+
def test_GetPlayerBans_no_api_key(self):
84+
"""Make sure that APIKeyRequiredError is raised without a Steam Web API
85+
key.
86+
87+
"""
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+
)
95+
96+
def test_GetPlayerBans_valid(self):
97+
"""Make sure that APIKeyRequiredError is raised without a Steam Web API
98+
key.
99+
100+
"""
101+
self.assertEqual(
102+
self.iSteamUser.GetPlayerBans(
103+
steamids=ISteamUserTest.PUBLIC_PROFILE,
104+
).json.status_code,
105+
200,
106+
'Error retrieving player bans.',
107+
)
108+
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):
115+
116+
117+
if __name__ == '__main__':
118+
main()

0 commit comments

Comments
 (0)