Skip to content

Commit

Permalink
Merge pull request #421 from gdetrez/github-token-oracle
Browse files Browse the repository at this point in the history
Fix @oracle:eval with Github and python 3
  • Loading branch information
gdetrez authored Dec 6, 2016
2 parents 43ea5ba + 01ae4f5 commit 12759f2
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 11 deletions.
5 changes: 4 additions & 1 deletion bugwarrior/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import logging
log = logging.getLogger(__name__)

from bugwarrior.data import BugwarriorData


# The name of the environment variable that can be used to ovewrite the path
# to the bugwarriorrc file
Expand Down Expand Up @@ -81,7 +83,7 @@ def oracle_eval(command):
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
if p.returncode == 0:
return p.stdout.readline().strip()
return p.stdout.readline().strip().decode('utf-8')
else:
die(
"Error retrieving password: `{command}` returned '{error}'".format(
Expand Down Expand Up @@ -193,6 +195,7 @@ def load_config(main_section, interactive=False):
path = get_config_path()
config.readfp(codecs.open(path, "r", "utf-8",))
config.interactive = interactive
config.data = BugwarriorData(get_data_path(config, main_section))
validate_config(config, main_section)
return config

Expand Down
5 changes: 1 addition & 4 deletions bugwarrior/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

from lockfile.pidlockfile import PIDLockFile

from bugwarrior.config import get_data_path


class BugwarriorData(object):
def __init__(self, config, main_section):
data_path = get_data_path(config, main_section)
def __init__(self, data_path):
self.datafile = os.path.join(data_path, 'bugwarrior.data')
self.lockfile = os.path.join(data_path, 'bugwarrior-data.lockfile')

Expand Down
2 changes: 0 additions & 2 deletions bugwarrior/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from taskw.task import Task

from bugwarrior.config import asbool, die, get_service_password
from bugwarrior.data import BugwarriorData
from bugwarrior.db import MARKUP, URLShortener

import logging
Expand Down Expand Up @@ -52,7 +51,6 @@ class IssueService(object):
def __init__(self, config, main_section, target):
self.config = config
self.main_section = main_section
self.data = BugwarriorData(config, main_section)
self.target = target

self.desc_len = 35
Expand Down
6 changes: 3 additions & 3 deletions bugwarrior/services/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, *args, **kw):
secret = self.config_get_default('secret')
auth = {'oauth': (key, secret)}

refresh_token = self.data.get('bitbucket_refresh_token')
refresh_token = self.config.data.get('bitbucket_refresh_token')

if not refresh_token:
login = self.config_get('login')
Expand All @@ -95,8 +95,8 @@ def __init__(self, *args, **kw):
'password': password},
auth=auth['oauth']).json()

self.data.set('bitbucket_refresh_token',
response['refresh_token'])
self.config.data.set('bitbucket_refresh_token',
response['refresh_token'])

auth['token'] = response['access_token']

Expand Down
2 changes: 2 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import responses

from bugwarrior import config
from bugwarrior.data import BugwarriorData


class AbstractServiceTest(object):
Expand Down Expand Up @@ -92,6 +93,7 @@ def get_int(section, name):
config.has_option = mock.Mock(side_effect=has_option)
config.get = mock.Mock(side_effect=get_option)
config.getint = mock.Mock(side_effect=get_int)
config.data = BugwarriorData(self.lists_path)

service_instance = service_class(config, 'general', section)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# coding: utf-8
from __future__ import unicode_literals

import os
import configparser
from unittest import TestCase

import bugwarrior.config as config

Expand Down Expand Up @@ -108,3 +110,9 @@ def test_unassigned(self):
os.environ['TASKDATA'] = ''

self.assertDataPath(os.path.expanduser('~/.task'))


class TestOracleEval(TestCase):

def test_echo(self):
self.assertEqual(config.oracle_eval("echo fööbår"), "fööbår")
2 changes: 1 addition & 1 deletion tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def setUp(self):
super(TestData, self).setUp()
config = configparser.RawConfigParser()
config.add_section('general')
self.data = data.BugwarriorData(config, 'general')
self.data = data.BugwarriorData(self.lists_path)

def assert0600(self):
permissions = oct(os.stat(self.data.datafile).st_mode & 0o777)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_github.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from builtins import next
import datetime
from unittest import TestCase
from configparser import RawConfigParser

import pytz
import responses
Expand Down Expand Up @@ -130,3 +132,20 @@ def test_issues(self):
'tags': []}

self.assertEqual(issue.get_taskwarrior_record(), expected)


class TestGithubService(TestCase):

def test_token_authorization_header(self):
config = RawConfigParser()
config.interactive = False
config.add_section('general')
config.add_section('mygithub')
config.set('mygithub', 'service', 'github')
config.set('mygithub', 'github.login', 'tintin')
config.set('mygithub', 'github.username', 'tintin')
config.set('mygithub', 'github.token',
'@oracle:eval:echo 1234567890ABCDEF')
service = GithubService(config, 'general', 'mygithub')
self.assertEqual(service.client.session.headers['Authorization'],
"token 1234567890ABCDEF")

0 comments on commit 12759f2

Please sign in to comment.