Merge pull request #73 from andresriancho/feature/fix_nested_decorators_72
Feature/fix nested decorators 72
This commit is contained in:
commit
5f7e60194f
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,5 +3,8 @@ dist/*
|
|||||||
.tox
|
.tox
|
||||||
.coverage
|
.coverage
|
||||||
*.pyc
|
*.pyc
|
||||||
|
*~
|
||||||
.noseids
|
.noseids
|
||||||
build/
|
build/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
@ -7,9 +7,13 @@ from .utils import convert_regex_to_flask_path
|
|||||||
|
|
||||||
|
|
||||||
class MockAWS(object):
|
class MockAWS(object):
|
||||||
|
nested_count = 0
|
||||||
|
|
||||||
def __init__(self, backend):
|
def __init__(self, backend):
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
HTTPretty.reset()
|
|
||||||
|
if self.__class__.nested_count == 0:
|
||||||
|
HTTPretty.reset()
|
||||||
|
|
||||||
def __call__(self, func):
|
def __call__(self, func):
|
||||||
return self.decorate_callable(func)
|
return self.decorate_callable(func)
|
||||||
@ -21,8 +25,11 @@ class MockAWS(object):
|
|||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
self.__class__.nested_count += 1
|
||||||
self.backend.reset()
|
self.backend.reset()
|
||||||
HTTPretty.enable()
|
|
||||||
|
if not HTTPretty.is_enabled():
|
||||||
|
HTTPretty.enable()
|
||||||
|
|
||||||
for method in HTTPretty.METHODS:
|
for method in HTTPretty.METHODS:
|
||||||
for key, value in self.backend.urls.iteritems():
|
for key, value in self.backend.urls.iteritems():
|
||||||
@ -40,7 +47,13 @@ class MockAWS(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
HTTPretty.disable()
|
self.__class__.nested_count -= 1
|
||||||
|
|
||||||
|
if self.__class__.nested_count < 0:
|
||||||
|
raise RuntimeError('Called stop() before start().')
|
||||||
|
|
||||||
|
if self.__class__.nested_count == 0:
|
||||||
|
HTTPretty.disable()
|
||||||
|
|
||||||
def decorate_callable(self, func):
|
def decorate_callable(self, func):
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
|
28
tests/test_core/test_nested.py
Normal file
28
tests/test_core/test_nested.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from boto.sqs.connection import SQSConnection
|
||||||
|
from boto.sqs.message import Message
|
||||||
|
from boto.ec2 import EC2Connection
|
||||||
|
|
||||||
|
from moto import mock_sqs, mock_ec2
|
||||||
|
|
||||||
|
|
||||||
|
class TestNestedDecorators(unittest.TestCase):
|
||||||
|
|
||||||
|
@mock_sqs
|
||||||
|
def setup_sqs_queue(self):
|
||||||
|
conn = SQSConnection()
|
||||||
|
q = conn.create_queue('some-queue')
|
||||||
|
|
||||||
|
m = Message()
|
||||||
|
m.set_body('This is my first message.')
|
||||||
|
q.write(m)
|
||||||
|
|
||||||
|
self.assertEqual(q.count(), 1)
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_nested(self):
|
||||||
|
self.setup_sqs_queue()
|
||||||
|
|
||||||
|
conn = EC2Connection()
|
||||||
|
conn.run_instances('ami-123456')
|
Loading…
Reference in New Issue
Block a user