-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathtest_webapi.py
More file actions
79 lines (67 loc) · 2.97 KB
/
test_webapi.py
File metadata and controls
79 lines (67 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import unittest
import mock
import vcr
from steam import webapi
from steam.webapi import WebAPI
from steam.enums import EType, EUniverse
# setup VCR
def scrub_req(r):
r.headers.pop('Cookie', None)
r.headers.pop('date', None)
return r
def scrub_resp(r):
r['headers'].pop('set-cookie', None)
r['headers'].pop('date', None)
r['headers'].pop('expires', None)
return r
test_api_key = 'test_api_key'
test_vcr = vcr.VCR(
record_mode='none', # change to 'new_episodes' when recording
serializer='yaml',
filter_query_parameters=['key'],
filter_post_data_parameters=['key'],
cassette_library_dir='vcr',
before_record_request=scrub_req,
before_record_response=scrub_resp,
)
class TCwebapi(unittest.TestCase):
@test_vcr.use_cassette('webapi.yaml', decode_compressed_response=True)
def setUp(self):
self.api = WebAPI(test_api_key)
self.api.session.headers['Accept-Encoding'] = 'identity'
def test_docs(self):
self.assertTrue(len(self.api.doc()) > 0)
@test_vcr.use_cassette('webapi.yaml', decode_compressed_response=True)
def test_simple_api_call(self):
resp = self.api.ISteamWebAPIUtil.GetServerInfo_v1()
self.assertTrue('servertime' in resp)
@test_vcr.use_cassette('webapi.yaml', decode_compressed_response=True)
def test_simple_api_call_vdf(self):
resp = self.api.ISteamWebAPIUtil.GetServerInfo(format='vdf')
self.assertTrue('servertime' in resp['response'])
@test_vcr.use_cassette('webapi.yaml', decode_compressed_response=True)
def test_resolve_vanity(self):
resp = self.api.ISteamUser.ResolveVanityURL(vanityurl='valve', url_type=2)
self.assertEqual(resp['response']['steamid'], '103582791429521412')
@test_vcr.use_cassette('webapi.yaml', decode_compressed_response=True)
def test_post_publishedfile(self):
resp = self.api.ISteamRemoteStorage.GetPublishedFileDetails(itemcount=5, publishedfileids=[1,1,1,1,1])
self.assertEqual(resp['response']['resultcount'], 5)
@test_vcr.use_cassette('webapi.yaml', decode_compressed_response=True)
def test_get(self):
resp = webapi.get('ISteamUser', 'ResolveVanityURL', 1,
session=self.api.session, params={
'key': test_api_key,
'vanityurl': 'valve',
'url_type': 2,
})
self.assertEqual(resp['response']['steamid'], '103582791429521412')
@test_vcr.use_cassette('webapi.yaml', decode_compressed_response=True)
def test_post(self):
resp = webapi.post('ISteamRemoteStorage', 'GetPublishedFileDetails', 1,
session=self.api.session, params={
'key': test_api_key,
'itemcount': 5,
'publishedfileids': [1,1,1,1,1],
})
self.assertEqual(resp['response']['resultcount'], 5)