Skip to content

Commit dadd511

Browse files
committed
Merge pull request GoogleCloudPlatform#44 from GoogleCloudPlatform/profile
Fixes Loading of User Credentials
2 parents d8bad24 + 4a37569 commit dadd511

File tree

15 files changed

+70
-7
lines changed

15 files changed

+70
-7
lines changed

4-auth/bookshelf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,6 @@ def _request_user_info(credentials):
119119
current_app.logger.error(
120120
"Error while obtaining user profile: %s" % resp)
121121
return None
122+
session['profile'] = json.loads(content.decode('utf-8'))
122123

123-
session['profile'] = json.loads(content)
124124
# [END request_user_info]

4-auth/requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ flaky==3.1.0
44
pytest==2.8.7
55
pytest-cov==2.2.1
66
retrying==1.3.3
7+
mock==1.3.0

4-auth/tests/test_auth.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
import contextlib
1616

17+
import bookshelf
1718
from conftest import flaky_filter
1819
from flaky import flaky
20+
import mock
1921
from oauth2client.client import OAuth2Credentials
2022
import pytest
2123

@@ -55,7 +57,6 @@ def inner():
5557
# in conftest.py
5658
@pytest.mark.usefixtures('app', 'model')
5759
class TestAuth(object):
58-
5960
def test_not_logged_in(self, app):
6061
with app.test_client() as c:
6162
rv = c.get('/books/')
@@ -120,3 +121,13 @@ def test_mine(self, model, client_with_credentials):
120121
body = rv.data.decode('utf-8')
121122
assert 'Book 1' in body
122123
assert 'Book 2' not in body
124+
125+
@mock.patch("httplib2.Http")
126+
def test_request_user_info(self, HttpMock):
127+
httpObj = mock.MagicMock()
128+
responseMock = mock.MagicMock(status=200)
129+
httpObj.request = mock.MagicMock(
130+
return_value=(responseMock, b'{"name": "bill"}'))
131+
HttpMock.return_value = httpObj
132+
credentials = mock.MagicMock()
133+
bookshelf._request_user_info(credentials)

5-logging/bookshelf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ def _request_user_info(credentials):
115115
"Error while obtaining user profile: %s" % resp)
116116
return None
117117

118-
session['profile'] = json.loads(content)
118+
session['profile'] = json.loads(content.decode('utf-8'))

5-logging/requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ flaky==3.1.0
44
pytest==2.8.7
55
pytest-cov==2.2.1
66
retrying==1.3.3
7+
mock==1.3.0

5-logging/tests/test_auth.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
import contextlib
1616

17+
import bookshelf
1718
from conftest import flaky_filter
1819
from flaky import flaky
20+
import mock
1921
from oauth2client.client import OAuth2Credentials
2022
import pytest
2123

@@ -120,3 +122,13 @@ def test_mine(self, model, client_with_credentials):
120122
body = rv.data.decode('utf-8')
121123
assert 'Book 1' in body
122124
assert 'Book 2' not in body
125+
126+
@mock.patch("httplib2.Http")
127+
def test_request_user_info(self, HttpMock):
128+
httpObj = mock.MagicMock()
129+
responseMock = mock.MagicMock(status=200)
130+
httpObj.request = mock.MagicMock(
131+
return_value=(responseMock, b'{"name": "bill"}'))
132+
HttpMock.return_value = httpObj
133+
credentials = mock.MagicMock()
134+
bookshelf._request_user_info(credentials)

6-pubsub/bookshelf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ def _request_user_info(credentials):
113113
"Error while obtaining user profile: %s" % resp)
114114
return None
115115

116-
session['profile'] = json.loads(content)
116+
session['profile'] = json.loads(content.decode('utf-8'))

6-pubsub/requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
tox==2.3.1
22
flake8==2.5.4
33
flaky==3.1.0
4+
mock==1.3.0
45
pytest==2.8.7
56
pytest-cov==2.2.1
67
BeautifulSoup4==4.4.1

6-pubsub/tests/test_auth.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
import contextlib
1616

17+
import bookshelf
1718
from conftest import flaky_filter
1819
from flaky import flaky
20+
import mock
1921
from oauth2client.client import OAuth2Credentials
2022
import pytest
2123

@@ -120,3 +122,13 @@ def test_mine(self, model, client_with_credentials):
120122
body = rv.data.decode('utf-8')
121123
assert 'Book 1' in body
122124
assert 'Book 2' not in body
125+
126+
@mock.patch("httplib2.Http")
127+
def test_request_user_info(self, HttpMock):
128+
httpObj = mock.MagicMock()
129+
responseMock = mock.MagicMock(status=200)
130+
httpObj.request = mock.MagicMock(
131+
return_value=(responseMock, b'{"name": "bill"}'))
132+
HttpMock.return_value = httpObj
133+
credentials = mock.MagicMock()
134+
bookshelf._request_user_info(credentials)

7-gce/bookshelf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,4 @@ def _request_user_info(credentials):
121121
"Error while obtaining user profile: %s" % resp)
122122
return None
123123

124-
session['profile'] = json.loads(content)
124+
session['profile'] = json.loads(content.decode('utf-8'))

0 commit comments

Comments
 (0)