Added get network test

This commit is contained in:
James Belleau 2020-05-06 21:54:59 -05:00
parent 5ec814a604
commit 811ec3bd2a
3 changed files with 25 additions and 1 deletions

View File

@ -14,3 +14,14 @@ class BadRequestException(ManagedBlockchainClientError):
pretty_called_method, operation_error
),
)
class ResourceNotFoundException(ManagedBlockchainClientError):
def __init__(self, pretty_called_method, operation_error):
self.code = 404
super(ResourceNotFoundException, self).__init__(
"ResourceNotFoundException",
"An error occurred (BadRequestException) when calling the {0} operation: {1}".format(
pretty_called_method, operation_error
),
)

View File

@ -6,7 +6,7 @@ from boto3 import Session
from moto.core import BaseBackend, BaseModel
from .exceptions import BadRequestException
from .exceptions import BadRequestException, ResourceNotFoundException
from .utils import get_network_id, get_member_id
@ -164,6 +164,10 @@ class ManagedBlockchainBackend(BaseBackend):
return self.networks.values()
def get_network(self, network_id):
if network_id not in self.networks:
raise ResourceNotFoundException(
"CreateNetwork", "Network {0} not found".format(network_id)
)
return self.networks.get(network_id)

View File

@ -131,3 +131,12 @@ def test_create_network_badedition():
VotingPolicy=default_votingpolicy,
MemberConfiguration=default_memberconfiguration,
).should.throw(Exception, "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-BADNETWORK",
).should.throw(Exception, "Network n-BADNETWORK not found")