Skip to content

Commit 580ff15

Browse files
move from get to post for _get_client_credentials (#23)
1 parent 7b3e662 commit 580ff15

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def read(*parts):
2020
test_requirements = [
2121
'pytest>=5.0,<6.0',
2222
'pytest-flake8',
23-
'pytest-isort==1.0.0',
23+
'pytest-isort==1.3.0',
2424
'pytest-cov>=2.7,<3.0',
2525
'pytest-mock==1.10.4',
2626
]

tests/test_api.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
from requests.exceptions import RequestException
55

6-
from wowapi import WowApi, WowApiException
6+
from wowapi import WowApi, WowApiException, WowApiOauthException
77

88
from .fixtures import ResponseMock
99

@@ -124,15 +124,16 @@ def test_get_resource_no_access_token(self, session_get_mock, utc_mock):
124124
ResponseMock()(200, b'{"access_token": "111", "expires_in": 60}'),
125125
ResponseMock()(200, b'{"response": "ok"}'),
126126
]
127-
data = self.api.get_resource('foo', 'eu')
128-
129-
assert data == {'response': 'ok'}
130-
assert self.api._access_tokens == {
131-
'eu': {
132-
'token': '111',
133-
'expiration': now + timedelta(seconds=60)
127+
with pytest.raises(WowApiOauthException):
128+
data = self.api.get_resource('foo', 'eu')
129+
130+
assert data == {'response': 'ok'}
131+
assert self.api._access_tokens == {
132+
'eu': {
133+
'token': '111',
134+
'expiration': now + timedelta(seconds=60)
135+
}
134136
}
135-
}
136137

137138
def test_get_resource_no_access_expired(self, session_get_mock, utc_mock):
138139
now = datetime.utcnow()
@@ -149,15 +150,16 @@ def test_get_resource_no_access_expired(self, session_get_mock, utc_mock):
149150
ResponseMock()(200, b'{"access_token": "333", "expires_in": 60}'),
150151
ResponseMock()(200, b'{"response": "ok"}'),
151152
]
152-
data = self.api.get_resource('foo', 'eu')
153-
154-
assert data == {'response': 'ok'}
155-
assert self.api._access_tokens == {
156-
'eu': {
157-
'token': '333',
158-
'expiration': now + timedelta(seconds=60)
153+
with pytest.raises(WowApiOauthException):
154+
data = self.api.get_resource('foo', 'eu')
155+
156+
assert data == {'response': 'ok'}
157+
assert self.api._access_tokens == {
158+
'eu': {
159+
'token': '333',
160+
'expiration': now + timedelta(seconds=60)
161+
}
159162
}
160-
}
161163

162164
def test_format_base_url(self):
163165
assert self.api._format_base_url('test', 'us') == 'https://us.api.blizzard.com/test'

wowapi/api.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import requests
55
from requests.adapters import HTTPAdapter
6+
from requests.auth import HTTPBasicAuth
67
from requests.exceptions import RequestException
78
from requests.packages.urllib3.util.retry import Retry
89

@@ -57,9 +58,9 @@ def retry_conn_failures(self, total=5, backoff_factor=1,
5758
self._session.mount('https://', HTTPAdapter(max_retries=retries))
5859

5960
def _get_client_credentials(self, region):
60-
path = '/oauth/token?grant_type=client_credentials&client_id={0}&client_secret={1}'.format(
61-
self._client_id, self._client_secret
62-
)
61+
path = '/oauth/token'
62+
data = {'grant_type': 'client_credentials'}
63+
auth = HTTPBasicAuth(self._client_id, self._client_secret)
6364

6465
url = 'https://{0}.battle.net{1}'.format(region, path)
6566
if region == 'cn':
@@ -69,7 +70,7 @@ def _get_client_credentials(self, region):
6970

7071
now = self._utcnow()
7172
try:
72-
response = self._session.get(url)
73+
response = self._session.post(url, data=data, auth=auth)
7374
except RequestException as exc:
7475
logger.exception(str(exc))
7576
raise WowApiOauthException(str(exc))

0 commit comments

Comments
 (0)