Skip to content

Commit a7e6196

Browse files
authored
Merge pull request #9 from corywright/remove-access-base-urls-from-constructor
Remove base_url, access_token_url, and verify_ssl from constructor
2 parents 5359332 + c5e026e commit a7e6196

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ History
66
------------------
77

88
* Use a `requests.Session` object for all api calls
9+
* Remove `base_url`, `access_token_url`, and `verify_ssl` from Api constructor
910

1011
0.7.3 (2017-05-18)
1112
------------------

iland/api.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Api(object):
2121
_username = None
2222
_password = None
2323
_base_url = BASE_URL
24-
_access_token_url = ACCESS_URL
24+
_access_token_url_ = ACCESS_URL
2525
_refresh_token_url = REFRESH_URL
2626
_proxies = None
2727

@@ -31,35 +31,30 @@ class Api(object):
3131
_verify_ssl = True
3232
_session = None
3333

34-
def __init__(self, client_id, client_secret, username, password,
35-
base_url=None, access_token_url=None, verify_ssl=True):
34+
def __init__(self, client_id, client_secret, username, password):
3635
"""Instantiate a new iland.Api object.
3736
3837
:param client_id: the client identifier
3938
:param client_secret: the client secret
4039
:param username: the iland cloud username
4140
:param password: the iland cloud password
42-
:param base_url: [optional] base url to contact the iland cloud API
43-
:param access_token_url: [optional] access token url to contact the \
44-
iland cloud API
45-
:param verify_ssl: [optional] whether or not to verify endpoints SSL
4641
:return: Api Object
4742
"""
4843
self._client_id = client_id
4944
self._client_secret = client_secret
5045
self._username = username
5146
self._password = password
52-
if base_url is not None:
53-
self._base_url = base_url
54-
else:
55-
self._base_url = BASE_URL
47+
self._session = requests.Session()
48+
49+
@property
50+
def _access_token_url(self):
51+
return self._access_token_url_
52+
53+
@_access_token_url.setter
54+
def _access_token_url(self, access_token_url):
5655
if access_token_url is not None:
57-
self._access_token_url = access_token_url
58-
#: Refresh token URL. (`refresh` query param is here only for mock
59-
# testing reason)
56+
self._access_token_url_ = access_token_url
6057
self._refresh_token_url = access_token_url + '?refresh=1'
61-
self._verify_ssl = verify_ssl
62-
self._session = requests.Session()
6358

6459
def _get_access_token(self):
6560

tests/test_iland.py

100644100755
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
import iland
1212

13-
BASE_URL = 'http://mock.com/ecs'
14-
ACCESS_URL = iland.ACCESS_URL
13+
BASE_URL = 'http://example.com/ecs'
1514

1615
VALID_TOKEN_PAYLOAD = {'expires_in': 12,
1716
'access_token': 'AZERTYUIOP',
@@ -30,9 +29,9 @@ def setUp(self):
3029
self.api = iland.Api(client_id='fake',
3130
client_secret='fake',
3231
username='fake',
33-
password='fake',
34-
base_url=BASE_URL,
35-
access_token_url=ACCESS_URL)
32+
password='fake')
33+
self.api._base_url = BASE_URL
34+
self.api._access_token_url = iland.ACCESS_URL
3635

3736
def test_login_ok_200(self):
3837
with requests_mock.mock() as m:

tests/test_iland_int.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def setUp(self):
4747
self._api = iland.Api(client_id=CLIENT_ID,
4848
client_secret=CLIENT_SECRET,
4949
username=USERNAME,
50-
password=PASSWORD,
51-
base_url=iland.constant.BASE_URL)
50+
password=PASSWORD)
51+
self._api._base_url = iland.constant.BASE_URL
5252

5353
def tearDown(self):
5454
pass
@@ -120,8 +120,9 @@ def test_unauthorized_errors(self):
120120
wrongCredsApi = iland.Api(client_id=CLIENT_ID,
121121
client_secret=CLIENT_SECRET,
122122
username='PYTHON_SDK_TEST',
123-
password='XXXX',
124-
base_url=iland.constant.BASE_URL)
123+
password='XXXX')
124+
wrongCredsApi._base_url = iland.constant.BASE_URL
125+
125126
with self.assertRaises(UnauthorizedException):
126127
wrongCredsApi.login()
127128

0 commit comments

Comments
 (0)