8000 Separate test from mocked methods. · googleapis/google-cloud-python@1187c48 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 1187c48

Browse files
committed
Separate test from mocked methods.
1 parent 51c0a3f commit 1187c48

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

gcloud/test_credentials.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _callFUT(self, *args, **kwargs):
4040
return generate_signed_url(*args, **kwargs)
4141

4242
def _generate_helper(self, response_type=None, response_disposition=None,
43-
generation=None, credentials=None):
43+
generation=None):
4444
import base64
4545
from six.moves.urllib.parse import parse_qs
4646
from six.moves.urllib.parse import urlsplit
@@ -50,7 +50,7 @@ def _generate_helper(self, response_type=None, response_disposition=None,
5050
ENDPOINT = 'http://api.example.com'
5151
RESOURCE = '/name/path'
5252
SIGNED = base64.b64encode(b'DEADBEEF')
53-
CREDENTIALS = credentials or _Credentials()
53+
CREDENTIALS = _Credentials()
5454

5555
def _get_signed_query_params(*args):
5656
credentials, expiration = args[:2]
@@ -90,19 +90,27 @@ def _get_signed_query_params(*args):
9090
self.assertEqual(frag, '')
9191

9292
def test_w_expiration_int(self):
93-
self._generate_helper(credentials=_Credentials())
94-
95-
def test_w_google_credentials(self):
96-
self._generate_helper(credentials=_GoogleCredentials())
93+
self._generate_helper()
9794

9895
def test_w_custom_fields(self):
9996
response_type = 'text/plain'
10097
response_disposition = 'attachment; filename=blob.png'
10198
generation = '123'
10299
self._generate_helper(response_type=response_type,
103100
response_disposition=response_disposition,
104-
generation=generation,
105-
credentials=_Credentials())
101+
generation=generation)
102+
103+
104+
class Test_generate_signed_url_exception(unittest2.TestCase):
105+
def test_with_google_credentials(self):
106+
import time
107+
from gcloud.credentials import generate_signed_url
108+
RESOURCE = '/name/path'
109+
110+
credentials = _GoogleCredentials()
111+
expiration = int(time.time() + 5)
112+
self.assertRaises(AttributeError, generate_signed_url, credentials,
113+
resource=RESOURCE, expiration=expiration)
106114

107115

108116
class Test__get_signed_query_params(unittest2.TestCase):
@@ -114,8 +122,6 @@ def _callFUT(self, credentials, expiration, string_to_sign):
114122

115123
def test_it(self):
116124
import base64
117-
# from gcloud._testing import _Monkey
118-
# from gcloud import credentials as MUT
119125

120126
SIG_BYTES = b'DEADBEEF'
121127
ACCOUNT_NAME = object()

0 commit comments

Comments
 (0)
0