Skip to content

Commit

Permalink
#42 use logger.warning for deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Jan 11, 2017
1 parent e7bf297 commit b7012b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ def test_is_valid():


def test_get_named_token_deprecated(monkeypatch):
logger = MagicMock()
response = MagicMock(status_code=401)
monkeypatch.setattr('zign.api.get_token', lambda x, y: 'mytok701')
monkeypatch.setattr('zign.api.logger', logger)
token = zign.api.get_named_token('myrealm', ['myscope'], 'myuser', 'mypass', 'http://example.org')
assert 'mytok701' == token['access_token']
logger.warning.assert_called_with('"get_named_token" is deprecated, please use "zign.api.get_token" instead')


def test_get_new_token_server_error(monkeypatch):
Expand Down
11 changes: 6 additions & 5 deletions zign/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click
from clickclick import error, info, UrlType
import logging
import os
import stups_cli.config
import time
Expand All @@ -18,6 +19,8 @@

TOKEN_MINIMUM_VALIDITY_SECONDS = 60*5 # 5 minutes

logger = logging.getLogger('zign.api')


class ServerError(Exception):
def __init__(self, message):
Expand Down Expand Up @@ -96,7 +99,7 @@ def load_config_ztoken(config_file: str):


def get_new_token(realm: str, scope: list, user, password, url=None, insecure=False):
'''"get_new_token" is deprecated, please use "zign.api.get_token" instead'''
logger.warning('"get_new_token" is deprecated, please use "zign.api.get_token" instead')

if not url:
config = get_config(OLD_CONFIG_NAME)
Expand Down Expand Up @@ -270,10 +273,8 @@ def get_token_implicit_flow(name=None, authorize_url=None, token_url=None, clien

def get_named_token(scope, realm, name, user, password, url=None,
insecure=False, refresh=False, use_keyring=True, prompt=False):
'''get named access token, return existing if still valid
"get_named_token" is deprecated, please use "zign.api.get_token" instead
'''
'''get named access token, return existing if still valid'''
logger.warning('"get_named_token" is deprecated, please use "zign.api.get_token" instead')

access_token = get_token(name, scope)
return {'access_token': access_token}
Expand Down

0 comments on commit b7012b8

Please sign in to comment.