clean up core responses
This commit is contained in:
parent
935e6bd95d
commit
dc9677e323
@ -1,12 +1,13 @@
|
|||||||
import functools
|
import functools
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from httpretty import HTTPretty
|
from moto.packages.httpretty import HTTPretty
|
||||||
|
|
||||||
|
|
||||||
class BaseBackend(object):
|
class BaseBackend(object):
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
self.__dict__ = {}
|
||||||
self.__init__()
|
self.__init__()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -22,7 +23,6 @@ class BaseBackend(object):
|
|||||||
def wrapper(*args, **kw):
|
def wrapper(*args, **kw):
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
HTTPretty.reset()
|
|
||||||
HTTPretty.enable()
|
HTTPretty.enable()
|
||||||
|
|
||||||
for method in HTTPretty.METHODS:
|
for method in HTTPretty.METHODS:
|
||||||
|
23
moto/core/responses.py
Normal file
23
moto/core/responses.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from urlparse import parse_qs
|
||||||
|
|
||||||
|
from moto.core.utils import headers_to_dict, camelcase_to_underscores, method_names_from_class
|
||||||
|
|
||||||
|
|
||||||
|
class BaseResponse(object):
|
||||||
|
def dispatch(self, uri, body, headers):
|
||||||
|
if body:
|
||||||
|
querystring = parse_qs(body)
|
||||||
|
else:
|
||||||
|
querystring = headers_to_dict(headers)
|
||||||
|
|
||||||
|
self.path = uri.path
|
||||||
|
self.querystring = querystring
|
||||||
|
|
||||||
|
action = querystring['Action'][0]
|
||||||
|
action = camelcase_to_underscores(action)
|
||||||
|
|
||||||
|
method_names = method_names_from_class(self.__class__)
|
||||||
|
if action in method_names:
|
||||||
|
method = getattr(self, action)
|
||||||
|
return method()
|
||||||
|
raise NotImplementedError("The {} action has not been implemented".format(action))
|
0
moto/packages/__init__.py
Normal file
0
moto/packages/__init__.py
Normal file
@ -113,9 +113,3 @@ def test_delete_batch_operation():
|
|||||||
queue.delete_message_batch(messages)
|
queue.delete_message_batch(messages)
|
||||||
|
|
||||||
queue.count().should.equal(1)
|
queue.count().should.equal(1)
|
||||||
|
|
||||||
|
|
||||||
@mock_sqs
|
|
||||||
def test_not_implemented_method():
|
|
||||||
requests.post.when.called_with("https://foobar.amazonaws.com/",
|
|
||||||
data={'Action':['foobar']}).should.throw(NotImplementedError)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user