Skip to content

Commit ed2dc92

Browse files
committed
Making coverage pass in core tox environment.
This was necessary because some lines were only tested transitively in the umbrella package, rather than directly by the core tests.
1 parent 9a70f16 commit ed2dc92

3 files changed

Lines changed: 65 additions & 4 deletions

File tree

core/unit_tests/streaming/test_buffered_stream.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ def _getTargetClass(self):
2424
def _makeOne(self, *args, **kw):
2525
return self._getTargetClass()(*args, **kw)
2626

27+
def test_ctor_closed_stream(self):
28+
class _Stream(object):
29+
closed = True
30+
31+
start = 0
32+
bufsize = 4
33+
bufstream = self._makeOne(_Stream, start, bufsize)
34+
self.assertIs(bufstream._stream, _Stream)
35+
self.assertEqual(bufstream._start_pos, start)
36+
self.assertEqual(bufstream._buffer_pos, 0)
37+
self.assertEqual(bufstream._buffered_data, b'')
38+
self.assertTrue(bufstream._stream_at_end)
39+
self.assertEqual(bufstream._end_pos, 0)
40+
2741
def test_ctor_start_zero_longer_than_buffer(self):
2842
from io import BytesIO
2943
CONTENT = b'CONTENT GOES HERE'

core/unit_tests/test_connection.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,37 @@ def test_user_agent_format(self):
7474
conn = self._makeOne()
7575
self.assertEqual(conn.USER_AGENT, expected_ua)
7676

77+
def test__create_scoped_credentials_with_scoped_credentials(self):
78+
klass = self._getTargetClass()
79+
scoped_creds = object()
80+
scope = 'google-specific-scope'
81+
credentials = _Credentials(scoped=scoped_creds)
82+
83+
result = klass._create_scoped_credentials(credentials, scope)
84+
self.assertIs(result, scoped_creds)
85+
self.assertEqual(credentials._create_scoped_calls, 1)
86+
self.assertEqual(credentials._scopes, [scope])
87+
88+
def test__create_scoped_credentials_without_scope_required(self):
89+
klass = self._getTargetClass()
90+
credentials = _Credentials()
91+
92+
result = klass._create_scoped_credentials(credentials, None)
93+
self.assertIs(result, credentials)
94+
self.assertEqual(credentials._create_scoped_calls, 1)
95+
self.assertEqual(credentials._scopes, [])
96+
97+
def test__create_scoped_credentials_non_scoped_credentials(self):
98+
klass = self._getTargetClass()
99+
credentials = object()
100+
result = klass._create_scoped_credentials(credentials, None)
101+
self.assertIs(result, credentials)
102+
103+
def test__create_scoped_credentials_no_credentials(self):
104+
klass = self._getTargetClass()
105+
result = klass._create_scoped_credentials(None, None)
106+
self.assertIsNone(result)
107+
77108

78109
class TestJSONConnection(unittest.TestCase):
79110

@@ -375,16 +406,21 @@ def request(self, **kw):
375406

376407
class _Credentials(object):
377408

378-
_scopes = None
379-
380-
def __init__(self, authorized=None):
409+
def __init__(self, authorized=None, scoped=None):
381410
self._authorized = authorized
411+
self._scoped = scoped
412+
self._scoped_required = scoped is not None
382413
self._create_scoped_calls = 0
414+
self._scopes = []
383415

384416
def authorize(self, http):
385417
self._called_with = http
386418
return self._authorized
387419

388420
def create_scoped_required(self):
389421
self._create_scoped_calls += 1
390-
return False
422+
return self._scoped_required
423+
424+
def create_scoped(self, scope):
425+
self._scopes.append(scope)
426+
return self._scoped

core/unit_tests/test_exceptions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ def test_html_when_json_expected(self):
125125
self.assertEqual(exception.message, content)
126126
self.assertEqual(list(exception.errors), [])
127127

128+
def test_without_use_json(self):
129+
from google.cloud.exceptions import TooManyRequests
130+
131+
content = u'error-content'
132+
response = _Response(TooManyRequests.code)
133+
exception = self._callFUT(response, content, use_json=False)
134+
135+
self.assertIsInstance(exception, TooManyRequests)
136+
self.assertEqual(exception.message, content)
137+
self.assertEqual(list(exception.errors), [])
138+
128139

129140
class _Response(object):
130141
def __init__(self, status):

0 commit comments

Comments
 (0)