Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage for 'gcloud._apitools.exceptions' #1191

Merged
merged 1 commit into from
Oct 25, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions gcloud/_apitools/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# pylint: skip-file
import unittest2


class Test_HttpError(unittest2.TestCase):

def _getTargetClass(self):
from gcloud._apitools.exceptions import HttpError
return HttpError

def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)

def test_ctor(self):
RESPONSE = {'status': '404'}
CONTENT = b'CONTENT'
URL = 'http://www.example.com'
exception = self._makeOne(RESPONSE, CONTENT, URL)
self.assertEqual(exception.response, RESPONSE)
self.assertEqual(exception.content, CONTENT)
self.assertEqual(exception.url, URL)
self.assertEqual(exception.status_code, 404)
self.assertEqual(
str(exception),
"HttpError accessing <http://www.example.com>: "
"response: <{'status': '404'}>, content <CONTENT>")

def test_FromResponse(self):

This comment was marked as spam.

This comment was marked as spam.

RESPONSE = {'status': '404'}
CONTENT = b'CONTENT'
URL = 'http://www.example.com'

class _Response(object):
info = RESPONSE
content = CONTENT
request_url = URL

klass = self._getTargetClass()
exception = klass.FromResponse(_Response())
self.assertTrue(isinstance(exception, klass))
self.assertEqual(exception.response, RESPONSE)
self.assertEqual(exception.content, CONTENT)
self.assertEqual(exception.url, URL)


class Test_RetryAfterError(unittest2.TestCase):

def _getTargetClass(self):
from gcloud._apitools.exceptions import RetryAfterError
return RetryAfterError

def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)

def test_ctor(self):
RESPONSE = {'status': '404'}
CONTENT = b'CONTENT'
URL = 'http://www.example.com'
RETRY_AFTER = 60
exception = self._makeOne(RESPONSE, CONTENT, URL, RETRY_AFTER)
self.assertEqual(exception.response, RESPONSE)
self.assertEqual(exception.content, CONTENT)
self.assertEqual(exception.url, URL)
self.assertEqual(exception.retry_after, RETRY_AFTER)
self.assertEqual(
str(exception),
"HttpError accessing <http://www.example.com>: "
"response: <{'status': '404'}>, content <CONTENT>")

def test_FromResponse(self):
RESPONSE = {'status': '404'}
CONTENT = b'CONTENT'
URL = 'http://www.example.com'
RETRY_AFTER = 60

class _Response(object):
info = RESPONSE
content = CONTENT
request_url = URL
retry_after = RETRY_AFTER

klass = self._getTargetClass()
exception = klass.FromResponse(_Response())
self.assertTrue(isinstance(exception, klass))
self.assertEqual(exception.response, RESPONSE)
self.assertEqual(exception.content, CONTENT)
self.assertEqual(exception.url, URL)
self.assertEqual(exception.retry_after, RETRY_AFTER)