Skip to content

move from get to post #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def read(*parts):
test_requirements = [
'pytest>=5.0,<6.0',
'pytest-flake8',
'pytest-isort==1.0.0',
'pytest-isort==1.3.0',
'pytest-cov>=2.7,<3.0',
'pytest-mock==1.10.4',
]
Expand Down
36 changes: 19 additions & 17 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from requests.exceptions import RequestException

from wowapi import WowApi, WowApiException
from wowapi import WowApi, WowApiException, WowApiOauthException

from .fixtures import ResponseMock

Expand Down Expand Up @@ -124,15 +124,16 @@ def test_get_resource_no_access_token(self, session_get_mock, utc_mock):
ResponseMock()(200, b'{"access_token": "111", "expires_in": 60}'),
ResponseMock()(200, b'{"response": "ok"}'),
]
data = self.api.get_resource('foo', 'eu')

assert data == {'response': 'ok'}
assert self.api._access_tokens == {
'eu': {
'token': '111',
'expiration': now + timedelta(seconds=60)
with pytest.raises(WowApiOauthException):
data = self.api.get_resource('foo', 'eu')

assert data == {'response': 'ok'}
assert self.api._access_tokens == {
'eu': {
'token': '111',
'expiration': now + timedelta(seconds=60)
}
}
}

def test_get_resource_no_access_expired(self, session_get_mock, utc_mock):
now = datetime.utcnow()
Expand All @@ -149,15 +150,16 @@ def test_get_resource_no_access_expired(self, session_get_mock, utc_mock):
ResponseMock()(200, b'{"access_token": "333", "expires_in": 60}'),
ResponseMock()(200, b'{"response": "ok"}'),
]
data = self.api.get_resource('foo', 'eu')

assert data == {'response': 'ok'}
assert self.api._access_tokens == {
'eu': {
'token': '333',
'expiration': now + timedelta(seconds=60)
with pytest.raises(WowApiOauthException):
data = self.api.get_resource('foo', 'eu')

assert data == {'response': 'ok'}
assert self.api._access_tokens == {
'eu': {
'token': '333',
'expiration': now + timedelta(seconds=60)
}
}
}

def test_format_base_url(self):
assert self.api._format_base_url('test', 'us') == 'https://us.api.blizzard.com/test'
Expand Down
9 changes: 5 additions & 4 deletions wowapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import requests
from requests.adapters import HTTPAdapter
from requests.auth import HTTPBasicAuth
from requests.exceptions import RequestException
from requests.packages.urllib3.util.retry import Retry

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

def _get_client_credentials(self, region):
path = '/oauth/token?grant_type=client_credentials&client_id={0}&client_secret={1}'.format(
self._client_id, self._client_secret
)
path = '/oauth/token'
data = {'grant_type': 'client_credentials'}
auth = HTTPBasicAuth(self._client_id, self._client_secret)

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

now = self._utcnow()
try:
response = self._session.get(url)
response = self._session.post(url, data=data, auth=auth)
except RequestException as exc:
logger.exception(str(exc))
raise WowApiOauthException(str(exc))
Expand Down