Make Moto (tests) compatible with flask/werkzeug 2.x (#3923)
* Dont fail if CodeCov fails - for now
* CI - Force cache rebuild
* Bump werkzeug to latest version
* CI - Enforce cache flush
* ManagedBlockchain - fix error format
* ManagedBlockchain - Fix tests to use pytest.raises paradigm
* Revert "Lock Flask (#3925)"
This reverts commit 8bb0feb956.
* CI - Enforce cache rebuild
This commit is contained in:
parent
8bb0feb956
commit
9e3faf7784
11 changed files with 599 additions and 317 deletions
|
|
@ -1,10 +1,55 @@
|
|||
from __future__ import unicode_literals
|
||||
from moto.core.exceptions import RESTError
|
||||
from functools import wraps
|
||||
from werkzeug.exceptions import HTTPException
|
||||
from jinja2 import DictLoader, Environment
|
||||
|
||||
|
||||
class ManagedBlockchainClientError(RESTError):
|
||||
ERROR_JSON_RESPONSE = """{
|
||||
"message": "{{message}}"
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def exception_handler(f):
|
||||
@wraps(f)
|
||||
def _wrapper(*args, **kwargs):
|
||||
try:
|
||||
return f(*args, **kwargs)
|
||||
except ManagedBlockchainClientError as err:
|
||||
return err.code, err.get_headers(), err.description
|
||||
|
||||
return _wrapper
|
||||
|
||||
|
||||
class ManagedBlockchainClientError(HTTPException):
|
||||
code = 400
|
||||
|
||||
templates = {
|
||||
"error": ERROR_JSON_RESPONSE,
|
||||
}
|
||||
|
||||
def __init__(self, error_type, message, **kwargs):
|
||||
super(HTTPException, self).__init__()
|
||||
env = Environment(loader=DictLoader(self.templates))
|
||||
self.error_type = error_type
|
||||
self.message = message
|
||||
self.description = env.get_template("error").render(
|
||||
error_type=error_type, message=message, **kwargs
|
||||
)
|
||||
|
||||
def get_headers(self, *args, **kwargs):
|
||||
return [
|
||||
("Content-Type", "application/json"),
|
||||
("x-amzn-ErrorType", self.error_type),
|
||||
]
|
||||
|
||||
@property
|
||||
def response(self):
|
||||
return self.get_body()
|
||||
|
||||
def get_body(self, *args, **kwargs):
|
||||
return self.description
|
||||
|
||||
|
||||
class BadRequestException(ManagedBlockchainClientError):
|
||||
def __init__(self, pretty_called_method, operation_error):
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import json
|
|||
from six.moves.urllib.parse import urlparse, parse_qs
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from .exceptions import exception_handler
|
||||
from .models import managedblockchain_backends
|
||||
from .utils import (
|
||||
region_from_managedblckchain_url,
|
||||
|
|
@ -21,6 +22,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
self.backend = backend
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def network_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
@ -73,6 +75,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
return 200, headers, json.dumps(response)
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def networkid_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
@ -94,6 +97,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
return 200, headers, response
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def proposal_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
@ -139,6 +143,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
return 200, headers, json.dumps(response)
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def proposalid_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
@ -160,6 +165,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
return 200, headers, response
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def proposal_votes_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
@ -203,6 +209,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
return 200, headers, ""
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def invitation_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
@ -224,6 +231,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
return 200, headers, response
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def invitationid_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
@ -243,6 +251,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
return 200, headers, ""
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def member_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
@ -283,6 +292,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
return 200, headers, json.dumps(response)
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def memberid_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
@ -327,6 +337,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
return 200, headers, ""
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def node_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
@ -380,6 +391,7 @@ class ManagedBlockchainResponse(BaseResponse):
|
|||
return 200, headers, json.dumps(response)
|
||||
|
||||
@classmethod
|
||||
@exception_handler
|
||||
def nodeid_response(clazz, request, full_url, headers):
|
||||
region_name = region_from_managedblckchain_url(full_url)
|
||||
response_instance = ManagedBlockchainResponse(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue