From 27dc4bc3615d11087f1663d78ab05b4ac5520b02 Mon Sep 17 00:00:00 2001 From: Kyle Hornberg Date: Fri, 1 Jun 2018 13:34:58 -0500 Subject: [PATCH] Bug Fix: Can use app auth --- src/octokit/__init__.py | 4 ++-- tests/test_auth.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/octokit/__init__.py b/src/octokit/__init__.py index 406452f..c8e8ac2 100644 --- a/src/octokit/__init__.py +++ b/src/octokit/__init__.py @@ -131,10 +131,10 @@ class Base(object): 'Authorization': 'Bearer {}'.format(getattr(self, 'jwt', None)) }, 'token': { - 'Authorization': 'token {}'.format(self.token) + 'Authorization': 'token {}'.format(getattr(self, 'token', None)) }, 'installation': { - 'Authorization': 'token {}'.format(self.token) + 'Authorization': 'token {}'.format(getattr(self, 'token', None)) }, } headers = requests_kwargs['headers'] diff --git a/tests/test_auth.py b/tests/test_auth.py index a24f754..100fd08 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -123,3 +123,12 @@ class TestAuth(object): sut = Octokit(auth='app', app_id=42, private_key=private_key) assert sut.auth == 'app' assert sut.jwt is not None + + def test_can_get_with_app_authentication(self, mocker): + Request = namedtuple('Request', ['json']) + get = mocker.patch('requests.get') + get.return_value = Request(json=lambda: [{'id': 37}]) + with open(os.path.join(os.path.dirname(__file__), 'test.pem'), 'r') as f: + private_key = f.read() + sut = Octokit(auth='app', app_id=42, private_key=private_key) + assert sut.apps.get()