Adding server mode
This commit is contained in:
parent
c6f5afff75
commit
a728b2581a
31 changed files with 489 additions and 66 deletions
|
|
@ -2,6 +2,7 @@ import functools
|
|||
import re
|
||||
|
||||
from moto.packages.httpretty import HTTPretty
|
||||
from .utils import convert_regex_to_flask_path
|
||||
|
||||
|
||||
class MockAWS(object):
|
||||
|
|
@ -48,13 +49,56 @@ class BaseBackend(object):
|
|||
self.__init__()
|
||||
|
||||
@property
|
||||
def urls(self):
|
||||
def _url_module(self):
|
||||
backend_module = self.__class__.__module__
|
||||
backend_urls_module_name = backend_module.replace("models", "urls")
|
||||
backend_urls_module = __import__(backend_urls_module_name, fromlist=['urls'])
|
||||
urls = backend_urls_module.urls
|
||||
backend_urls_module = __import__(backend_urls_module_name, fromlist=['url_bases', 'url_paths'])
|
||||
return backend_urls_module
|
||||
|
||||
@property
|
||||
def urls(self):
|
||||
"""
|
||||
A dictionary of the urls to be mocked with this service and the handlers
|
||||
that should be called in their place
|
||||
"""
|
||||
url_bases = self._url_module.url_bases
|
||||
unformatted_paths = self._url_module.url_paths
|
||||
|
||||
urls = {}
|
||||
for url_base in url_bases:
|
||||
for url_path, handler in unformatted_paths.iteritems():
|
||||
url = url_path.format(url_base)
|
||||
urls[url] = handler
|
||||
|
||||
return urls
|
||||
|
||||
@property
|
||||
def url_paths(self):
|
||||
"""
|
||||
A dictionary of the paths of the urls to be mocked with this service and
|
||||
the handlers that should be called in their place
|
||||
"""
|
||||
unformatted_paths = self._url_module.url_paths
|
||||
|
||||
paths = {}
|
||||
for unformatted_path, handler in unformatted_paths.iteritems():
|
||||
path = unformatted_path.format("")
|
||||
paths[path] = handler
|
||||
|
||||
return paths
|
||||
|
||||
@property
|
||||
def flask_paths(self):
|
||||
"""
|
||||
The url paths that will be used for the flask server
|
||||
"""
|
||||
paths = {}
|
||||
for url_path, handler in self.url_paths.iteritems():
|
||||
url_path = convert_regex_to_flask_path(url_path)
|
||||
paths[url_path] = handler
|
||||
|
||||
return paths
|
||||
|
||||
def decorator(self, func=None):
|
||||
if func:
|
||||
return MockAWS(self)(func)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue