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:
Bert Blommers 2021-05-13 10:36:56 +01:00 committed by GitHub
parent 8bb0feb956
commit 9e3faf7784
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 599 additions and 317 deletions

View File

@ -26,7 +26,7 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache-dir.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}-4
- name: Update pip
if: ${{ steps.pip-cache.outputs.cache-hit != 'true' && matrix.python-version != '2.7' }}
run: |
@ -58,7 +58,7 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}-4
# Update PIP - recent version does not support PY2 though
- name: Update pip
if: ${{ matrix.python-version != '2.7' }}
@ -97,7 +97,7 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}-4
- name: Update pip
if: ${{ matrix.python-version != '2.7' }}
run: |
@ -113,7 +113,7 @@ jobs:
if: ${{ github.repository == 'spulec/moto'}}
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
fail_ci_if_error: false
flags: unittests
testserver:
@ -145,7 +145,7 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}-4
- name: Update pip
if: ${{ matrix.python-version != '2.7' }}
run: |
@ -162,7 +162,7 @@ jobs:
if: ${{ github.repository == 'spulec/moto'}}
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
fail_ci_if_error: false
flags: servertests
deploy:

View File

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

View File

@ -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(

View File

@ -7,7 +7,7 @@ coverage==4.5.4
flake8==3.7.8
boto>=2.45.0
prompt-toolkit==2.0.10 # 3.x is not available with python2
click==6.7
click
inflection==0.3.1
lxml
packaging

View File

@ -36,8 +36,7 @@ install_requires = [
"requests>=2.5",
"xmltodict",
"six>1.9",
# TODO: werkzeug 2.x currently breaks test_s3_server_post_without_content_length
"werkzeug<2.0.0",
"werkzeug",
"pytz",
"python-dateutil<3.0.0,>=2.1",
"responses>=0.9.0",
@ -99,7 +98,7 @@ all_extra_deps = [
_dep_sshpubkeys_py2,
_dep_sshpubkeys_py3,
]
all_server_deps = all_extra_deps + ["flask<2.0.0", "flask-cors"]
all_server_deps = all_extra_deps + ["flask", "flask-cors"]
# TODO: do we want to add ALL services here?
# i.e. even those without extra dependencies.

View File

@ -1,8 +1,10 @@
from __future__ import unicode_literals
import boto3
import pytest
import sure # noqa
from botocore.exceptions import ClientError
from moto import mock_managedblockchain
from . import helpers
@ -136,6 +138,10 @@ def test_reject_invitation_badinvitation():
Vote="YES",
)
response = conn.reject_invitation.when.called_with(
InvitationId="in-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "InvitationId in-ABCDEFGHIJKLMNOP0123456789 not found.")
with pytest.raises(ClientError) as ex:
conn.reject_invitation(InvitationId="in-ABCDEFGHIJKLMNOP0123456789")
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain(
"InvitationId in-ABCDEFGHIJKLMNOP0123456789 not found."
)

View File

@ -1,8 +1,10 @@
from __future__ import unicode_literals
import boto3
import pytest
import sure # noqa
from botocore.exceptions import ClientError, ParamValidationError
from moto import mock_managedblockchain
from . import helpers
@ -165,13 +167,17 @@ def test_create_another_member_withopts():
response["Member"]["Description"].should.equal("Test Member 2")
# Try to create member with already used invitation
response = conn.create_member.when.called_with(
InvitationId=invitation_id,
NetworkId=network_id,
MemberConfiguration=helpers.create_member_configuration(
"testmember2", "admin", "Admin12345", False, "Test Member 2 Duplicate"
),
).should.throw(Exception, "Invitation {0} not valid".format(invitation_id))
with pytest.raises(ClientError) as ex:
conn.create_member(
InvitationId=invitation_id,
NetworkId=network_id,
MemberConfiguration=helpers.create_member_configuration(
"testmember2", "admin", "Admin12345", False, "Test Member 2 Duplicate"
),
)
err = ex.value.response["Error"]
err["Code"].should.equal("InvalidRequestException")
err["Message"].should.contain("Invitation {0} not valid".format(invitation_id))
# Delete member 2
conn.delete_member(NetworkId=network_id, MemberId=member_id2)
@ -182,9 +188,11 @@ def test_create_another_member_withopts():
members.should.have.length_of(2)
# But cannot get
response = conn.get_member.when.called_with(
NetworkId=network_id, MemberId=member_id2,
).should.throw(Exception, "Member {0} not found".format(member_id2))
with pytest.raises(ClientError) as ex:
conn.get_member(NetworkId=network_id, MemberId=member_id2)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member {0} not found".format(member_id2))
# Delete member 1
conn.delete_member(NetworkId=network_id, MemberId=member_id)
@ -362,13 +370,17 @@ def test_create_too_many_members():
)[0]
# Try to create one too many members
response = conn.create_member.when.called_with(
InvitationId=invitation_id,
NetworkId=network_id,
MemberConfiguration=helpers.create_member_configuration(
"testmember6", "admin", "Admin12345", False, "Test Member 6"
),
).should.throw(Exception, "is the maximum number of members allowed in a",)
with pytest.raises(ClientError) as ex:
conn.create_member(
InvitationId=invitation_id,
NetworkId=network_id,
MemberConfiguration=helpers.create_member_configuration(
"testmember6", "admin", "Admin12345", False, "Test Member 6"
),
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceLimitExceededException")
err["Message"].should.contain("is the maximum number of members allowed in a")
@mock_managedblockchain
@ -409,17 +421,20 @@ def test_create_another_member_alreadyhave():
invitation_id = response["Invitations"][0]["InvitationId"]
# Should fail trying to create with same name
response = conn.create_member.when.called_with(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=helpers.create_member_configuration(
"testmember1", "admin", "Admin12345", False
),
).should.throw(
Exception,
with pytest.raises(ClientError) as ex:
conn.create_member(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=helpers.create_member_configuration(
"testmember1", "admin", "Admin12345", False
),
)
err = ex.value.response["Error"]
err["Code"].should.equal("InvalidRequestException")
err["Message"].should.contain(
"Member name {0} already exists in network {1}".format(
"testmember1", network_id
),
)
)
@ -427,13 +442,17 @@ def test_create_another_member_alreadyhave():
def test_create_another_member_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.create_member.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
InvitationId="id-ABCDEFGHIJKLMNOP0123456789",
MemberConfiguration=helpers.create_member_configuration(
"testmember2", "admin", "Admin12345", False
),
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.create_member(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
InvitationId="id-ABCDEFGHIJKLMNOP0123456789",
MemberConfiguration=helpers.create_member_configuration(
"testmember2", "admin", "Admin12345", False
),
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -451,13 +470,17 @@ def test_create_another_member_badinvitation():
)
network_id = response["NetworkId"]
response = conn.create_member.when.called_with(
NetworkId=network_id,
InvitationId="in-ABCDEFGHIJKLMNOP0123456789",
MemberConfiguration=helpers.create_member_configuration(
"testmember2", "admin", "Admin12345", False
),
).should.throw(Exception, "Invitation in-ABCDEFGHIJKLMNOP0123456789 not valid")
with pytest.raises(ClientError) as ex:
conn.create_member(
NetworkId=network_id,
InvitationId="in-ABCDEFGHIJKLMNOP0123456789",
MemberConfiguration=helpers.create_member_configuration(
"testmember2", "admin", "Admin12345", False
),
)
err = ex.value.response["Error"]
err["Code"].should.equal("InvalidRequestException")
err["Message"].should.contain("Invitation in-ABCDEFGHIJKLMNOP0123456789 not valid")
@mock_managedblockchain
@ -509,73 +532,97 @@ def test_create_another_member_adminpassword():
badadminpassmemberconf["FrameworkConfiguration"]["Fabric"][
"AdminPassword"
] = "badap"
response = conn.create_member.when.called_with(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=badadminpassmemberconf,
).should.throw(
Exception,
"Invalid length for parameter MemberConfiguration.FrameworkConfiguration.Fabric.AdminPassword",
with pytest.raises(ParamValidationError) as ex:
conn.create_member(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=badadminpassmemberconf,
)
err = ex.value
str(err).should.contain(
"Invalid length for parameter MemberConfiguration.FrameworkConfiguration.Fabric.AdminPassword"
)
# No uppercase or numbers
badadminpassmemberconf["FrameworkConfiguration"]["Fabric"][
"AdminPassword"
] = "badadminpwd"
response = conn.create_member.when.called_with(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=badadminpassmemberconf,
).should.throw(Exception, "Invalid request body")
with pytest.raises(ClientError) as ex:
conn.create_member(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=badadminpassmemberconf,
)
err = ex.value.response["Error"]
err["Code"].should.equal("BadRequestException")
err["Message"].should.contain("Invalid request body")
# No lowercase or numbers
badadminpassmemberconf["FrameworkConfiguration"]["Fabric"][
"AdminPassword"
] = "BADADMINPWD"
response = conn.create_member.when.called_with(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=badadminpassmemberconf,
).should.throw(Exception, "Invalid request body")
with pytest.raises(ClientError) as ex:
conn.create_member(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=badadminpassmemberconf,
)
err = ex.value.response["Error"]
err["Code"].should.equal("BadRequestException")
err["Message"].should.contain("Invalid request body")
# No numbers
badadminpassmemberconf["FrameworkConfiguration"]["Fabric"][
"AdminPassword"
] = "badAdminpwd"
response = conn.create_member.when.called_with(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=badadminpassmemberconf,
).should.throw(Exception, "Invalid request body")
with pytest.raises(ClientError) as ex:
conn.create_member(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=badadminpassmemberconf,
)
err = ex.value.response["Error"]
err["Code"].should.equal("BadRequestException")
err["Message"].should.contain("Invalid request body")
# Invalid character
badadminpassmemberconf["FrameworkConfiguration"]["Fabric"][
"AdminPassword"
] = "badAdmin@pwd1"
response = conn.create_member.when.called_with(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=badadminpassmemberconf,
).should.throw(Exception, "Invalid request body")
with pytest.raises(ClientError) as ex:
conn.create_member(
NetworkId=network_id,
InvitationId=invitation_id,
MemberConfiguration=badadminpassmemberconf,
)
err = ex.value.response["Error"]
err["Code"].should.equal("BadRequestException")
err["Message"].should.contain("Invalid request body")
@mock_managedblockchain
def test_list_members_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.list_members.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.list_members(NetworkId="n-ABCDEFGHIJKLMNOP0123456789")
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
def test_get_member_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.get_member.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.get_member(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -593,19 +640,25 @@ def test_get_member_badmember():
)
network_id = response["NetworkId"]
response = conn.get_member.when.called_with(
NetworkId=network_id, MemberId="m-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.get_member(NetworkId=network_id, MemberId="m-ABCDEFGHIJKLMNOP0123456789")
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member m-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
def test_delete_member_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.delete_member.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.delete_member(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -623,22 +676,30 @@ def test_delete_member_badmember():
)
network_id = response["NetworkId"]
response = conn.delete_member.when.called_with(
NetworkId=network_id, MemberId="m-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.delete_member(
NetworkId=network_id, MemberId="m-ABCDEFGHIJKLMNOP0123456789"
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member m-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
def test_update_member_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.update_member.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
LogPublishingConfiguration=helpers.default_memberconfiguration[
"LogPublishingConfiguration"
],
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.update_member(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
LogPublishingConfiguration=helpers.default_memberconfiguration[
"LogPublishingConfiguration"
],
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -656,10 +717,14 @@ def test_update_member_badmember():
)
network_id = response["NetworkId"]
response = conn.update_member.when.called_with(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
LogPublishingConfiguration=helpers.default_memberconfiguration[
"LogPublishingConfiguration"
],
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.update_member(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
LogPublishingConfiguration=helpers.default_memberconfiguration[
"LogPublishingConfiguration"
],
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member m-ABCDEFGHIJKLMNOP0123456789 not found")

View File

@ -1,8 +1,10 @@
from __future__ import unicode_literals
import boto3
import pytest
import sure # noqa
from botocore.exceptions import ClientError
from moto import mock_managedblockchain
from . import helpers
@ -68,31 +70,39 @@ def test_create_network_withopts():
def test_create_network_noframework():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.create_network.when.called_with(
Name="testnetwork1",
Description="Test Network 1",
Framework="HYPERLEDGER_VINYL",
FrameworkVersion="1.2",
FrameworkConfiguration=helpers.default_frameworkconfiguration,
VotingPolicy=helpers.default_votingpolicy,
MemberConfiguration=helpers.default_memberconfiguration,
).should.throw(Exception, "Invalid request body")
with pytest.raises(ClientError) as ex:
conn.create_network(
Name="testnetwork1",
Description="Test Network 1",
Framework="HYPERLEDGER_VINYL",
FrameworkVersion="1.2",
FrameworkConfiguration=helpers.default_frameworkconfiguration,
VotingPolicy=helpers.default_votingpolicy,
MemberConfiguration=helpers.default_memberconfiguration,
)
err = ex.value.response["Error"]
err["Code"].should.equal("BadRequestException")
err["Message"].should.contain("Invalid request body")
@mock_managedblockchain
def test_create_network_badframeworkver():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.create_network.when.called_with(
Name="testnetwork1",
Description="Test Network 1",
Framework="HYPERLEDGER_FABRIC",
FrameworkVersion="1.X",
FrameworkConfiguration=helpers.default_frameworkconfiguration,
VotingPolicy=helpers.default_votingpolicy,
MemberConfiguration=helpers.default_memberconfiguration,
).should.throw(
Exception, "Invalid version 1.X requested for framework HYPERLEDGER_FABRIC"
with pytest.raises(ClientError) as ex:
conn.create_network(
Name="testnetwork1",
Description="Test Network 1",
Framework="HYPERLEDGER_FABRIC",
FrameworkVersion="1.X",
FrameworkConfiguration=helpers.default_frameworkconfiguration,
VotingPolicy=helpers.default_votingpolicy,
MemberConfiguration=helpers.default_memberconfiguration,
)
err = ex.value.response["Error"]
err["Code"].should.equal("BadRequestException")
err["Message"].should.contain(
"Invalid version 1.X requested for framework HYPERLEDGER_FABRIC"
)
@ -102,21 +112,27 @@ def test_create_network_badedition():
frameworkconfiguration = {"Fabric": {"Edition": "SUPER"}}
response = conn.create_network.when.called_with(
Name="testnetwork1",
Description="Test Network 1",
Framework="HYPERLEDGER_FABRIC",
FrameworkVersion="1.2",
FrameworkConfiguration=frameworkconfiguration,
VotingPolicy=helpers.default_votingpolicy,
MemberConfiguration=helpers.default_memberconfiguration,
).should.throw(Exception, "Invalid request body")
with pytest.raises(ClientError) as ex:
conn.create_network(
Name="testnetwork1",
Description="Test Network 1",
Framework="HYPERLEDGER_FABRIC",
FrameworkVersion="1.2",
FrameworkConfiguration=frameworkconfiguration,
VotingPolicy=helpers.default_votingpolicy,
MemberConfiguration=helpers.default_memberconfiguration,
)
err = ex.value.response["Error"]
err["Code"].should.equal("BadRequestException")
err["Message"].should.contain("Invalid request body")
@mock_managedblockchain
def test_get_network_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.get_network.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.get_network(NetworkId="n-ABCDEFGHIJKLMNOP0123456789")
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")

View File

@ -1,8 +1,10 @@
from __future__ import unicode_literals
import boto3
import pytest
import sure # noqa
from botocore.exceptions import ClientError
from moto import mock_managedblockchain
from . import helpers
@ -76,9 +78,11 @@ def test_create_node():
helpers.node_id_exist_in_list(nodes, node_id).should.equal(True)
# But cannot get
response = conn.get_node.when.called_with(
NetworkId=network_id, MemberId=member_id, NodeId=node_id,
).should.throw(Exception, "Node {0} not found".format(node_id))
with pytest.raises(ClientError) as ex:
conn.get_node(NetworkId=network_id, MemberId=member_id, NodeId=node_id)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Node {0} not found".format(node_id))
@mock_managedblockchain
@ -145,9 +149,11 @@ def test_create_node_standard_edition():
conn.delete_member(NetworkId=network_id, MemberId=member_id)
# Should now be an exception
response = conn.list_nodes.when.called_with(
NetworkId=network_id, MemberId=member_id,
).should.throw(Exception, "Member {0} not found".format(member_id))
with pytest.raises(ClientError) as ex:
conn.list_nodes(NetworkId=network_id, MemberId=member_id)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member {0} not found".format(member_id))
@mock_managedblockchain
@ -187,12 +193,16 @@ def test_create_too_many_nodes():
nodes.should.have.length_of(2)
# Try to create one too many nodes
response = conn.create_node.when.called_with(
NetworkId=network_id,
MemberId=member_id,
NodeConfiguration=helpers.default_nodeconfiguration,
).should.throw(
Exception, "Maximum number of nodes exceeded in member {0}".format(member_id),
with pytest.raises(ClientError) as ex:
conn.create_node(
NetworkId=network_id,
MemberId=member_id,
NodeConfiguration=helpers.default_nodeconfiguration,
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceLimitExceededException")
err["Message"].should.contain(
"Maximum number of nodes exceeded in member {0}".format(member_id)
)
@ -200,11 +210,15 @@ def test_create_too_many_nodes():
def test_create_node_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.create_node.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeConfiguration=helpers.default_nodeconfiguration,
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.create_node(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeConfiguration=helpers.default_nodeconfiguration,
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -222,11 +236,15 @@ def test_create_node_badmember():
)
network_id = response["NetworkId"]
response = conn.create_node.when.called_with(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeConfiguration=helpers.default_nodeconfiguration,
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.create_node(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeConfiguration=helpers.default_nodeconfiguration,
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member m-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -248,36 +266,51 @@ def test_create_node_badnodeconfig():
# Incorrect instance type
logconfigbad = dict(helpers.default_nodeconfiguration)
logconfigbad["InstanceType"] = "foo"
response = conn.create_node.when.called_with(
NetworkId=network_id, MemberId=member_id, NodeConfiguration=logconfigbad,
).should.throw(Exception, "Requested instance foo isn't supported.")
with pytest.raises(ClientError) as ex:
conn.create_node(
NetworkId=network_id, MemberId=member_id, NodeConfiguration=logconfigbad
)
err = ex.value.response["Error"]
err["Code"].should.equal("InvalidRequestException")
err["Message"].should.contain("Requested instance foo isn't supported.")
# Incorrect instance type for edition
logconfigbad = dict(helpers.default_nodeconfiguration)
logconfigbad["InstanceType"] = "bc.t3.large"
response = conn.create_node.when.called_with(
NetworkId=network_id, MemberId=member_id, NodeConfiguration=logconfigbad,
).should.throw(
Exception,
"Instance type bc.t3.large is not supported with STARTER Edition networks",
with pytest.raises(ClientError) as ex:
conn.create_node(
NetworkId=network_id, MemberId=member_id, NodeConfiguration=logconfigbad
)
err = ex.value.response["Error"]
err["Code"].should.equal("InvalidRequestException")
err["Message"].should.contain(
"Instance type bc.t3.large is not supported with STARTER Edition networks."
)
# Incorrect availability zone
logconfigbad = dict(helpers.default_nodeconfiguration)
logconfigbad["AvailabilityZone"] = "us-east-11"
response = conn.create_node.when.called_with(
NetworkId=network_id, MemberId=member_id, NodeConfiguration=logconfigbad,
).should.throw(Exception, "Availability Zone is not valid")
with pytest.raises(ClientError) as ex:
conn.create_node(
NetworkId=network_id, MemberId=member_id, NodeConfiguration=logconfigbad
)
err = ex.value.response["Error"]
err["Code"].should.equal("InvalidRequestException")
err["Message"].should.contain("Availability Zone is not valid")
@mock_managedblockchain
def test_list_nodes_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.list_nodes.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.list_nodes(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -295,20 +328,28 @@ def test_list_nodes_badmember():
)
network_id = response["NetworkId"]
response = conn.list_nodes.when.called_with(
NetworkId=network_id, MemberId="m-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.list_nodes(
NetworkId=network_id, MemberId="m-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member m-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
def test_get_node_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.get_node.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.get_node(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -326,11 +367,15 @@ def test_get_node_badmember():
)
network_id = response["NetworkId"]
response = conn.get_node.when.called_with(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.get_node(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member m-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -349,22 +394,30 @@ def test_get_node_badnode():
network_id = response["NetworkId"]
member_id = response["MemberId"]
response = conn.get_node.when.called_with(
NetworkId=network_id,
MemberId=member_id,
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Node nd-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.get_node(
NetworkId=network_id,
MemberId=member_id,
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Node nd-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
def test_delete_node_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.delete_node.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.delete_node(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -382,11 +435,15 @@ def test_delete_node_badmember():
)
network_id = response["NetworkId"]
response = conn.delete_node.when.called_with(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.delete_node(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member m-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -405,25 +462,33 @@ def test_delete_node_badnode():
network_id = response["NetworkId"]
member_id = response["MemberId"]
response = conn.delete_node.when.called_with(
NetworkId=network_id,
MemberId=member_id,
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Node nd-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.delete_node(
NetworkId=network_id,
MemberId=member_id,
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Node nd-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
def test_update_node_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.update_node.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
LogPublishingConfiguration=helpers.default_nodeconfiguration[
"LogPublishingConfiguration"
],
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.update_node(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
LogPublishingConfiguration=helpers.default_nodeconfiguration[
"LogPublishingConfiguration"
],
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -441,14 +506,18 @@ def test_update_node_badmember():
)
network_id = response["NetworkId"]
response = conn.update_node.when.called_with(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
LogPublishingConfiguration=helpers.default_nodeconfiguration[
"LogPublishingConfiguration"
],
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.update_node(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
LogPublishingConfiguration=helpers.default_nodeconfiguration[
"LogPublishingConfiguration"
],
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member m-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -467,11 +536,15 @@ def test_update_node_badnode():
network_id = response["NetworkId"]
member_id = response["MemberId"]
response = conn.update_node.when.called_with(
NetworkId=network_id,
MemberId=member_id,
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
LogPublishingConfiguration=helpers.default_nodeconfiguration[
"LogPublishingConfiguration"
],
).should.throw(Exception, "Node nd-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.update_node(
NetworkId=network_id,
MemberId=member_id,
NodeId="nd-ABCDEFGHIJKLMNOP0123456789",
LogPublishingConfiguration=helpers.default_nodeconfiguration[
"LogPublishingConfiguration"
],
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Node nd-ABCDEFGHIJKLMNOP0123456789 not found")

View File

@ -1,8 +1,10 @@
from __future__ import unicode_literals
import boto3
import pytest
import sure # noqa
from botocore.exceptions import ClientError
from moto import mock_managedblockchain
from . import helpers
@ -82,11 +84,15 @@ def test_create_proposal_withopts():
def test_create_proposal_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.create_proposal.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
Actions=helpers.default_policy_actions,
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.create_proposal(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
Actions=helpers.default_policy_actions,
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -104,11 +110,15 @@ def test_create_proposal_badmember():
)
network_id = response["NetworkId"]
response = conn.create_proposal.when.called_with(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
Actions=helpers.default_policy_actions,
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.create_proposal(
NetworkId=network_id,
MemberId="m-ABCDEFGHIJKLMNOP0123456789",
Actions=helpers.default_policy_actions,
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member m-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -130,9 +140,15 @@ def test_create_proposal_badinvitationacctid():
network_id = response["NetworkId"]
member_id = response["MemberId"]
response = conn.create_proposal.when.called_with(
NetworkId=network_id, MemberId=member_id, Actions=actions,
).should.throw(Exception, "Account ID format specified in proposal is not valid")
with pytest.raises(ClientError) as ex:
conn.create_proposal(
NetworkId=network_id, MemberId=member_id, Actions=actions,
)
err = ex.value.response["Error"]
err["Code"].should.equal("InvalidRequestException")
err["Message"].should.contain(
"Account ID format specified in proposal is not valid"
)
@mock_managedblockchain
@ -154,28 +170,38 @@ def test_create_proposal_badremovalmemid():
network_id = response["NetworkId"]
member_id = response["MemberId"]
response = conn.create_proposal.when.called_with(
NetworkId=network_id, MemberId=member_id, Actions=actions,
).should.throw(Exception, "Member ID format specified in proposal is not valid")
with pytest.raises(ClientError) as ex:
conn.create_proposal(
NetworkId=network_id, MemberId=member_id, Actions=actions,
)
err = ex.value.response["Error"]
err["Code"].should.equal("InvalidRequestException")
err["Message"].should.contain("Member ID format specified in proposal is not valid")
@mock_managedblockchain
def test_list_proposal_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.list_proposals.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.list_proposals(NetworkId="n-ABCDEFGHIJKLMNOP0123456789",)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
def test_get_proposal_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.get_proposal.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.get_proposal(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -193,6 +219,10 @@ def test_get_proposal_badproposal():
)
network_id = response["NetworkId"]
response = conn.get_proposal.when.called_with(
NetworkId=network_id, ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Proposal p-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.get_proposal(
NetworkId=network_id, ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Proposal p-ABCDEFGHIJKLMNOP0123456789 not found")

View File

@ -3,7 +3,9 @@ from __future__ import unicode_literals
import os
import boto3
import pytest
import sure # noqa
from botocore.exceptions import ClientError
from freezegun import freeze_time
from unittest import SkipTest
@ -321,14 +323,17 @@ def test_vote_on_proposal_expiredproposal():
with freeze_time("2015-02-01 12:00:00"):
# Vote yes - should set status to expired
response = conn.vote_on_proposal.when.called_with(
NetworkId=network_id,
ProposalId=proposal_id,
VoterMemberId=member_id,
Vote="YES",
).should.throw(
Exception,
"Proposal {0} is expired and you cannot vote on it.".format(proposal_id),
with pytest.raises(ClientError) as ex:
conn.vote_on_proposal(
NetworkId=network_id,
ProposalId=proposal_id,
VoterMemberId=member_id,
Vote="YES",
)
err = ex.value.response["Error"]
err["Code"].should.equal("InvalidRequestException")
err["Message"].should.contain(
"Proposal {0} is expired and you cannot vote on it.".format(proposal_id)
)
# Get proposal details - should be EXPIRED
@ -438,12 +443,16 @@ def test_vote_on_proposal_status_check():
pendinginvs.should.have.length_of(1)
# Vote with member 3 - should throw an exception and not create a new invitation
response = conn.vote_on_proposal.when.called_with(
NetworkId=network_id,
ProposalId=proposal_id,
VoterMemberId=memberidlist[2],
Vote="YES",
).should.throw(Exception, "and you cannot vote on it")
with pytest.raises(ClientError) as ex:
conn.vote_on_proposal(
NetworkId=network_id,
ProposalId=proposal_id,
VoterMemberId=memberidlist[2],
Vote="YES",
)
err = ex.value.response["Error"]
err["Code"].should.equal("InvalidRequestException")
err["Message"].should.contain("and you cannot vote on it")
# Should still be one pending invitation
response = conn.list_invitations()
@ -457,12 +466,16 @@ def test_vote_on_proposal_status_check():
def test_vote_on_proposal_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.vote_on_proposal.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789",
Vote="YES",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.vote_on_proposal(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789",
Vote="YES",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -480,12 +493,16 @@ def test_vote_on_proposal_badproposal():
)
network_id = response["NetworkId"]
response = conn.vote_on_proposal.when.called_with(
NetworkId=network_id,
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789",
Vote="YES",
).should.throw(Exception, "Proposal p-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.vote_on_proposal(
NetworkId=network_id,
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789",
Vote="YES",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Proposal p-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -512,12 +529,16 @@ def test_vote_on_proposal_badmember():
proposal_id = response["ProposalId"]
response = conn.vote_on_proposal.when.called_with(
NetworkId=network_id,
ProposalId=proposal_id,
VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789",
Vote="YES",
).should.throw(Exception, "Member m-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.vote_on_proposal(
NetworkId=network_id,
ProposalId=proposal_id,
VoterMemberId="m-ABCDEFGHIJKLMNOP0123456789",
Vote="YES",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Member m-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -544,12 +565,16 @@ def test_vote_on_proposal_badvote():
proposal_id = response["ProposalId"]
response = conn.vote_on_proposal.when.called_with(
NetworkId=network_id,
ProposalId=proposal_id,
VoterMemberId=member_id,
Vote="FOO",
).should.throw(Exception, "Invalid request body")
with pytest.raises(ClientError) as ex:
conn.vote_on_proposal(
NetworkId=network_id,
ProposalId=proposal_id,
VoterMemberId=member_id,
Vote="FOO",
)
err = ex.value.response["Error"]
err["Code"].should.equal("BadRequestException")
err["Message"].should.contain("Invalid request body")
@mock_managedblockchain
@ -628,14 +653,17 @@ def test_vote_on_proposal_alreadyvoted():
)
# Vote yes with member 1 again
response = conn.vote_on_proposal.when.called_with(
NetworkId=network_id,
ProposalId=proposal_id,
VoterMemberId=member_id,
Vote="YES",
).should.throw(
Exception,
"Member {0} has already voted on proposal {1}.".format(member_id, proposal_id),
with pytest.raises(ClientError) as ex:
conn.vote_on_proposal(
NetworkId=network_id,
ProposalId=proposal_id,
VoterMemberId=member_id,
Vote="YES",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceAlreadyExistsException")
err["Message"].should.contain(
"Member {0} has already voted on proposal {1}.".format(member_id, proposal_id)
)
@ -643,10 +671,14 @@ def test_vote_on_proposal_alreadyvoted():
def test_list_proposal_votes_badnetwork():
conn = boto3.client("managedblockchain", region_name="us-east-1")
response = conn.list_proposal_votes.when.called_with(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Network n-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.list_proposal_votes(
NetworkId="n-ABCDEFGHIJKLMNOP0123456789",
ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Network n-ABCDEFGHIJKLMNOP0123456789 not found")
@mock_managedblockchain
@ -665,6 +697,10 @@ def test_list_proposal_votes_badproposal():
network_id = response["NetworkId"]
member_id = response["MemberId"]
response = conn.list_proposal_votes.when.called_with(
NetworkId=network_id, ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
).should.throw(Exception, "Proposal p-ABCDEFGHIJKLMNOP0123456789 not found")
with pytest.raises(ClientError) as ex:
conn.list_proposal_votes(
NetworkId=network_id, ProposalId="p-ABCDEFGHIJKLMNOP0123456789",
)
err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException")
err["Message"].should.contain("Proposal p-ABCDEFGHIJKLMNOP0123456789 not found")