|
7 | 7 | # Third-Party Python Imports
|
8 | 8 | from requests import HTTPError
|
9 | 9 |
|
| 10 | +# User Imports |
| 11 | +from steamwebapi.user import ISteamUser |
| 12 | + |
| 13 | +# Util Imports |
| 14 | +from steamwebapi.util.exceptions import APIKeyRequiredError |
10 | 15 |
|
11 | 16 | # =============================================================================
|
12 | 17 | # >> GLOBALS
|
13 | 18 | # =============================================================================
|
14 |
| -VANITY_URL = 'http://steamcommunity.com/id/XE_ManUp/' |
| 19 | +VANITY_URL = 'XE_ManUp' |
15 | 20 | 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' |
26 | 24 |
|
| 25 | +# ============================================================================= |
| 26 | +# >> ISteamUser Tests |
| 27 | +# ============================================================================= |
| 28 | +class ISteamUserNoAPIKeyTest(TestCase): |
27 | 29 | def setUp(self):
|
28 |
| - from steamwebapi.user import ISteamUser |
29 |
| - self.iSteamUser = ISteamUser() |
| 30 | + self.iSteamUser = ISteamUser(key='') |
30 | 31 |
|
31 | 32 | def test_GetFriendList_no_api_key(self):
|
32 | 33 | """Make sure that APIKeyRequiredError is raised without a Steam Web API
|
33 | 34 | key.
|
34 | 35 |
|
35 | 36 | """
|
36 |
| - from steamwebapi.util.exceptions import APIKeyRequiredError |
37 | 37 | with self.assertRaises(APIKeyRequiredError):
|
38 |
| - # Modify the ISteamUser() instance with an empty Steam Web API Key |
39 |
| - self.iSteamUser.key = '' |
40 | 38 | 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, |
42 | 80 | )
|
| 81 | + |
| 82 | + |
| 83 | +class ISteamUserTest(TestCase): |
| 84 | + def setUp(self): |
| 85 | + self.iSteamUser = ISteamUser() |
43 | 86 |
|
44 | 87 | def test_GetFriendList_valid(self):
|
45 | 88 | """Test to make sure we get a response code of 200 OK from a public
|
46 | 89 | profile.
|
47 | 90 |
|
48 | 91 | """
|
| 92 | + # Retrieve the status code |
| 93 | + status = self.iSteamUser.GetFriendList( |
| 94 | + steamid=PUBLIC_PROFILE |
| 95 | + ).json.status_code |
| 96 | + |
| 97 | + # Run the test |
49 | 98 | self.assertEqual(
|
50 |
| - self.iSteamUser.GetFriendList( |
51 |
| - steamid=ISteamUserTest.PUBLIC_PROFILE |
52 |
| - ).json.status_code, |
| 99 | + status, |
53 | 100 | 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), |
55 | 103 | )
|
56 | 104 |
|
57 | 105 | def test_GetFriendList_private(self):
|
58 | 106 | """Test to make sure we get a response code of 401 Unauthorized from a
|
59 | 107 | public profile.
|
60 | 108 |
|
61 | 109 | """
|
| 110 | + # Retrieve the status code |
| 111 | + status = self.iSteamUser.GetFriendList( |
| 112 | + steamid=PRIVATE_PROFILE |
| 113 | + ).json.status_code |
| 114 | + |
| 115 | + # Run the test |
62 | 116 | self.assertEqual(
|
63 |
| - self.iSteamUser.GetFriendList( |
64 |
| - steamid=ISteamUserTest.PRIVATE_PROFILE |
65 |
| - ).json.status_code, |
| 117 | + status, |
66 | 118 | 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), |
68 | 121 | )
|
69 | 122 |
|
70 | 123 | def test_GetFriendList_friends_only(self):
|
71 | 124 | """Test to make sure we get a response code of 401 Unauthorized from a
|
72 | 125 | friends only profile.
|
73 | 126 |
|
74 | 127 | """
|
| 128 | + # Retrieve the status code |
| 129 | + status = self.iSteamUser.GetFriendList( |
| 130 | + steamid=FRIENDSONLY_PROFILE |
| 131 | + ).json.status_code |
| 132 | + |
| 133 | + # Run the test |
75 | 134 | self.assertEqual(
|
76 |
| - self.iSteamUser.GetFriendList( |
77 |
| - steamid=ISteamUserTest.FRIENDSONLY_PROFILE |
78 |
| - ).json.status_code, |
| 135 | + status, |
79 | 136 | 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).', |
81 | 140 | )
|
82 | 141 |
|
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. |
86 | 145 |
|
87 | 146 | """
|
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 |
95 | 151 |
|
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. |
99 | 163 |
|
100 | 164 | """
|
| 165 | + # Retrieve the status code |
| 166 | + status = self.iSteamUser.GetPlayerBans( |
| 167 | + steamids=PUBLIC_PROFILE, |
| 168 | + ).json.status_code |
| 169 | + |
| 170 | + # Run the test |
101 | 171 | 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, |
105 | 263 | 200,
|
106 |
| - 'Error retrieving player bans.', |
| 264 | + 'Error retrieving player summary. Received Status ' + |
| 265 | + ' ({0}) instead of Status (200).'.format(status), |
107 | 266 | )
|
108 | 267 |
|
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 | + ) |
115 | 313 |
|
116 | 314 |
|
117 | 315 | if __name__ == '__main__':
|
|
0 commit comments