clean up core responses

This commit is contained in:
Steve Pulec 2013-02-25 23:48:17 -05:00
parent 935e6bd95d
commit dc9677e323
5 changed files with 25 additions and 8 deletions

View File

@ -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
View 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))

View File

View 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)