Skip to content

Commit

Permalink
Separate test from mocked methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
daspecster committed Jul 8, 2016
1 parent 51c0a3f commit 1187c48
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions gcloud/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _callFUT(self, *args, **kwargs):
return generate_signed_url(*args, **kwargs)

def _generate_helper(self, response_type=None, response_disposition=None,
generation=None, credentials=None):
generation=None):
import base64
from six.moves.urllib.parse import parse_qs
from six.moves.urllib.parse import urlsplit
Expand All @@ -50,7 +50,7 @@ def _generate_helper(self, response_type=None, response_disposition=None,
ENDPOINT = 'http://api.example.com'
RESOURCE = '/name/path'
SIGNED = base64.b64encode(b'DEADBEEF')
CREDENTIALS = credentials or _Credentials()
CREDENTIALS = _Credentials()

def _get_signed_query_params(*args):
credentials, expiration = args[:2]
Expand Down Expand Up @@ -90,19 +90,27 @@ def _get_signed_query_params(*args):
self.assertEqual(frag, '')

def test_w_expiration_int(self):
self._generate_helper(credentials=_Credentials())

def test_w_google_credentials(self):
self._generate_helper(credentials=_GoogleCredentials())
self._generate_helper()

def test_w_custom_fields(self):
response_type = 'text/plain'
response_disposition = 'attachment; filename=blob.png'
generation = '123'
self._generate_helper(response_type=response_type,
response_disposition=response_disposition,
generation=generation,
credentials=_Credentials())
generation=generation)


class Test_generate_signed_url_exception(unittest2.TestCase):
def test_with_google_credentials(self):
import time
from gcloud.credentials import generate_signed_url
RESOURCE = '/name/path'

credentials = _GoogleCredentials()
expiration = int(time.time() + 5)
self.assertRaises(AttributeError, generate_signed_url, credentials,
resource=RESOURCE, expiration=expiration)


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

def test_it(self):
import base64
# from gcloud._testing import _Monkey
# from gcloud import credentials as MUT

SIG_BYTES = b'DEADBEEF'
ACCOUNT_NAME = object()
Expand Down

0 comments on commit 1187c48

Please sign in to comment.