From dc9677e32360db6305895bae31900a2f45a886a1 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Mon, 25 Feb 2013 23:48:17 -0500 Subject: [PATCH] clean up core responses --- moto/core/models.py | 4 ++-- moto/core/responses.py | 23 ++++++++++++++++++++++ moto/packages/__init__.py | 0 httpretty.py => moto/packages/httpretty.py | 0 tests/test_sqs/test_sqs.py | 6 ------ 5 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 moto/core/responses.py create mode 100644 moto/packages/__init__.py rename httpretty.py => moto/packages/httpretty.py (100%) diff --git a/moto/core/models.py b/moto/core/models.py index 1a0268569..48a695c6d 100644 --- a/moto/core/models.py +++ b/moto/core/models.py @@ -1,12 +1,13 @@ import functools import re -from httpretty import HTTPretty +from moto.packages.httpretty import HTTPretty class BaseBackend(object): def reset(self): + self.__dict__ = {} self.__init__() @property @@ -22,7 +23,6 @@ class BaseBackend(object): def wrapper(*args, **kw): self.reset() - HTTPretty.reset() HTTPretty.enable() for method in HTTPretty.METHODS: diff --git a/moto/core/responses.py b/moto/core/responses.py new file mode 100644 index 000000000..5e645b44f --- /dev/null +++ b/moto/core/responses.py @@ -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)) diff --git a/moto/packages/__init__.py b/moto/packages/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/httpretty.py b/moto/packages/httpretty.py similarity index 100% rename from httpretty.py rename to moto/packages/httpretty.py diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index 1c220f764..4d1fd24fa 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -113,9 +113,3 @@ def test_delete_batch_operation(): queue.delete_message_batch(messages) 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)