Skip to content

Commit

Permalink
Rename idonethis token, adjust error reporting
Browse files Browse the repository at this point in the history
API token renamed from 'apitoken' to 'token' to make it consistent with
other plugins. Error reporting slightly adjusted.
  • Loading branch information
psss committed Oct 7, 2015
1 parent 75cae55 commit d6a8a45
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
23 changes: 11 additions & 12 deletions did/plugins/idonethis.py
Expand Up @@ -6,23 +6,20 @@
[idonethis]
type = idonethis
apitoken = ...
token = ...
apitoken
token
https://idonethis.com/api/token/
"""

# Possible API methods to add:
# http://developers.trello.com/advanced-reference/member

from __future__ import unicode_literals, absolute_import

try:
import requests
except ImportError:
raise NotImplementedError("urllib2 version is not yet implemented!")

from did.base import Config, ConfigError
import did.base
from did.utils import log
from did.stats import Stats, StatsGroup

Expand Down Expand Up @@ -57,7 +54,8 @@ def fetch(self, page_size=100):

if not payload.get('ok'):
detail = payload.get('detail') or 'UNKNOWN ERROR'
raise RuntimeError(detail)
raise did.base.ReportError(
"Failed to fetch idonethis items ({0})".format(detail))

k = payload['count']
log.info('Found {0} dones'.format(k))
Expand Down Expand Up @@ -85,11 +83,12 @@ def __init__(self, option, name=None, parent=None, user=None):
super(IdonethisStatsGroup, self).__init__(
option=option, name=name, parent=parent, user=user)

self.config = dict(Config().section(option))
self.config = dict(did.base.Config().section(option))

self.apitoken = self.config.get('apitoken')
if not self.apitoken:
raise ConfigError('apitoken must be defined!')
self.token = self.config.get('token')
if not self.token:
raise did.base.ConfigError(
'No token defined in the [{0}] section'.format(option))

self.stats = [
IdonethisStats(option=option + '-dones', parent=self)
Expand All @@ -100,7 +99,7 @@ def session(self):
""" Initialize the session """
if self._session is None:
_s = requests.Session()
_s.headers['Authorization'] = 'Token {0}'.format(self.apitoken)
_s.headers['Authorization'] = 'Token {0}'.format(self.token)
self._session = _s
return self._session

Expand Down
2 changes: 1 addition & 1 deletion examples/config
Expand Up @@ -62,7 +62,7 @@ token = <token>

[idonethis]
type = idonethis
apitoken = <token>
token = <token>

[projects]
type = items
Expand Down
11 changes: 5 additions & 6 deletions tests/plugins/test_idonethis.py
Expand Up @@ -8,7 +8,6 @@
import pytest
import did.cli
import did.base
from did.base import ConfigError

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Constants
Expand All @@ -22,9 +21,9 @@
type = idonethis
"""

CONFIG_BAD_TOKEN = _C + '\napitoken = NOT_A_VALID_TOKEN'
CONFIG_BAD_TOKEN = _C + '\ntoken = NOT_A_VALID_TOKEN'
# test token created by "Chris Ward" <kejbaly2@gmail.com>
CONFIG_OK = _C + '\napitoken = 480710a894e756a27ef9d812f2309b8b2cd9dd4e'
CONFIG_OK = _C + '\ntoken = 480710a894e756a27ef9d812f2309b8b2cd9dd4e'

INTERVAL = "--since 2015-10-06 --until 2015-10-07"

Expand All @@ -45,15 +44,15 @@ def test_missing_token():
"""
import did
did.base.Config(CONFIG_NO_TOKEN)
with pytest.raises(ConfigError):
with pytest.raises(did.base.ConfigError):
did.cli.main(INTERVAL)


def test_invalid_token():
""" Invalid bitly token """
import did
did.base.Config(CONFIG_BAD_TOKEN)
with pytest.raises(RuntimeError):
with pytest.raises(did.base.ReportError):
did.cli.main(INTERVAL)


Expand All @@ -67,7 +66,7 @@ def test_all_dones():
result = did.cli.main(INTERVAL)
stats = result[0][0].stats[0].stats[0].stats
assert len(stats) == 5
_stats = [u'[2015-10-06] <kejbaly2_did_test> [ ] did goal test 1',
_stats = [u'[2015-10-07] <kejbaly2_did_test> [ ] did goal test 1',
u'[2015-10-06] <kejbaly2_did_test> [x] did goal done test 2',
u'[2015-10-06] <kejbaly2_did_test> did done test 1',
u'[2015-10-06] <kejbaly2_did_test> did done test 2',
Expand Down

0 comments on commit d6a8a45

Please sign in to comment.