Error handling: Model-level validations, proper error responses. (backport assert_raises as context manager for Python 2.6)
This commit is contained in:
parent
d160f2c6d6
commit
c97417d8e7
37
tests/backport_assert_raises.py
Normal file
37
tests/backport_assert_raises.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
"""
|
||||||
|
Patch courtesy of:
|
||||||
|
https://marmida.com/blog/index.php/2012/08/08/monkey-patching-assert_raises/
|
||||||
|
"""
|
||||||
|
|
||||||
|
# code for monkey-patching
|
||||||
|
import nose.tools
|
||||||
|
|
||||||
|
# let's fix nose.tools.assert_raises (which is really unittest.assertRaises)
|
||||||
|
# so that it always supports context management
|
||||||
|
|
||||||
|
# in order for these changes to be available to other modules, you'll need
|
||||||
|
# to guarantee this module is imported by your fixture before either nose or
|
||||||
|
# unittest are imported
|
||||||
|
|
||||||
|
try:
|
||||||
|
nose.tools.assert_raises(Exception)
|
||||||
|
except TypeError:
|
||||||
|
# this version of assert_raises doesn't support the 1-arg version
|
||||||
|
class AssertRaisesContext(object):
|
||||||
|
def __init__(self, expected):
|
||||||
|
self.expected = expected
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, tb):
|
||||||
|
self.exception = exc_val
|
||||||
|
nose.tools.assert_equal(exc_type, self.expected)
|
||||||
|
# if you get to this line, the last assertion must have passed
|
||||||
|
# suppress the propagation of this exception
|
||||||
|
return True
|
||||||
|
|
||||||
|
def assert_raises_context(exc_type):
|
||||||
|
return AssertRaisesContext(exc_type)
|
||||||
|
|
||||||
|
nose.tools.assert_raises = assert_raises_context
|
@ -1,8 +1,11 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
|
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
|
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
from moto.ec2.models import ec2_backend
|
from moto.ec2.models import ec2_backend
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
"""Test mocking of Elatic IP Address"""
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
|
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.ec2.instance import Reservation, InstanceAttribute
|
from boto.ec2.instance import Reservation, InstanceAttribute
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
|
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
from tests.helpers import requires_boto_gte
|
from tests.helpers import requires_boto_gte
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||||
|
import tests.backport_assert_raises
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
import boto
|
import boto
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
from nose.tools import assert_raises
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
from moto import mock_ec2
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user