Port test suite from nose to pytest.
This just eliminates all errors on the tests collection. Elimination of failures is left to the next commit.
This commit is contained in:
parent
47dbad291e
commit
77dc60ea97
@ -1,4 +1,4 @@
|
||||
nose
|
||||
pytest
|
||||
sure==1.4.11
|
||||
freezegun
|
||||
parameterized>=0.7.0
|
@ -1,8 +1,2 @@
|
||||
[nosetests]
|
||||
verbosity=1
|
||||
detailed-errors=1
|
||||
with-coverage=1
|
||||
cover-package=moto
|
||||
|
||||
[bdist_wheel]
|
||||
universal=1
|
||||
|
@ -6,4 +6,3 @@ import logging
|
||||
logging.getLogger("boto").setLevel(logging.CRITICAL)
|
||||
logging.getLogger("boto3").setLevel(logging.CRITICAL)
|
||||
logging.getLogger("botocore").setLevel(logging.CRITICAL)
|
||||
logging.getLogger("nose").setLevel(logging.CRITICAL)
|
||||
|
@ -1,41 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
"""
|
||||
Patch courtesy of:
|
||||
https://marmida.com/blog/index.php/2012/08/08/monkey-patching-assert_raises/
|
||||
"""
|
||||
|
||||
# code for monkey-patching
|
||||
import nose.tools
|
||||
|
||||
# let's fix nose.tools.assert_raises (which is really unittest.assertRaises)
|
||||
# so that it always supports context management
|
||||
|
||||
# in order for these changes to be available to other modules, you'll need
|
||||
# to guarantee this module is imported by your fixture before either nose or
|
||||
# unittest are imported
|
||||
|
||||
try:
|
||||
nose.tools.assert_raises(Exception)
|
||||
except TypeError:
|
||||
# this version of assert_raises doesn't support the 1-arg version
|
||||
class AssertRaisesContext(object):
|
||||
def __init__(self, expected):
|
||||
self.expected = expected
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, tb):
|
||||
self.exception = exc_val
|
||||
if issubclass(exc_type, self.expected):
|
||||
return True
|
||||
nose.tools.assert_equal(exc_type, self.expected)
|
||||
# if you get to this line, the last assertion must have passed
|
||||
# suppress the propagation of this exception
|
||||
return True
|
||||
|
||||
def assert_raises_context(exc_type):
|
||||
return AssertRaisesContext(exc_type)
|
||||
|
||||
nose.tools.assert_raises = assert_raises_context
|
@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
import boto
|
||||
from nose.plugins.skip import SkipTest
|
||||
from unittest import SkipTest
|
||||
import six
|
||||
|
||||
|
||||
|
1
tests/test_acm/__init__.py
Normal file
1
tests/test_acm/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
1
tests/test_acm/resources/__init__.py
Normal file
1
tests/test_acm/resources/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
1
tests/test_apigateway/__init__.py
Normal file
1
tests/test_apigateway/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -11,7 +11,7 @@ from botocore.exceptions import ClientError
|
||||
import responses
|
||||
from moto import mock_apigateway, mock_cognitoidp, settings
|
||||
from moto.core import ACCOUNT_ID
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
|
||||
@freeze_time("2015-01-01")
|
||||
@ -90,7 +90,7 @@ def test_create_rest_api_with_policy():
|
||||
def test_create_rest_api_invalid_apikeysource():
|
||||
client = boto3.client("apigateway", region_name="us-west-2")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_rest_api(
|
||||
name="my_api",
|
||||
description="this is my api",
|
||||
@ -126,7 +126,7 @@ def test_create_rest_api_valid_apikeysources():
|
||||
def test_create_rest_api_invalid_endpointconfiguration():
|
||||
client = boto3.client("apigateway", region_name="us-west-2")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_rest_api(
|
||||
name="my_api",
|
||||
description="this is my api",
|
||||
@ -194,7 +194,7 @@ def test_create_resource__validate_name():
|
||||
valid_names = ["users", "{user_id}", "{proxy+}", "user_09", "good-dog"]
|
||||
# All invalid names should throw an exception
|
||||
for name in invalid_names:
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_resource(restApiId=api_id, parentId=root_id, pathPart=name)
|
||||
ex.exception.response["Error"]["Code"].should.equal("BadRequestException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -1194,7 +1194,7 @@ def test_create_deployment_requires_REST_methods():
|
||||
response = client.create_rest_api(name="my_api", description="this is my api")
|
||||
api_id = response["id"]
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_deployment(restApiId=api_id, stageName=stage_name)["id"]
|
||||
ex.exception.response["Error"]["Code"].should.equal("BadRequestException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -1217,7 +1217,7 @@ def test_create_deployment_requires_REST_method_integrations():
|
||||
restApiId=api_id, resourceId=root_id, httpMethod="GET", authorizationType="NONE"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_deployment(restApiId=api_id, stageName=stage_name)["id"]
|
||||
ex.exception.response["Error"]["Code"].should.equal("BadRequestException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -1273,7 +1273,7 @@ def test_put_integration_response_requires_responseTemplate():
|
||||
integrationHttpMethod="POST",
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_integration_response(
|
||||
restApiId=api_id, resourceId=root_id, httpMethod="GET", statusCode="200"
|
||||
)
|
||||
@ -1314,7 +1314,7 @@ def test_put_integration_response_with_response_template():
|
||||
integrationHttpMethod="POST",
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_integration_response(
|
||||
restApiId=api_id, resourceId=root_id, httpMethod="GET", statusCode="200"
|
||||
)
|
||||
@ -1372,7 +1372,7 @@ def test_put_integration_validation():
|
||||
|
||||
for type in types_requiring_integration_method:
|
||||
# Ensure that integrations of these types fail if no integrationHttpMethod is provided
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_integration(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
@ -1428,7 +1428,7 @@ def test_put_integration_validation():
|
||||
)
|
||||
for type in ["AWS_PROXY"]:
|
||||
# Ensure that aws_proxy does not support S3
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_integration(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
@ -1446,7 +1446,7 @@ def test_put_integration_validation():
|
||||
)
|
||||
for type in aws_types:
|
||||
# Ensure that the Role ARN is for the current account
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_integration(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
@ -1462,7 +1462,7 @@ def test_put_integration_validation():
|
||||
)
|
||||
for type in ["AWS"]:
|
||||
# Ensure that the Role ARN is specified for aws integrations
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_integration(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
@ -1477,7 +1477,7 @@ def test_put_integration_validation():
|
||||
)
|
||||
for type in http_types:
|
||||
# Ensure that the URI is valid HTTP
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_integration(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
@ -1492,7 +1492,7 @@ def test_put_integration_validation():
|
||||
)
|
||||
for type in aws_types:
|
||||
# Ensure that the URI is an ARN
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_integration(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
@ -1507,7 +1507,7 @@ def test_put_integration_validation():
|
||||
)
|
||||
for type in aws_types:
|
||||
# Ensure that the URI is a valid ARN
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_integration(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
@ -1632,7 +1632,7 @@ def test_create_domain_names():
|
||||
response["domainName"].should.equal(domain_name)
|
||||
response["certificateName"].should.equal(test_certificate_name)
|
||||
# without domain name it should throw BadRequestException
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_domain_name(domainName="")
|
||||
|
||||
ex.exception.response["Error"]["Message"].should.equal("No Domain Name specified")
|
||||
@ -1666,7 +1666,7 @@ def test_get_domain_name():
|
||||
client = boto3.client("apigateway", region_name="us-west-2")
|
||||
domain_name = "testDomain"
|
||||
# quering an invalid domain name which is not present
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_domain_name(domainName=domain_name)
|
||||
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -1701,7 +1701,7 @@ def test_create_model():
|
||||
response["description"].should.equal(description)
|
||||
|
||||
# with an invalid rest_api_id it should throw NotFoundException
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_model(
|
||||
restApiId=dummy_rest_api_id,
|
||||
name=model_name,
|
||||
@ -1713,7 +1713,7 @@ def test_create_model():
|
||||
)
|
||||
ex.exception.response["Error"]["Code"].should.equal("NotFoundException")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_model(
|
||||
restApiId=rest_api_id,
|
||||
name="",
|
||||
@ -1770,7 +1770,7 @@ def test_get_model_by_name():
|
||||
result["name"] = model_name
|
||||
result["description"] = description
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_model(restApiId=dummy_rest_api_id, modelName=model_name)
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"Invalid Rest API Id specified"
|
||||
@ -1784,7 +1784,7 @@ def test_get_model_with_invalid_name():
|
||||
response = client.create_rest_api(name="my_api", description="this is my api")
|
||||
rest_api_id = response["id"]
|
||||
# test with an invalid model name
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_model(restApiId=rest_api_id, modelName="fake")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"Invalid Model Name specified"
|
||||
@ -1868,7 +1868,7 @@ def test_create_api_headers():
|
||||
payload = {"value": apikey_value, "name": apikey_name}
|
||||
|
||||
client.create_api_key(**payload)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_api_key(**payload)
|
||||
ex.exception.response["Error"]["Code"].should.equal("ConflictException")
|
||||
if not settings.TEST_SERVER_MODE:
|
||||
@ -1939,7 +1939,7 @@ def test_usage_plans():
|
||||
len(response["items"]).should.equal(0)
|
||||
|
||||
# # Try to get info about a non existing usage
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_usage_plan(usagePlanId="not_existing")
|
||||
ex.exception.response["Error"]["Code"].should.equal("NotFoundException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -2030,7 +2030,7 @@ def test_usage_plan_keys():
|
||||
len(response["items"]).should.equal(0)
|
||||
|
||||
# Try to get info about a non existing api key
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_usage_plan_key(usagePlanId=usage_plan_id, keyId="not_existing_key")
|
||||
ex.exception.response["Error"]["Code"].should.equal("NotFoundException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -2038,7 +2038,7 @@ def test_usage_plan_keys():
|
||||
)
|
||||
|
||||
# Try to get info about an existing api key that has not jet added to a valid usage plan
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_usage_plan_key(usagePlanId=usage_plan_id, keyId=key_id)
|
||||
ex.exception.response["Error"]["Code"].should.equal("NotFoundException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -2046,7 +2046,7 @@ def test_usage_plan_keys():
|
||||
)
|
||||
|
||||
# Try to get info about an existing api key that has not jet added to a valid usage plan
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_usage_plan_key(usagePlanId="not_existing_plan_id", keyId=key_id)
|
||||
ex.exception.response["Error"]["Code"].should.equal("NotFoundException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
|
@ -1,10 +1,10 @@
|
||||
from __future__ import unicode_literals
|
||||
import botocore
|
||||
|
||||
import boto3
|
||||
import botocore
|
||||
import pytest
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
from moto import mock_applicationautoscaling, mock_ecs
|
||||
from moto.applicationautoscaling.exceptions import AWSValidationException
|
||||
|
||||
DEFAULT_REGION = "us-east-1"
|
||||
DEFAULT_ECS_CLUSTER = "default"
|
||||
@ -334,7 +334,7 @@ def test_put_scaling_policy():
|
||||
},
|
||||
}
|
||||
|
||||
with assert_raises(client.exceptions.ValidationException) as e:
|
||||
with pytest.raises(client.exceptions.ValidationException) as e:
|
||||
client.put_scaling_policy(
|
||||
PolicyName=policy_name,
|
||||
ServiceNamespace=namespace,
|
||||
@ -443,7 +443,7 @@ def test_delete_scaling_policies():
|
||||
},
|
||||
}
|
||||
|
||||
with assert_raises(client.exceptions.ValidationException) as e:
|
||||
with pytest.raises(client.exceptions.ValidationException) as e:
|
||||
client.delete_scaling_policy(
|
||||
PolicyName=policy_name,
|
||||
ServiceNamespace=namespace,
|
||||
@ -507,7 +507,7 @@ def test_deregister_scalable_target():
|
||||
response = client.describe_scalable_targets(ServiceNamespace=namespace)
|
||||
len(response["ScalableTargets"]).should.equal(0)
|
||||
|
||||
with assert_raises(client.exceptions.ValidationException) as e:
|
||||
with pytest.raises(client.exceptions.ValidationException) as e:
|
||||
client.deregister_scalable_target(
|
||||
ServiceNamespace=namespace,
|
||||
ResourceId=resource_id,
|
||||
|
@ -4,7 +4,7 @@ from moto import mock_applicationautoscaling, mock_ecs
|
||||
from moto.applicationautoscaling import models
|
||||
from moto.applicationautoscaling.exceptions import AWSValidationException
|
||||
from botocore.exceptions import ParamValidationError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
import sure # noqa
|
||||
from botocore.exceptions import ClientError
|
||||
from parameterized import parameterized
|
||||
@ -25,21 +25,21 @@ DEFAULT_ROLE_ARN = "test:arn"
|
||||
@mock_applicationautoscaling
|
||||
def test_describe_scalable_targets_no_params_should_raise_param_validation_errors():
|
||||
client = boto3.client("application-autoscaling", region_name=DEFAULT_REGION)
|
||||
with assert_raises(ParamValidationError):
|
||||
with pytest.raises(ParamValidationError):
|
||||
client.describe_scalable_targets()
|
||||
|
||||
|
||||
@mock_applicationautoscaling
|
||||
def test_register_scalable_target_no_params_should_raise_param_validation_errors():
|
||||
client = boto3.client("application-autoscaling", region_name=DEFAULT_REGION)
|
||||
with assert_raises(ParamValidationError):
|
||||
with pytest.raises(ParamValidationError):
|
||||
client.register_scalable_target()
|
||||
|
||||
|
||||
@mock_applicationautoscaling
|
||||
def test_register_scalable_target_with_none_service_namespace_should_raise_param_validation_errors():
|
||||
client = boto3.client("application-autoscaling", region_name=DEFAULT_REGION)
|
||||
with assert_raises(ParamValidationError):
|
||||
with pytest.raises(ParamValidationError):
|
||||
register_scalable_target(client, ServiceNamespace=None)
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ def test_register_scalable_target_with_none_service_namespace_should_raise_param
|
||||
def test_describe_scalable_targets_with_invalid_scalable_dimension_should_return_validation_exception():
|
||||
client = boto3.client("application-autoscaling", region_name=DEFAULT_REGION)
|
||||
|
||||
with assert_raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as err:
|
||||
response = client.describe_scalable_targets(
|
||||
ServiceNamespace=DEFAULT_SERVICE_NAMESPACE, ScalableDimension="foo",
|
||||
)
|
||||
@ -62,7 +62,7 @@ def test_describe_scalable_targets_with_invalid_scalable_dimension_should_return
|
||||
def test_describe_scalable_targets_with_invalid_service_namespace_should_return_validation_exception():
|
||||
client = boto3.client("application-autoscaling", region_name=DEFAULT_REGION)
|
||||
|
||||
with assert_raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as err:
|
||||
response = client.describe_scalable_targets(
|
||||
ServiceNamespace="foo", ScalableDimension=DEFAULT_SCALABLE_DIMENSION,
|
||||
)
|
||||
@ -77,7 +77,7 @@ def test_describe_scalable_targets_with_invalid_service_namespace_should_return_
|
||||
def test_describe_scalable_targets_with_multiple_invalid_parameters_should_return_validation_exception():
|
||||
client = boto3.client("application-autoscaling", region_name=DEFAULT_REGION)
|
||||
|
||||
with assert_raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as err:
|
||||
response = client.describe_scalable_targets(
|
||||
ServiceNamespace="foo", ScalableDimension="bar",
|
||||
)
|
||||
@ -94,7 +94,7 @@ def test_register_scalable_target_ecs_with_non_existent_service_should_return_va
|
||||
client = boto3.client("application-autoscaling", region_name=DEFAULT_REGION)
|
||||
resource_id = "service/{}/foo".format(DEFAULT_ECS_CLUSTER)
|
||||
|
||||
with assert_raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as err:
|
||||
register_scalable_target(client, ServiceNamespace="ecs", ResourceId=resource_id)
|
||||
err.response["Error"]["Code"].should.equal("ValidationException")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
@ -116,7 +116,7 @@ def test_target_params_are_valid_success(namespace, r_id, dimension, expected):
|
||||
expected
|
||||
)
|
||||
else:
|
||||
with assert_raises(AWSValidationException):
|
||||
with pytest.raises(AWSValidationException):
|
||||
models._target_params_are_valid(namespace, r_id, dimension)
|
||||
|
||||
|
||||
|
1
tests/test_athena/__init__.py
Normal file
1
tests/test_athena/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -1,7 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
import boto3
|
||||
import sure # noqa
|
||||
|
||||
@ -104,7 +104,7 @@ def test_start_query_execution():
|
||||
def test_start_query_validate_workgroup():
|
||||
client = boto3.client("athena", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as err:
|
||||
client.start_query_execution(
|
||||
QueryString="query1",
|
||||
QueryExecutionContext={"Database": "string"},
|
||||
|
1
tests/test_autoscaling/__init__.py
Normal file
1
tests/test_autoscaling/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -8,7 +8,7 @@ from boto.ec2.autoscale import Tag
|
||||
import boto.ec2.elb
|
||||
import sure # noqa
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import (
|
||||
mock_autoscaling,
|
||||
@ -21,7 +21,7 @@ from moto import (
|
||||
)
|
||||
from tests.helpers import requires_boto_gte
|
||||
|
||||
from utils import (
|
||||
from .utils import (
|
||||
setup_networking,
|
||||
setup_networking_deprecated,
|
||||
setup_instance_with_networking,
|
||||
@ -781,7 +781,7 @@ def test_create_autoscaling_group_from_invalid_instance_id():
|
||||
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceId=invalid_instance_id,
|
||||
|
@ -7,7 +7,7 @@ from moto import (
|
||||
mock_ec2,
|
||||
)
|
||||
|
||||
from utils import setup_networking
|
||||
from .utils import setup_networking
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
|
@ -4,7 +4,7 @@ import boto3
|
||||
import sure # noqa
|
||||
from moto import mock_autoscaling, mock_ec2, mock_elbv2
|
||||
|
||||
from utils import setup_networking
|
||||
from .utils import setup_networking
|
||||
|
||||
|
||||
@mock_elbv2
|
||||
|
@ -7,7 +7,7 @@ import sure # noqa
|
||||
|
||||
from moto import mock_autoscaling_deprecated
|
||||
|
||||
from utils import setup_networking_deprecated
|
||||
from .utils import setup_networking_deprecated
|
||||
|
||||
|
||||
def setup_autoscale_group():
|
||||
|
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -4,7 +4,7 @@ import sure # noqa
|
||||
import zipfile
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_cloudformation, mock_iam, mock_lambda, mock_s3, mock_sqs
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from string import Template
|
||||
from uuid import uuid4
|
||||
|
||||
@ -109,7 +109,7 @@ def test_lambda_can_be_deleted_by_cloudformation():
|
||||
# Delete Stack
|
||||
cf.delete_stack(StackName=stack["StackId"])
|
||||
# Verify function was deleted
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
lmbda.get_function(FunctionName=created_fn_name)
|
||||
e.exception.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
||||
|
||||
|
@ -24,7 +24,7 @@ from moto import (
|
||||
mock_sqs,
|
||||
)
|
||||
from moto.sts.models import ACCOUNT_ID
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
_lambda_region = "us-west-2"
|
||||
@ -497,7 +497,7 @@ def test_get_function():
|
||||
)
|
||||
|
||||
# Test get function when can't find function name
|
||||
with assert_raises(conn.exceptions.ResourceNotFoundException):
|
||||
with pytest.raises(conn.exceptions.ResourceNotFoundException):
|
||||
conn.get_function(FunctionName="junk", Qualifier="$LATEST")
|
||||
|
||||
|
||||
@ -1800,7 +1800,7 @@ def test_get_function_concurrency():
|
||||
def create_invalid_lambda(role):
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
zip_content = get_test_zip_file1()
|
||||
with assert_raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as err:
|
||||
conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python2.7",
|
||||
|
1
tests/test_batch/__init__.py
Normal file
1
tests/test_batch/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -7,10 +7,6 @@ from botocore.exceptions import ClientError
|
||||
import sure # noqa
|
||||
from moto import mock_batch, mock_iam, mock_ec2, mock_ecs, mock_logs
|
||||
|
||||
import functools
|
||||
import nose
|
||||
|
||||
|
||||
DEFAULT_REGION = "eu-central-1"
|
||||
|
||||
|
||||
|
@ -14,7 +14,6 @@ from moto import (
|
||||
mock_cloudformation,
|
||||
)
|
||||
import functools
|
||||
import nose
|
||||
import json
|
||||
|
||||
DEFAULT_REGION = "eu-central-1"
|
||||
|
@ -12,9 +12,7 @@ import boto.cloudformation
|
||||
from boto.exception import BotoServerError
|
||||
import sure # noqa
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from moto.core import ACCOUNT_ID
|
||||
|
||||
from moto import (
|
||||
@ -319,7 +317,7 @@ def test_delete_stack_by_id():
|
||||
conn.describe_stacks().should.have.length_of(1)
|
||||
conn.delete_stack(stack_id)
|
||||
conn.describe_stacks().should.have.length_of(0)
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.describe_stacks("test_stack")
|
||||
|
||||
conn.describe_stacks(stack_id).should.have.length_of(1)
|
||||
@ -338,7 +336,7 @@ def test_delete_stack_with_resource_missing_delete_attr():
|
||||
@mock_cloudformation_deprecated
|
||||
def test_bad_describe_stack():
|
||||
conn = boto.connect_cloudformation()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.describe_stacks("bad_stack")
|
||||
|
||||
|
||||
@ -519,7 +517,7 @@ def test_update_stack_when_rolled_back():
|
||||
stack_id
|
||||
].status = "ROLLBACK_COMPLETE"
|
||||
|
||||
with assert_raises(BotoServerError) as err:
|
||||
with pytest.raises(BotoServerError) as err:
|
||||
conn.update_stack("test_stack", dummy_template_json)
|
||||
|
||||
ex = err.exception
|
||||
|
@ -9,8 +9,7 @@ import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import sure # noqa
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_cloudformation, mock_s3, mock_sqs, mock_ec2
|
||||
from moto.core import ACCOUNT_ID
|
||||
@ -548,7 +547,7 @@ def test_boto3_list_stack_set_operations():
|
||||
@mock_cloudformation
|
||||
def test_boto3_bad_list_stack_resources():
|
||||
cf_conn = boto3.client("cloudformation", region_name="us-east-1")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
cf_conn.list_stack_resources(StackName="test_stack_set")
|
||||
|
||||
|
||||
@ -1180,7 +1179,7 @@ def test_describe_updated_stack():
|
||||
@mock_cloudformation
|
||||
def test_bad_describe_stack():
|
||||
cf_conn = boto3.client("cloudformation", region_name="us-east-1")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
cf_conn.describe_stacks(StackName="non_existent_stack")
|
||||
|
||||
|
||||
@ -1332,7 +1331,7 @@ def test_delete_stack_with_export():
|
||||
def test_export_names_must_be_unique():
|
||||
cf = boto3.resource("cloudformation", region_name="us-east-1")
|
||||
cf.create_stack(StackName="test_stack", TemplateBody=dummy_output_template_json)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
cf.create_stack(StackName="test_stack", TemplateBody=dummy_output_template_json)
|
||||
|
||||
|
||||
@ -1373,7 +1372,7 @@ def test_boto3_create_duplicate_stack():
|
||||
StackName="test_stack", TemplateBody=dummy_template_json,
|
||||
)
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
cf_conn.create_stack(
|
||||
StackName="test_stack", TemplateBody=dummy_template_json,
|
||||
)
|
||||
|
@ -3,7 +3,6 @@ import json
|
||||
import yaml
|
||||
import os
|
||||
import boto3
|
||||
from nose.tools import raises
|
||||
import botocore
|
||||
import sure # noqa
|
||||
|
||||
|
1
tests/test_cloudwatch/__init__.py
Normal file
1
tests/test_cloudwatch/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -4,7 +4,7 @@ import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
from datetime import datetime, timedelta
|
||||
from freezegun import freeze_time
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from uuid import uuid4
|
||||
import pytz
|
||||
import sure # noqa
|
||||
@ -111,7 +111,7 @@ def test_delete_invalid_alarm():
|
||||
)
|
||||
|
||||
# trying to delete an alarm which is not created along with valid alarm.
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
cloudwatch.delete_alarms(AlarmNames=["InvalidAlarmName", "testalarm1"])
|
||||
e.exception.response["Error"]["Code"].should.equal("ResourceNotFound")
|
||||
|
||||
@ -120,7 +120,7 @@ def test_delete_invalid_alarm():
|
||||
len(resp["MetricAlarms"]).should.equal(1)
|
||||
|
||||
# test to check if the error raises if only one invalid alarm is tried to delete.
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
cloudwatch.delete_alarms(AlarmNames=["InvalidAlarmName"])
|
||||
e.exception.response["Error"]["Code"].should.equal("ResourceNotFound")
|
||||
|
||||
@ -423,7 +423,7 @@ def test_list_metrics_paginated():
|
||||
# Verify that only a single page of metrics is returned
|
||||
cloudwatch.list_metrics()["Metrics"].should.be.empty
|
||||
# Verify we can't pass a random NextToken
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
cloudwatch.list_metrics(NextToken=str(uuid4()))
|
||||
e.exception.response["Error"]["Message"].should.equal(
|
||||
"Request parameter NextToken is invalid"
|
||||
@ -452,7 +452,7 @@ def test_list_metrics_paginated():
|
||||
len(third_page["Metrics"]).should.equal(100)
|
||||
third_page.shouldnt.contain("NextToken")
|
||||
# Verify that we can't reuse an existing token
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
cloudwatch.list_metrics(NextToken=first_page["NextToken"])
|
||||
e.exception.response["Error"]["Message"].should.equal(
|
||||
"Request parameter NextToken is invalid"
|
||||
|
@ -4,7 +4,7 @@ import sure # noqa
|
||||
from moto import mock_codecommit
|
||||
from moto.core import ACCOUNT_ID
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
|
||||
@mock_codecommit
|
||||
@ -81,7 +81,7 @@ def test_create_repository_repository_name_exists():
|
||||
|
||||
client.create_repository(repositoryName="repository_two")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.create_repository(
|
||||
repositoryName="repository_two",
|
||||
repositoryDescription="description repo two",
|
||||
@ -99,7 +99,7 @@ def test_create_repository_repository_name_exists():
|
||||
def test_create_repository_invalid_repository_name():
|
||||
client = boto3.client("codecommit", region_name="eu-central-1")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.create_repository(repositoryName="in_123_valid_@#$_characters")
|
||||
ex = e.exception
|
||||
ex.operation_name.should.equal("CreateRepository")
|
||||
@ -156,7 +156,7 @@ def test_get_repository():
|
||||
|
||||
client = boto3.client("codecommit", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.get_repository(repositoryName=repository_name)
|
||||
ex = e.exception
|
||||
ex.operation_name.should.equal("GetRepository")
|
||||
@ -171,7 +171,7 @@ def test_get_repository():
|
||||
def test_get_repository_invalid_repository_name():
|
||||
client = boto3.client("codecommit", region_name="eu-central-1")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.get_repository(repositoryName="repository_one-@#@")
|
||||
ex = e.exception
|
||||
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
@ -207,7 +207,7 @@ def test_delete_repository():
|
||||
def test_delete_repository_invalid_repository_name():
|
||||
client = boto3.client("codecommit", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.delete_repository(repositoryName="_rep@ository_one")
|
||||
ex = e.exception
|
||||
ex.operation_name.should.equal("DeleteRepository")
|
||||
|
@ -4,7 +4,7 @@ from datetime import datetime
|
||||
import boto3
|
||||
import sure # noqa
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_codepipeline, mock_iam
|
||||
|
||||
@ -77,7 +77,7 @@ def test_create_pipeline_errors():
|
||||
client_iam = boto3.client("iam", region_name="us-east-1")
|
||||
create_basic_codepipeline(client, "test-pipeline")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
create_basic_codepipeline(client, "test-pipeline")
|
||||
ex = e.exception
|
||||
ex.operation_name.should.equal("CreatePipeline")
|
||||
@ -87,7 +87,7 @@ def test_create_pipeline_errors():
|
||||
"A pipeline with the name 'test-pipeline' already exists in account '123456789012'"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.create_pipeline(
|
||||
pipeline={
|
||||
"name": "invalid-pipeline",
|
||||
@ -139,7 +139,7 @@ def test_create_pipeline_errors():
|
||||
),
|
||||
)["Role"]["Arn"]
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.create_pipeline(
|
||||
pipeline={
|
||||
"name": "invalid-pipeline",
|
||||
@ -175,7 +175,7 @@ def test_create_pipeline_errors():
|
||||
"CodePipeline is not authorized to perform AssumeRole on role arn:aws:iam::123456789012:role/wrong-role"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.create_pipeline(
|
||||
pipeline={
|
||||
"name": "invalid-pipeline",
|
||||
@ -282,7 +282,7 @@ def test_get_pipeline():
|
||||
def test_get_pipeline_errors():
|
||||
client = boto3.client("codepipeline", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.get_pipeline(name="not-existing")
|
||||
ex = e.exception
|
||||
ex.operation_name.should.equal("GetPipeline")
|
||||
@ -410,7 +410,7 @@ def test_update_pipeline():
|
||||
def test_update_pipeline_errors():
|
||||
client = boto3.client("codepipeline", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.update_pipeline(
|
||||
pipeline={
|
||||
"name": "not-existing",
|
||||
@ -517,7 +517,7 @@ def test_list_tags_for_resource():
|
||||
def test_list_tags_for_resource_errors():
|
||||
client = boto3.client("codepipeline", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.list_tags_for_resource(
|
||||
resourceArn="arn:aws:codepipeline:us-east-1:123456789012:not-existing"
|
||||
)
|
||||
@ -555,7 +555,7 @@ def test_tag_resource_errors():
|
||||
name = "test-pipeline"
|
||||
create_basic_codepipeline(client, name)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.tag_resource(
|
||||
resourceArn="arn:aws:codepipeline:us-east-1:123456789012:not-existing",
|
||||
tags=[{"key": "key-2", "value": "value-2"}],
|
||||
@ -568,7 +568,7 @@ def test_tag_resource_errors():
|
||||
"The account with id '123456789012' does not include a pipeline with the name 'not-existing'"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.tag_resource(
|
||||
resourceArn="arn:aws:codepipeline:us-east-1:123456789012:{}".format(name),
|
||||
tags=[{"key": "aws:key", "value": "value"}],
|
||||
@ -583,7 +583,7 @@ def test_tag_resource_errors():
|
||||
"msg=[Caller is an end user and not allowed to mutate system tags]"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.tag_resource(
|
||||
resourceArn="arn:aws:codepipeline:us-east-1:123456789012:{}".format(name),
|
||||
tags=[
|
||||
@ -634,7 +634,7 @@ def test_untag_resource():
|
||||
def test_untag_resource_errors():
|
||||
client = boto3.client("codepipeline", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.untag_resource(
|
||||
resourceArn="arn:aws:codepipeline:us-east-1:123456789012:not-existing",
|
||||
tagKeys=["key"],
|
||||
|
1
tests/test_cognitoidentity/__init__.py
Normal file
1
tests/test_cognitoidentity/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||
import boto3
|
||||
import sure # noqa
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_cognitoidentity
|
||||
from moto.cognitoidentity.utils import get_random_identity_id
|
||||
@ -75,7 +75,7 @@ def test_describe_identity_pool():
|
||||
def test_describe_identity_pool_with_invalid_id_raises_error():
|
||||
conn = boto3.client("cognito-identity", "us-west-2")
|
||||
|
||||
with assert_raises(ClientError) as cm:
|
||||
with pytest.raises(ClientError) as cm:
|
||||
conn.describe_identity_pool(IdentityPoolId="us-west-2_non-existent")
|
||||
|
||||
cm.exception.operation_name.should.equal("DescribeIdentityPool")
|
||||
|
1
tests/test_cognitoidp/__init__.py
Normal file
1
tests/test_cognitoidp/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -17,7 +17,7 @@ import boto3
|
||||
import sure # noqa
|
||||
from botocore.exceptions import ClientError
|
||||
from jose import jws, jwk, jwt
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_cognitoidp, settings
|
||||
from moto.cognitoidp.utils import create_id
|
||||
@ -603,7 +603,7 @@ def test_update_identity_provider_no_user_pool():
|
||||
|
||||
new_value = str(uuid.uuid4())
|
||||
|
||||
with assert_raises(conn.exceptions.ResourceNotFoundException) as cm:
|
||||
with pytest.raises(conn.exceptions.ResourceNotFoundException) as cm:
|
||||
conn.update_identity_provider(
|
||||
UserPoolId="foo", ProviderName="bar", ProviderDetails={"thing": new_value}
|
||||
)
|
||||
@ -623,7 +623,7 @@ def test_update_identity_provider_no_identity_provider():
|
||||
new_value = str(uuid.uuid4())
|
||||
user_pool_id = conn.create_user_pool(PoolName=str(uuid.uuid4()))["UserPool"]["Id"]
|
||||
|
||||
with assert_raises(conn.exceptions.ResourceNotFoundException) as cm:
|
||||
with pytest.raises(conn.exceptions.ResourceNotFoundException) as cm:
|
||||
conn.update_identity_provider(
|
||||
UserPoolId=user_pool_id,
|
||||
ProviderName="foo",
|
||||
@ -699,7 +699,7 @@ def test_create_group_with_duplicate_name_raises_error():
|
||||
|
||||
conn.create_group(GroupName=group_name, UserPoolId=user_pool_id)
|
||||
|
||||
with assert_raises(ClientError) as cm:
|
||||
with pytest.raises(ClientError) as cm:
|
||||
conn.create_group(GroupName=group_name, UserPoolId=user_pool_id)
|
||||
cm.exception.operation_name.should.equal("CreateGroup")
|
||||
cm.exception.response["Error"]["Code"].should.equal("GroupExistsException")
|
||||
@ -747,7 +747,7 @@ def test_delete_group():
|
||||
result = conn.delete_group(GroupName=group_name, UserPoolId=user_pool_id)
|
||||
list(result.keys()).should.equal(["ResponseMetadata"]) # No response expected
|
||||
|
||||
with assert_raises(ClientError) as cm:
|
||||
with pytest.raises(ClientError) as cm:
|
||||
conn.get_group(GroupName=group_name, UserPoolId=user_pool_id)
|
||||
cm.exception.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
||||
|
||||
@ -1565,7 +1565,7 @@ def test_resource_server():
|
||||
res["ResourceServer"]["Name"].should.equal(name)
|
||||
res["ResourceServer"]["Scopes"].should.equal(scopes)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_resource_server(
|
||||
UserPoolId=user_pool_id, Identifier=identifier, Name=name, Scopes=scopes
|
||||
)
|
||||
|
1
tests/test_config/__init__.py
Normal file
1
tests/test_config/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -5,8 +5,8 @@ from datetime import datetime, timedelta
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
from nose import SkipTest
|
||||
from nose.tools import assert_raises
|
||||
from unittest import SkipTest
|
||||
import pytest
|
||||
|
||||
from moto import mock_s3
|
||||
from moto.config import mock_config
|
||||
@ -20,7 +20,7 @@ def test_put_configuration_recorder():
|
||||
client = boto3.client("config", region_name="us-west-2")
|
||||
|
||||
# Try without a name supplied:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_recorder(ConfigurationRecorder={"roleARN": "somearn"})
|
||||
assert (
|
||||
ce.exception.response["Error"]["Code"]
|
||||
@ -29,7 +29,7 @@ def test_put_configuration_recorder():
|
||||
assert "is not valid, blank string." in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# Try with a really long name:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_recorder(
|
||||
ConfigurationRecorder={"name": "a" * 257, "roleARN": "somearn"}
|
||||
)
|
||||
@ -68,7 +68,7 @@ def test_put_configuration_recorder():
|
||||
]
|
||||
|
||||
for bg in bad_groups:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_recorder(
|
||||
ConfigurationRecorder={
|
||||
"name": "default",
|
||||
@ -85,7 +85,7 @@ def test_put_configuration_recorder():
|
||||
)
|
||||
|
||||
# With an invalid Resource Type:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_recorder(
|
||||
ConfigurationRecorder={
|
||||
"name": "default",
|
||||
@ -166,7 +166,7 @@ def test_put_configuration_recorder():
|
||||
assert not result[0]["recordingGroup"].get("resourceTypes")
|
||||
|
||||
# Can currently only have exactly 1 Config Recorder in an account/region:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_recorder(
|
||||
ConfigurationRecorder={
|
||||
"name": "someotherrecorder",
|
||||
@ -192,7 +192,7 @@ def test_put_configuration_aggregator():
|
||||
client = boto3.client("config", region_name="us-west-2")
|
||||
|
||||
# With too many aggregation sources:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
AccountAggregationSources=[
|
||||
@ -213,7 +213,7 @@ def test_put_configuration_aggregator():
|
||||
assert ce.exception.response["Error"]["Code"] == "ValidationException"
|
||||
|
||||
# With an invalid region config (no regions defined):
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
AccountAggregationSources=[
|
||||
@ -229,7 +229,7 @@ def test_put_configuration_aggregator():
|
||||
)
|
||||
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
|
||||
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
OrganizationAggregationSource={
|
||||
@ -243,7 +243,7 @@ def test_put_configuration_aggregator():
|
||||
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
|
||||
|
||||
# With both region flags defined:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
AccountAggregationSources=[
|
||||
@ -260,7 +260,7 @@ def test_put_configuration_aggregator():
|
||||
)
|
||||
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
|
||||
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
OrganizationAggregationSource={
|
||||
@ -276,7 +276,7 @@ def test_put_configuration_aggregator():
|
||||
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
|
||||
|
||||
# Name too long:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="a" * 257,
|
||||
AccountAggregationSources=[
|
||||
@ -287,7 +287,7 @@ def test_put_configuration_aggregator():
|
||||
assert ce.exception.response["Error"]["Code"] == "ValidationException"
|
||||
|
||||
# Too many tags (>50):
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
AccountAggregationSources=[
|
||||
@ -304,7 +304,7 @@ def test_put_configuration_aggregator():
|
||||
assert ce.exception.response["Error"]["Code"] == "ValidationException"
|
||||
|
||||
# Tag key is too big (>128 chars):
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
AccountAggregationSources=[
|
||||
@ -319,7 +319,7 @@ def test_put_configuration_aggregator():
|
||||
assert ce.exception.response["Error"]["Code"] == "ValidationException"
|
||||
|
||||
# Tag value is too big (>256 chars):
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
AccountAggregationSources=[
|
||||
@ -334,7 +334,7 @@ def test_put_configuration_aggregator():
|
||||
assert ce.exception.response["Error"]["Code"] == "ValidationException"
|
||||
|
||||
# Duplicate Tags:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
AccountAggregationSources=[
|
||||
@ -346,7 +346,7 @@ def test_put_configuration_aggregator():
|
||||
assert ce.exception.response["Error"]["Code"] == "InvalidInput"
|
||||
|
||||
# Invalid characters in the tag key:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
AccountAggregationSources=[
|
||||
@ -361,7 +361,7 @@ def test_put_configuration_aggregator():
|
||||
assert ce.exception.response["Error"]["Code"] == "ValidationException"
|
||||
|
||||
# If it contains both the AccountAggregationSources and the OrganizationAggregationSource
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(
|
||||
ConfigurationAggregatorName="testing",
|
||||
AccountAggregationSources=[
|
||||
@ -379,7 +379,7 @@ def test_put_configuration_aggregator():
|
||||
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
|
||||
|
||||
# If it contains neither:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_configuration_aggregator(ConfigurationAggregatorName="testing")
|
||||
assert (
|
||||
"AccountAggregationSource or the OrganizationAggregationSource"
|
||||
@ -466,7 +466,7 @@ def test_describe_configuration_aggregators():
|
||||
)
|
||||
|
||||
# Describe with an incorrect name:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.describe_configuration_aggregators(
|
||||
ConfigurationAggregatorNames=["DoesNotExist"]
|
||||
)
|
||||
@ -480,7 +480,7 @@ def test_describe_configuration_aggregators():
|
||||
)
|
||||
|
||||
# Error describe with more than 1 item in the list:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.describe_configuration_aggregators(
|
||||
ConfigurationAggregatorNames=["testing0", "DoesNotExist"]
|
||||
)
|
||||
@ -551,7 +551,7 @@ def test_describe_configuration_aggregators():
|
||||
)
|
||||
|
||||
# Test with an invalid filter:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.describe_configuration_aggregators(NextToken="WRONG")
|
||||
assert (
|
||||
"The nextToken provided is invalid" == ce.exception.response["Error"]["Message"]
|
||||
@ -564,7 +564,7 @@ def test_put_aggregation_authorization():
|
||||
client = boto3.client("config", region_name="us-west-2")
|
||||
|
||||
# Too many tags (>50):
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_aggregation_authorization(
|
||||
AuthorizedAccountId="012345678910",
|
||||
AuthorizedAwsRegion="us-west-2",
|
||||
@ -579,7 +579,7 @@ def test_put_aggregation_authorization():
|
||||
assert ce.exception.response["Error"]["Code"] == "ValidationException"
|
||||
|
||||
# Tag key is too big (>128 chars):
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_aggregation_authorization(
|
||||
AuthorizedAccountId="012345678910",
|
||||
AuthorizedAwsRegion="us-west-2",
|
||||
@ -592,7 +592,7 @@ def test_put_aggregation_authorization():
|
||||
assert ce.exception.response["Error"]["Code"] == "ValidationException"
|
||||
|
||||
# Tag value is too big (>256 chars):
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_aggregation_authorization(
|
||||
AuthorizedAccountId="012345678910",
|
||||
AuthorizedAwsRegion="us-west-2",
|
||||
@ -605,7 +605,7 @@ def test_put_aggregation_authorization():
|
||||
assert ce.exception.response["Error"]["Code"] == "ValidationException"
|
||||
|
||||
# Duplicate Tags:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_aggregation_authorization(
|
||||
AuthorizedAccountId="012345678910",
|
||||
AuthorizedAwsRegion="us-west-2",
|
||||
@ -615,7 +615,7 @@ def test_put_aggregation_authorization():
|
||||
assert ce.exception.response["Error"]["Code"] == "InvalidInput"
|
||||
|
||||
# Invalid characters in the tag key:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_aggregation_authorization(
|
||||
AuthorizedAccountId="012345678910",
|
||||
AuthorizedAwsRegion="us-west-2",
|
||||
@ -708,7 +708,7 @@ def test_describe_aggregation_authorizations():
|
||||
] == ["{}".format(str(x) * 12) for x in range(8, 10)]
|
||||
|
||||
# Test with an invalid filter:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.describe_aggregation_authorizations(NextToken="WRONG")
|
||||
assert (
|
||||
"The nextToken provided is invalid" == ce.exception.response["Error"]["Message"]
|
||||
@ -751,7 +751,7 @@ def test_delete_configuration_aggregator():
|
||||
client.delete_configuration_aggregator(ConfigurationAggregatorName="testing")
|
||||
|
||||
# And again to confirm that it's deleted:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.delete_configuration_aggregator(ConfigurationAggregatorName="testing")
|
||||
assert (
|
||||
"The configuration aggregator does not exist."
|
||||
@ -796,7 +796,7 @@ def test_describe_configurations():
|
||||
)
|
||||
|
||||
# Specify an incorrect name:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.describe_configuration_recorders(ConfigurationRecorderNames=["wrong"])
|
||||
assert (
|
||||
ce.exception.response["Error"]["Code"] == "NoSuchConfigurationRecorderException"
|
||||
@ -804,7 +804,7 @@ def test_describe_configurations():
|
||||
assert "wrong" in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# And with both a good and wrong name:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.describe_configuration_recorders(
|
||||
ConfigurationRecorderNames=["testrecorder", "wrong"]
|
||||
)
|
||||
@ -819,7 +819,7 @@ def test_delivery_channels():
|
||||
client = boto3.client("config", region_name="us-west-2")
|
||||
|
||||
# Try without a config recorder:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_delivery_channel(DeliveryChannel={})
|
||||
assert (
|
||||
ce.exception.response["Error"]["Code"]
|
||||
@ -845,7 +845,7 @@ def test_delivery_channels():
|
||||
)
|
||||
|
||||
# Try without a name supplied:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_delivery_channel(DeliveryChannel={})
|
||||
assert (
|
||||
ce.exception.response["Error"]["Code"] == "InvalidDeliveryChannelNameException"
|
||||
@ -853,7 +853,7 @@ def test_delivery_channels():
|
||||
assert "is not valid, blank string." in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# Try with a really long name:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_delivery_channel(DeliveryChannel={"name": "a" * 257})
|
||||
assert ce.exception.response["Error"]["Code"] == "ValidationException"
|
||||
assert (
|
||||
@ -862,7 +862,7 @@ def test_delivery_channels():
|
||||
)
|
||||
|
||||
# Without specifying a bucket name:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_delivery_channel(DeliveryChannel={"name": "testchannel"})
|
||||
assert ce.exception.response["Error"]["Code"] == "NoSuchBucketException"
|
||||
assert (
|
||||
@ -870,7 +870,7 @@ def test_delivery_channels():
|
||||
== "Cannot find a S3 bucket with an empty bucket name."
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_delivery_channel(
|
||||
DeliveryChannel={"name": "testchannel", "s3BucketName": ""}
|
||||
)
|
||||
@ -881,7 +881,7 @@ def test_delivery_channels():
|
||||
)
|
||||
|
||||
# With an empty string for the S3 key prefix:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_delivery_channel(
|
||||
DeliveryChannel={
|
||||
"name": "testchannel",
|
||||
@ -893,7 +893,7 @@ def test_delivery_channels():
|
||||
assert "empty s3 key prefix." in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# With an empty string for the SNS ARN:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_delivery_channel(
|
||||
DeliveryChannel={
|
||||
"name": "testchannel",
|
||||
@ -905,7 +905,7 @@ def test_delivery_channels():
|
||||
assert "The sns topic arn" in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# With an invalid delivery frequency:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_delivery_channel(
|
||||
DeliveryChannel={
|
||||
"name": "testchannel",
|
||||
@ -950,7 +950,7 @@ def test_delivery_channels():
|
||||
)
|
||||
|
||||
# Can only have 1:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_delivery_channel(
|
||||
DeliveryChannel={"name": "testchannel2", "s3BucketName": "somebucket"}
|
||||
)
|
||||
@ -1015,13 +1015,13 @@ def test_describe_delivery_channels():
|
||||
)
|
||||
|
||||
# Specify an incorrect name:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.describe_delivery_channels(DeliveryChannelNames=["wrong"])
|
||||
assert ce.exception.response["Error"]["Code"] == "NoSuchDeliveryChannelException"
|
||||
assert "wrong" in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# And with both a good and wrong name:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.describe_delivery_channels(DeliveryChannelNames=["testchannel", "wrong"])
|
||||
assert ce.exception.response["Error"]["Code"] == "NoSuchDeliveryChannelException"
|
||||
assert "wrong" in ce.exception.response["Error"]["Message"]
|
||||
@ -1032,7 +1032,7 @@ def test_start_configuration_recorder():
|
||||
client = boto3.client("config", region_name="us-west-2")
|
||||
|
||||
# Without a config recorder:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.start_configuration_recorder(ConfigurationRecorderName="testrecorder")
|
||||
assert (
|
||||
ce.exception.response["Error"]["Code"] == "NoSuchConfigurationRecorderException"
|
||||
@ -1052,7 +1052,7 @@ def test_start_configuration_recorder():
|
||||
)
|
||||
|
||||
# Without a delivery channel:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.start_configuration_recorder(ConfigurationRecorderName="testrecorder")
|
||||
assert (
|
||||
ce.exception.response["Error"]["Code"] == "NoAvailableDeliveryChannelException"
|
||||
@ -1090,7 +1090,7 @@ def test_stop_configuration_recorder():
|
||||
client = boto3.client("config", region_name="us-west-2")
|
||||
|
||||
# Without a config recorder:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.stop_configuration_recorder(ConfigurationRecorderName="testrecorder")
|
||||
assert (
|
||||
ce.exception.response["Error"]["Code"] == "NoSuchConfigurationRecorderException"
|
||||
@ -1180,7 +1180,7 @@ def test_describe_configuration_recorder_status():
|
||||
assert not result[0]["recording"]
|
||||
|
||||
# Invalid name:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.describe_configuration_recorder_status(
|
||||
ConfigurationRecorderNames=["testrecorder", "wrong"]
|
||||
)
|
||||
@ -1211,7 +1211,7 @@ def test_delete_configuration_recorder():
|
||||
client.delete_configuration_recorder(ConfigurationRecorderName="testrecorder")
|
||||
|
||||
# Try again -- it should be deleted:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.delete_configuration_recorder(ConfigurationRecorderName="testrecorder")
|
||||
assert (
|
||||
ce.exception.response["Error"]["Code"] == "NoSuchConfigurationRecorderException"
|
||||
@ -1240,7 +1240,7 @@ def test_delete_delivery_channel():
|
||||
client.start_configuration_recorder(ConfigurationRecorderName="testrecorder")
|
||||
|
||||
# With the recorder enabled:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.delete_delivery_channel(DeliveryChannelName="testchannel")
|
||||
assert (
|
||||
ce.exception.response["Error"]["Code"]
|
||||
@ -1258,7 +1258,7 @@ def test_delete_delivery_channel():
|
||||
client.delete_delivery_channel(DeliveryChannelName="testchannel")
|
||||
|
||||
# Verify:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.delete_delivery_channel(DeliveryChannelName="testchannel")
|
||||
assert ce.exception.response["Error"]["Code"] == "NoSuchDeliveryChannelException"
|
||||
|
||||
@ -1341,12 +1341,12 @@ def test_list_discovered_resource():
|
||||
)["resourceIdentifiers"]
|
||||
|
||||
# Test with an invalid page num > 100:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.list_discovered_resources(resourceType="AWS::S3::Bucket", limit=101)
|
||||
assert "101" in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# Test by supplying both resourceName and also resourceIds:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.list_discovered_resources(
|
||||
resourceType="AWS::S3::Bucket",
|
||||
resourceName="whats",
|
||||
@ -1359,7 +1359,7 @@ def test_list_discovered_resource():
|
||||
|
||||
# More than 20 resourceIds:
|
||||
resource_ids = ["{}".format(x) for x in range(0, 21)]
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.list_discovered_resources(
|
||||
resourceType="AWS::S3::Bucket", resourceIds=resource_ids
|
||||
)
|
||||
@ -1378,7 +1378,7 @@ def test_list_aggregate_discovered_resource():
|
||||
client = boto3.client("config", region_name="us-west-2")
|
||||
|
||||
# Without an aggregator:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.list_aggregate_discovered_resources(
|
||||
ConfigurationAggregatorName="lolno", ResourceType="AWS::S3::Bucket"
|
||||
)
|
||||
@ -1504,7 +1504,7 @@ def test_list_aggregate_discovered_resource():
|
||||
)["ResourceIdentifiers"]
|
||||
|
||||
# Test with an invalid page num > 100:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.list_aggregate_discovered_resources(
|
||||
ConfigurationAggregatorName="testing",
|
||||
ResourceType="AWS::S3::Bucket",
|
||||
@ -1522,7 +1522,7 @@ def test_get_resource_config_history():
|
||||
client = boto3.client("config", region_name="us-west-2")
|
||||
|
||||
# With an invalid resource type:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.get_resource_config_history(
|
||||
resourceType="NOT::A::RESOURCE", resourceId="notcreatedyet"
|
||||
)
|
||||
@ -1533,7 +1533,7 @@ def test_get_resource_config_history():
|
||||
}
|
||||
|
||||
# With nothing created yet:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.get_resource_config_history(
|
||||
resourceType="AWS::S3::Bucket", resourceId="notcreatedyet"
|
||||
)
|
||||
@ -1565,7 +1565,7 @@ def test_get_resource_config_history():
|
||||
Bucket="eu-bucket",
|
||||
CreateBucketConfiguration={"LocationConstraint": "eu-west-1"},
|
||||
)
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.get_resource_config_history(
|
||||
resourceType="AWS::S3::Bucket", resourceId="eu-bucket"
|
||||
)
|
||||
@ -1581,7 +1581,7 @@ def test_batch_get_resource_config():
|
||||
client = boto3.client("config", region_name="us-west-2")
|
||||
|
||||
# With more than 100 resourceKeys:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.batch_get_resource_config(
|
||||
resourceKeys=[
|
||||
{"resourceType": "AWS::S3::Bucket", "resourceId": "someBucket"}
|
||||
@ -1653,7 +1653,7 @@ def test_batch_get_aggregate_resource_config():
|
||||
"ResourceType": "NOT::A::RESOURCE",
|
||||
"ResourceId": "nope",
|
||||
}
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.batch_get_aggregate_resource_config(
|
||||
ConfigurationAggregatorName="lolno", ResourceIdentifiers=[bad_ri]
|
||||
)
|
||||
@ -1673,7 +1673,7 @@ def test_batch_get_aggregate_resource_config():
|
||||
)
|
||||
|
||||
# With more than 100 items:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.batch_get_aggregate_resource_config(
|
||||
ConfigurationAggregatorName="testing", ResourceIdentifiers=[bad_ri] * 101
|
||||
)
|
||||
@ -1814,7 +1814,7 @@ def test_put_evaluations():
|
||||
client = boto3.client("config", region_name="us-west-2")
|
||||
|
||||
# Try without Evaluations supplied:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_evaluations(Evaluations=[], ResultToken="test", TestMode=True)
|
||||
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
|
||||
assert (
|
||||
@ -1823,7 +1823,7 @@ def test_put_evaluations():
|
||||
)
|
||||
|
||||
# Try without a ResultToken supplied:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.put_evaluations(
|
||||
Evaluations=[
|
||||
{
|
||||
@ -1842,7 +1842,7 @@ def test_put_evaluations():
|
||||
raise SkipTest("Does not work in server mode due to error in Workzeug")
|
||||
else:
|
||||
# Try without TestMode supplied:
|
||||
with assert_raises(NotImplementedError):
|
||||
with pytest.raises(NotImplementedError):
|
||||
client.put_evaluations(
|
||||
Evaluations=[
|
||||
{
|
||||
@ -1913,7 +1913,7 @@ def test_put_organization_conformance_pack_errors():
|
||||
client = boto3.client("config", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.put_organization_conformance_pack(
|
||||
DeliveryS3Bucket="awsconfigconforms-test-bucket",
|
||||
OrganizationConformancePackName="test-pack",
|
||||
@ -1927,7 +1927,7 @@ def test_put_organization_conformance_pack_errors():
|
||||
ex.response["Error"]["Message"].should.equal("Template body is invalid")
|
||||
|
||||
# when
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.put_organization_conformance_pack(
|
||||
DeliveryS3Bucket="awsconfigconforms-test-bucket",
|
||||
OrganizationConformancePackName="test-pack",
|
||||
@ -1979,7 +1979,7 @@ def test_describe_organization_conformance_packs_errors():
|
||||
client = boto3.client("config", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.describe_organization_conformance_packs(
|
||||
OrganizationConformancePackNames=["not-existing"]
|
||||
)
|
||||
@ -2055,7 +2055,7 @@ def test_describe_organization_conformance_pack_statuses_errors():
|
||||
client = boto3.client("config", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.describe_organization_conformance_pack_statuses(
|
||||
OrganizationConformancePackNames=["not-existing"]
|
||||
)
|
||||
@ -2127,7 +2127,7 @@ def test_get_organization_conformance_pack_detailed_status_errors():
|
||||
client = boto3.client("config", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.get_organization_conformance_pack_detailed_status(
|
||||
OrganizationConformancePackName="not-existing"
|
||||
)
|
||||
@ -2171,7 +2171,7 @@ def test_delete_organization_conformance_pack_errors():
|
||||
client = boto3.client("config", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.delete_organization_conformance_pack(
|
||||
OrganizationConformancePackName="not-existing"
|
||||
)
|
||||
|
1
tests/test_core/__init__.py
Normal file
1
tests/test_core/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -4,9 +4,7 @@ import boto3
|
||||
import sure # noqa
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_iam, mock_ec2, mock_s3, mock_sts, mock_elbv2, mock_rds2
|
||||
from moto.core import set_initial_no_auth_action_count
|
||||
@ -179,7 +177,7 @@ def test_invalid_client_token_id():
|
||||
aws_access_key_id="invalid",
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_user()
|
||||
ex.exception.response["Error"]["Code"].should.equal("InvalidClientTokenId")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -197,7 +195,7 @@ def test_auth_failure():
|
||||
aws_access_key_id="invalid",
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.describe_instances()
|
||||
ex.exception.response["Error"]["Code"].should.equal("AuthFailure")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(401)
|
||||
@ -216,7 +214,7 @@ def test_signature_does_not_match():
|
||||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_user()
|
||||
ex.exception.response["Error"]["Code"].should.equal("SignatureDoesNotMatch")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -235,7 +233,7 @@ def test_auth_failure_with_valid_access_key_id():
|
||||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.describe_instances()
|
||||
ex.exception.response["Error"]["Code"].should.equal("AuthFailure")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(401)
|
||||
@ -255,7 +253,7 @@ def test_access_denied_with_no_policy():
|
||||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.describe_instances()
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -321,7 +319,7 @@ def test_access_denied_for_run_instances():
|
||||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.run_instances(MaxCount=1, MinCount=1)
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -352,7 +350,7 @@ def test_access_denied_with_denying_policy():
|
||||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_vpc(CidrBlock="10.0.0.0/16")
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -452,7 +450,7 @@ def test_s3_access_denied_with_denying_attached_group_policy():
|
||||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.list_buckets()
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -486,7 +484,7 @@ def test_s3_access_denied_with_denying_inline_group_policy():
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
client.create_bucket(Bucket=bucket_name)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.get_object(Bucket=bucket_name, Key="sdfsdf")
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -532,7 +530,7 @@ def test_access_denied_with_many_irrelevant_policies():
|
||||
aws_access_key_id=access_key["AccessKeyId"],
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_key_pair(KeyName="TestKey")
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -631,7 +629,7 @@ def test_access_denied_with_temporary_credentials():
|
||||
aws_secret_access_key=credentials["SecretAccessKey"],
|
||||
aws_session_token=credentials["SessionToken"],
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_db_instance(
|
||||
DBInstanceIdentifier="test-db-instance",
|
||||
DBInstanceClass="db.t3",
|
||||
@ -678,7 +676,7 @@ def test_s3_invalid_access_key_id():
|
||||
aws_access_key_id="invalid",
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.list_buckets()
|
||||
ex.exception.response["Error"]["Code"].should.equal("InvalidAccessKeyId")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -700,7 +698,7 @@ def test_s3_signature_does_not_match():
|
||||
aws_secret_access_key="invalid",
|
||||
)
|
||||
client.create_bucket(Bucket=bucket_name)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.put_object(Bucket=bucket_name, Key="abc")
|
||||
ex.exception.response["Error"]["Code"].should.equal("SignatureDoesNotMatch")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -736,7 +734,7 @@ def test_s3_access_denied_not_action():
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
client.create_bucket(Bucket=bucket_name)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.delete_object(Bucket=bucket_name, Key="sdfsdf")
|
||||
ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
|
||||
@ -776,7 +774,7 @@ def test_s3_invalid_token_with_temporary_credentials():
|
||||
aws_session_token="invalid",
|
||||
)
|
||||
client.create_bucket(Bucket=bucket_name)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.list_bucket_metrics_configurations(Bucket=bucket_name)
|
||||
ex.exception.response["Error"]["Code"].should.equal("InvalidToken")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
|
@ -4,8 +4,7 @@ from boto.exception import EC2ResponseError
|
||||
import sure # noqa
|
||||
import unittest
|
||||
|
||||
import tests.backport_assert_raises # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_ec2_deprecated, mock_s3_deprecated
|
||||
|
||||
@ -27,21 +26,21 @@ def test_basic_decorator():
|
||||
|
||||
def test_context_manager():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
with assert_raises(EC2ResponseError):
|
||||
with pytest.raises(EC2ResponseError):
|
||||
conn.get_all_instances()
|
||||
|
||||
with mock_ec2_deprecated():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
list(conn.get_all_instances()).should.equal([])
|
||||
|
||||
with assert_raises(EC2ResponseError):
|
||||
with pytest.raises(EC2ResponseError):
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
conn.get_all_instances()
|
||||
|
||||
|
||||
def test_decorator_start_and_stop():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
with assert_raises(EC2ResponseError):
|
||||
with pytest.raises(EC2ResponseError):
|
||||
conn.get_all_instances()
|
||||
|
||||
mock = mock_ec2_deprecated()
|
||||
@ -50,7 +49,7 @@ def test_decorator_start_and_stop():
|
||||
list(conn.get_all_instances()).should.equal([])
|
||||
mock.stop()
|
||||
|
||||
with assert_raises(EC2ResponseError):
|
||||
with pytest.raises(EC2ResponseError):
|
||||
conn.get_all_instances()
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from moto import mock_ec2, settings
|
||||
|
@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
import boto3
|
||||
|
1
tests/test_datapipeline/__init__.py
Normal file
1
tests/test_datapipeline/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -4,7 +4,7 @@ import boto
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_datasync
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
|
||||
def create_locations(client, create_smb=False, create_s3=False):
|
||||
@ -101,7 +101,7 @@ def test_describe_location_wrong():
|
||||
Password="",
|
||||
AgentArns=agent_arns,
|
||||
)
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
response = client.describe_location_s3(LocationArn=response["LocationArn"])
|
||||
|
||||
|
||||
@ -159,11 +159,11 @@ def test_create_task_fail():
|
||||
""" Test that Locations must exist before a Task can be created """
|
||||
client = boto3.client("datasync", region_name="us-east-1")
|
||||
locations = create_locations(client, create_smb=True, create_s3=True)
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
response = client.create_task(
|
||||
SourceLocationArn="1", DestinationLocationArn=locations["s3_arn"]
|
||||
)
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
response = client.create_task(
|
||||
SourceLocationArn=locations["smb_arn"], DestinationLocationArn="2"
|
||||
)
|
||||
@ -220,7 +220,7 @@ def test_describe_task():
|
||||
def test_describe_task_not_exist():
|
||||
client = boto3.client("datasync", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.describe_task(TaskArn="abc")
|
||||
|
||||
|
||||
@ -328,7 +328,7 @@ def test_start_task_execution_twice():
|
||||
assert "TaskExecutionArn" in response
|
||||
task_execution_arn = response["TaskExecutionArn"]
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
response = client.start_task_execution(TaskArn=task_arn)
|
||||
|
||||
|
||||
@ -392,7 +392,7 @@ def test_describe_task_execution():
|
||||
def test_describe_task_execution_not_exist():
|
||||
client = boto3.client("datasync", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.describe_task_execution(TaskExecutionArn="abc")
|
||||
|
||||
|
||||
|
1
tests/test_dynamodb/__init__.py
Normal file
1
tests/test_dynamodb/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -4,8 +4,7 @@ import boto
|
||||
import boto.dynamodb
|
||||
import sure # noqa
|
||||
import requests
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_dynamodb, mock_dynamodb_deprecated
|
||||
from moto.dynamodb import dynamodb_backend
|
||||
@ -38,7 +37,7 @@ def test_list_tables_layer_1():
|
||||
@mock_dynamodb_deprecated
|
||||
def test_describe_missing_table():
|
||||
conn = boto.connect_dynamodb("the_key", "the_secret")
|
||||
with assert_raises(DynamoDBResponseError):
|
||||
with pytest.raises(DynamoDBResponseError):
|
||||
conn.describe_table("messages")
|
||||
|
||||
|
||||
|
1
tests/test_dynamodb2/__init__.py
Normal file
1
tests/test_dynamodb2/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -17,7 +17,7 @@ from tests.helpers import requires_boto_gte
|
||||
import moto.dynamodb2.comparisons
|
||||
import moto.dynamodb2.models
|
||||
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
try:
|
||||
import boto.dynamodb2
|
||||
@ -72,7 +72,7 @@ def test_describe_missing_table():
|
||||
conn = boto.dynamodb2.connect_to_region(
|
||||
"us-west-2", aws_access_key_id="ak", aws_secret_access_key="sk"
|
||||
)
|
||||
with assert_raises(JSONResponseError):
|
||||
with pytest.raises(JSONResponseError):
|
||||
conn.describe_table("messages")
|
||||
|
||||
|
||||
@ -201,7 +201,7 @@ def test_item_add_empty_string_exception():
|
||||
ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
conn.put_item(
|
||||
TableName=name,
|
||||
Item={
|
||||
@ -248,7 +248,7 @@ def test_update_item_with_empty_string_exception():
|
||||
},
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
conn.update_item(
|
||||
TableName=name,
|
||||
Key={"forum_name": {"S": "LOLCat Forum"}},
|
||||
@ -1354,7 +1354,7 @@ def test_put_empty_item():
|
||||
)
|
||||
table = dynamodb.Table("test")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.put_item(Item={})
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"One or more parameter values were invalid: Missing the key structure_id in the item"
|
||||
@ -1373,7 +1373,7 @@ def test_put_item_nonexisting_hash_key():
|
||||
)
|
||||
table = dynamodb.Table("test")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.put_item(Item={"a_terribly_misguided_id_attribute": "abcdef"})
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"One or more parameter values were invalid: Missing the key structure_id in the item"
|
||||
@ -1398,7 +1398,7 @@ def test_put_item_nonexisting_range_key():
|
||||
)
|
||||
table = dynamodb.Table("test")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.put_item(Item={"structure_id": "abcdef"})
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"One or more parameter values were invalid: Missing the key added_at in the item"
|
||||
@ -1980,7 +1980,7 @@ def test_delete_item():
|
||||
assert response["Count"] == 2
|
||||
|
||||
# Test ReturnValues validation
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.delete_item(
|
||||
Key={"client": "client1", "app": "app1"}, ReturnValues="ALL_NEW"
|
||||
)
|
||||
@ -2085,7 +2085,7 @@ def test_describe_continuous_backups_errors():
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(Exception) as e:
|
||||
with pytest.raises(Exception) as e:
|
||||
client.describe_continuous_backups(TableName="not-existing-table")
|
||||
|
||||
# then
|
||||
@ -2171,7 +2171,7 @@ def test_update_continuous_backups_errors():
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
# when
|
||||
with assert_raises(Exception) as e:
|
||||
with pytest.raises(Exception) as e:
|
||||
client.update_continuous_backups(
|
||||
TableName="not-existing-table",
|
||||
PointInTimeRecoverySpecification={"PointInTimeRecoveryEnabled": True},
|
||||
@ -2291,7 +2291,7 @@ def test_update_item_on_map():
|
||||
ExpressionAttributeValues={":tb": "new_value"},
|
||||
)
|
||||
# Running this against AWS DDB gives an exception so make sure it also fails.:
|
||||
with assert_raises(client.exceptions.ClientError):
|
||||
with pytest.raises(client.exceptions.ClientError):
|
||||
# botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the UpdateItem
|
||||
# operation: The document path provided in the update expression is invalid for update
|
||||
table.update_item(
|
||||
@ -2321,7 +2321,7 @@ def test_update_item_on_map():
|
||||
)
|
||||
|
||||
# Test nested value for a nonexistent attribute throws a ClientError.
|
||||
with assert_raises(client.exceptions.ClientError):
|
||||
with pytest.raises(client.exceptions.ClientError):
|
||||
table.update_item(
|
||||
Key={"forum_name": "the-key", "subject": "123"},
|
||||
UpdateExpression="SET nonexistent.#nested = :tb",
|
||||
@ -2409,7 +2409,7 @@ def test_update_return_attributes():
|
||||
r = update("col1", "val5", "NONE")
|
||||
assert r["Attributes"] == {}
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
r = update("col1", "val6", "WRONG")
|
||||
|
||||
|
||||
@ -2438,7 +2438,7 @@ def test_put_return_attributes():
|
||||
)
|
||||
assert r["Attributes"] == {"id": {"S": "foo"}, "col1": {"S": "val1"}}
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.put_item(
|
||||
TableName="moto-test",
|
||||
Item={"id": {"S": "foo"}, "col1": {"S": "val3"}},
|
||||
@ -2675,7 +2675,7 @@ def test_condition_expressions():
|
||||
},
|
||||
)
|
||||
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.put_item(
|
||||
TableName="test1",
|
||||
Item={
|
||||
@ -2691,7 +2691,7 @@ def test_condition_expressions():
|
||||
},
|
||||
)
|
||||
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.put_item(
|
||||
TableName="test1",
|
||||
Item={
|
||||
@ -2707,7 +2707,7 @@ def test_condition_expressions():
|
||||
},
|
||||
)
|
||||
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.put_item(
|
||||
TableName="test1",
|
||||
Item={
|
||||
@ -2735,7 +2735,7 @@ def test_condition_expressions():
|
||||
ExpressionAttributeValues={":match": {"S": "match"}},
|
||||
)
|
||||
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.update_item(
|
||||
TableName="test1",
|
||||
Key={"client": {"S": "client1"}, "app": {"S": "app1"}},
|
||||
@ -2745,7 +2745,7 @@ def test_condition_expressions():
|
||||
ExpressionAttributeNames={"#existing": "existing", "#match": "match"},
|
||||
)
|
||||
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.delete_item(
|
||||
TableName="test1",
|
||||
Key={"client": {"S": "client1"}, "app": {"S": "app1"}},
|
||||
@ -2830,7 +2830,7 @@ def test_condition_expression__attr_doesnt_exist():
|
||||
update_if_attr_doesnt_exist()
|
||||
|
||||
# Second time should fail
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
update_if_attr_doesnt_exist()
|
||||
|
||||
|
||||
@ -2870,7 +2870,7 @@ def test_condition_expression__and_order():
|
||||
|
||||
# ensure that the RHS of the AND expression is not evaluated if the LHS
|
||||
# returns true (as it would result an error)
|
||||
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||
with pytest.raises(client.exceptions.ConditionalCheckFailedException):
|
||||
client.update_item(
|
||||
TableName="test",
|
||||
Key={"forum_name": {"S": "the-key"}},
|
||||
@ -2966,7 +2966,7 @@ def test_scan_by_non_exists_index():
|
||||
],
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.scan(TableName="test", IndexName="non_exists_index")
|
||||
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
@ -3001,7 +3001,7 @@ def test_query_by_non_exists_index():
|
||||
],
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.query(
|
||||
TableName="test",
|
||||
IndexName="non_exists_index",
|
||||
@ -3041,7 +3041,7 @@ def test_batch_items_returns_all():
|
||||
@mock_dynamodb2
|
||||
def test_batch_items_throws_exception_when_requesting_100_items_for_single_table():
|
||||
dynamodb = _create_user_table()
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.batch_get_item(
|
||||
RequestItems={
|
||||
"users": {
|
||||
@ -3063,7 +3063,7 @@ def test_batch_items_throws_exception_when_requesting_100_items_for_single_table
|
||||
@mock_dynamodb2
|
||||
def test_batch_items_throws_exception_when_requesting_100_items_across_all_tables():
|
||||
dynamodb = _create_user_table()
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.batch_get_item(
|
||||
RequestItems={
|
||||
"users": {
|
||||
@ -3160,7 +3160,7 @@ def test_batch_items_with_basic_projection_expression_and_attr_expression_names(
|
||||
@mock_dynamodb2
|
||||
def test_batch_items_should_throw_exception_for_duplicate_request():
|
||||
client = _create_user_table()
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.batch_get_item(
|
||||
RequestItems={
|
||||
"users": {
|
||||
@ -3186,7 +3186,7 @@ def test_index_with_unknown_attributes_should_fail():
|
||||
"Some index key attributes are not defined in AttributeDefinitions."
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.create_table(
|
||||
AttributeDefinitions=[
|
||||
{"AttributeName": "customer_nr", "AttributeType": "S"},
|
||||
@ -3366,7 +3366,7 @@ def test_update_list_index__set_index_of_a_string():
|
||||
client.put_item(
|
||||
TableName=table_name, Item={"id": {"S": "foo2"}, "itemstr": {"S": "somestring"}}
|
||||
)
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.update_item(
|
||||
TableName=table_name,
|
||||
Key={"id": {"S": "foo2"}},
|
||||
@ -3615,7 +3615,7 @@ def test_item_size_is_under_400KB():
|
||||
|
||||
|
||||
def assert_failure_due_to_item_size(func, **kwargs):
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
func(**kwargs)
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -3624,7 +3624,7 @@ def assert_failure_due_to_item_size(func, **kwargs):
|
||||
|
||||
|
||||
def assert_failure_due_to_item_size_to_update(func, **kwargs):
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
func(**kwargs)
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -3654,7 +3654,7 @@ def test_hash_key_cannot_use_begins_with_operations():
|
||||
batch.put_item(Item=item)
|
||||
|
||||
table = dynamodb.Table("test-table")
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.query(KeyConditionExpression=Key("key").begins_with("prefix-"))
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -4047,7 +4047,7 @@ def test_update_catches_invalid_list_append_operation():
|
||||
)
|
||||
|
||||
# Update item using invalid list_append expression
|
||||
with assert_raises(ParamValidationError) as ex:
|
||||
with pytest.raises(ParamValidationError) as ex:
|
||||
client.update_item(
|
||||
TableName="TestTable",
|
||||
Key={"SHA256": {"S": "sha-of-file"}},
|
||||
@ -4166,7 +4166,7 @@ def test_query_catches_when_no_filters():
|
||||
)
|
||||
table = dynamo.Table("origin-rbu-dev")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
table.query(TableName="original-rbu-dev")
|
||||
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
@ -4197,7 +4197,7 @@ def test_invalid_transact_get_items():
|
||||
|
||||
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.transact_get_items(
|
||||
TransactItems=[
|
||||
{"Get": {"Key": {"id": {"S": "1"}}, "TableName": "test1"}}
|
||||
@ -4211,7 +4211,7 @@ def test_invalid_transact_get_items():
|
||||
re.I,
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.transact_get_items(
|
||||
TransactItems=[
|
||||
{"Get": {"Key": {"id": {"S": "1"},}, "TableName": "test1"}},
|
||||
@ -4491,7 +4491,7 @@ def test_transact_write_items_put_conditional_expressions():
|
||||
TableName="test-table", Item={"id": {"S": "foo2"},},
|
||||
)
|
||||
# Put multiple items
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.transact_write_items(
|
||||
TransactItems=[
|
||||
{
|
||||
@ -4581,7 +4581,7 @@ def test_transact_write_items_conditioncheck_fails():
|
||||
)
|
||||
# Try to put an email address, but verify whether it exists
|
||||
# ConditionCheck should fail
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.transact_write_items(
|
||||
TransactItems=[
|
||||
{
|
||||
@ -4687,7 +4687,7 @@ def test_transact_write_items_delete_with_failed_condition_expression():
|
||||
)
|
||||
# Try to delete an item that does not have an email address
|
||||
# ConditionCheck should fail
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.transact_write_items(
|
||||
TransactItems=[
|
||||
{
|
||||
@ -4758,7 +4758,7 @@ def test_transact_write_items_update_with_failed_condition_expression():
|
||||
)
|
||||
# Try to update an item that does not have an email address
|
||||
# ConditionCheck should fail
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.transact_write_items(
|
||||
TransactItems=[
|
||||
{
|
||||
@ -5318,7 +5318,7 @@ def test_transact_write_items_fails_with_transaction_canceled_exception():
|
||||
# Insert one item
|
||||
dynamodb.put_item(TableName="test-table", Item={"id": {"S": "foo"}})
|
||||
# Update two items, the one that exists and another that doesn't
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
dynamodb.transact_write_items(
|
||||
TransactItems=[
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ from boto3.dynamodb.conditions import Key
|
||||
from botocore.exceptions import ClientError
|
||||
import sure # noqa
|
||||
from freezegun import freeze_time
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_dynamodb2, mock_dynamodb2_deprecated
|
||||
from boto.exception import JSONResponseError
|
||||
@ -1353,7 +1353,7 @@ def test_update_item_with_expression():
|
||||
|
||||
|
||||
def assert_failure_due_to_key_not_in_schema(func, **kwargs):
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
func(**kwargs)
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
|
1
tests/test_dynamodbstreams/__init__.py
Normal file
1
tests/test_dynamodbstreams/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals, print_function
|
||||
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto3
|
||||
from moto import mock_dynamodb2, mock_dynamodbstreams
|
||||
@ -224,7 +224,7 @@ class TestEdges:
|
||||
assert "LatestStreamLabel" in resp["TableDescription"]
|
||||
|
||||
# now try to enable it again
|
||||
with assert_raises(conn.exceptions.ResourceInUseException):
|
||||
with pytest.raises(conn.exceptions.ResourceInUseException):
|
||||
resp = conn.update_table(
|
||||
TableName="test-streams",
|
||||
StreamSpecification={
|
||||
|
@ -7,7 +7,7 @@ from boto.exception import EC2ResponseError
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_ec2_deprecated, mock_ec2
|
||||
@ -27,7 +27,7 @@ def test_ami_create_and_delete():
|
||||
reservation = conn.run_instances("ami-1234abcd")
|
||||
instance = reservation.instances[0]
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
image_id = conn.create_image(
|
||||
instance.id, "test-ami", "this is a test ami", dry_run=True
|
||||
)
|
||||
@ -76,7 +76,7 @@ def test_ami_create_and_delete():
|
||||
root_mapping.should_not.be.none
|
||||
|
||||
# Deregister
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
success = conn.deregister_image(image_id, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -87,7 +87,7 @@ def test_ami_create_and_delete():
|
||||
success = conn.deregister_image(image_id)
|
||||
success.should.be.true
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.deregister_image(image_id)
|
||||
cm.exception.code.should.equal("InvalidAMIID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -112,7 +112,7 @@ def test_ami_copy():
|
||||
|
||||
# Boto returns a 'CopyImage' object with an image_id attribute here. Use
|
||||
# the image_id to fetch the full info.
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
copy_image_ref = conn.copy_image(
|
||||
source_image.region.name,
|
||||
source_image.id,
|
||||
@ -152,7 +152,7 @@ def test_ami_copy():
|
||||
)
|
||||
|
||||
# Copy from non-existent source ID.
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.copy_image(
|
||||
source_image.region.name,
|
||||
"ami-abcd1234",
|
||||
@ -164,7 +164,7 @@ def test_ami_copy():
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Copy from non-existent source region.
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
invalid_region = (
|
||||
"us-east-1" if (source_image.region.name != "us-east-1") else "us-west-1"
|
||||
)
|
||||
@ -208,7 +208,7 @@ def test_ami_tagging():
|
||||
conn.create_image(instance.id, "test-ami", "this is a test ami")
|
||||
image = conn.get_all_images()[0]
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
image.add_tag("a key", "some value", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -233,7 +233,7 @@ def test_ami_create_from_missing_instance():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
args = ["i-abcdefg", "test-ami", "this is a test ami"]
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_image(*args)
|
||||
cm.exception.code.should.equal("InvalidInstanceID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -353,7 +353,7 @@ def test_ami_filtering_via_tag():
|
||||
def test_getting_missing_ami():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_image("ami-missing")
|
||||
cm.exception.code.should.equal("InvalidAMIID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -364,7 +364,7 @@ def test_getting_missing_ami():
|
||||
def test_getting_malformed_ami():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_image("foo-missing")
|
||||
cm.exception.code.should.equal("InvalidAMIID.Malformed")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -399,7 +399,7 @@ def test_ami_attribute_group_permissions():
|
||||
}
|
||||
|
||||
# Add 'all' group and confirm
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.modify_image_attribute(**dict(ADD_GROUP_ARGS, **{"dry_run": True}))
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -678,7 +678,7 @@ def test_ami_attribute_error_cases():
|
||||
image = conn.get_image(image_id)
|
||||
|
||||
# Error: Add with group != 'all'
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.modify_image_attribute(
|
||||
image.id, attribute="launchPermission", operation="add", groups="everyone"
|
||||
)
|
||||
@ -687,7 +687,7 @@ def test_ami_attribute_error_cases():
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Add with user ID that isn't an integer.
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.modify_image_attribute(
|
||||
image.id,
|
||||
attribute="launchPermission",
|
||||
@ -699,7 +699,7 @@ def test_ami_attribute_error_cases():
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Add with user ID that is > length 12.
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.modify_image_attribute(
|
||||
image.id,
|
||||
attribute="launchPermission",
|
||||
@ -711,7 +711,7 @@ def test_ami_attribute_error_cases():
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Add with user ID that is < length 12.
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.modify_image_attribute(
|
||||
image.id,
|
||||
attribute="launchPermission",
|
||||
@ -724,7 +724,7 @@ def test_ami_attribute_error_cases():
|
||||
|
||||
# Error: Add with one invalid user ID among other valid IDs, ensure no
|
||||
# partial changes.
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.modify_image_attribute(
|
||||
image.id,
|
||||
attribute="launchPermission",
|
||||
@ -739,7 +739,7 @@ def test_ami_attribute_error_cases():
|
||||
attributes.attrs.should.have.length_of(0)
|
||||
|
||||
# Error: Add with invalid image ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.modify_image_attribute(
|
||||
"ami-abcd1234", attribute="launchPermission", operation="add", groups="all"
|
||||
)
|
||||
@ -748,7 +748,7 @@ def test_ami_attribute_error_cases():
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Remove with invalid image ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.modify_image_attribute(
|
||||
"ami-abcd1234",
|
||||
attribute="launchPermission",
|
||||
@ -765,11 +765,11 @@ def test_ami_describe_non_existent():
|
||||
ec2 = boto3.resource("ec2", region_name="us-west-1")
|
||||
# Valid pattern but non-existent id
|
||||
img = ec2.Image("ami-abcd1234")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
img.load()
|
||||
# Invalid ami pattern
|
||||
img = ec2.Image("not_an_ami_id")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
img.load()
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import boto
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
from nose.tools import assert_false
|
||||
import pytest
|
||||
from boto.exception import EC2ResponseError
|
||||
|
||||
from moto import mock_ec2_deprecated
|
||||
@ -45,5 +44,5 @@ def test_delete_customer_gateways():
|
||||
@mock_ec2_deprecated
|
||||
def test_delete_customer_gateways_bad_id():
|
||||
conn = boto.connect_vpc("the_key", "the_secret")
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_customer_gateway("cgw-0123abcd")
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto3
|
||||
import boto
|
||||
@ -33,7 +32,7 @@ def test_dhcp_options_associate_invalid_dhcp_id():
|
||||
conn = boto.connect_vpc("the_key", "the_secret")
|
||||
vpc = conn.create_vpc("10.0.0.0/16")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.associate_dhcp_options("foo", vpc.id)
|
||||
cm.exception.code.should.equal("InvalidDhcpOptionID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -46,7 +45,7 @@ def test_dhcp_options_associate_invalid_vpc_id():
|
||||
conn = boto.connect_vpc("the_key", "the_secret")
|
||||
dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.associate_dhcp_options(dhcp_options.id, "foo")
|
||||
cm.exception.code.should.equal("InvalidVpcID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -64,7 +63,7 @@ def test_dhcp_options_delete_with_vpc():
|
||||
rval = conn.associate_dhcp_options(dhcp_options_id, vpc.id)
|
||||
rval.should.be.equal(True)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_dhcp_options(dhcp_options_id)
|
||||
cm.exception.code.should.equal("DependencyViolation")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -72,7 +71,7 @@ def test_dhcp_options_delete_with_vpc():
|
||||
|
||||
vpc.delete()
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_dhcp_options([dhcp_options_id])
|
||||
cm.exception.code.should.equal("InvalidDhcpOptionID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -100,13 +99,13 @@ def test_create_dhcp_options_invalid_options():
|
||||
conn = boto.connect_vpc("the_key", "the_secret")
|
||||
servers = ["f", "f", "f", "f", "f"]
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_dhcp_options(ntp_servers=servers)
|
||||
cm.exception.code.should.equal("InvalidParameterValue")
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_dhcp_options(netbios_node_type="0")
|
||||
cm.exception.code.should.equal("InvalidParameterValue")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -131,7 +130,7 @@ def test_describe_dhcp_options_invalid_id():
|
||||
"""get error on invalid dhcp_option_id lookup"""
|
||||
conn = boto.connect_vpc("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_dhcp_options(["1"])
|
||||
cm.exception.code.should.equal("InvalidDhcpOptionID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -149,7 +148,7 @@ def test_delete_dhcp_options():
|
||||
|
||||
conn.delete_dhcp_options(dhcp_option.id) # .should.be.equal(True)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_dhcp_options([dhcp_option.id])
|
||||
cm.exception.code.should.equal("InvalidDhcpOptionID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -162,7 +161,7 @@ def test_delete_dhcp_options_invalid_id():
|
||||
|
||||
conn.create_dhcp_options()
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_dhcp_options("dopt-abcd1234")
|
||||
cm.exception.code.should.equal("InvalidDhcpOptionID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -175,7 +174,7 @@ def test_delete_dhcp_options_malformed_id():
|
||||
|
||||
conn.create_dhcp_options()
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_dhcp_options("foo-abcd1234")
|
||||
cm.exception.code.should.equal("InvalidDhcpOptionsId.Malformed")
|
||||
cm.exception.status.should.equal(400)
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto.ec2 import ec2_backends
|
||||
import boto
|
||||
@ -31,7 +30,7 @@ def test_create_and_delete_volume():
|
||||
|
||||
volume = current_volume[0]
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
volume.delete(dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -46,7 +45,7 @@ def test_create_and_delete_volume():
|
||||
my_volume.should.have.length_of(0)
|
||||
|
||||
# Deleting something that was already deleted should throw an error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
volume.delete()
|
||||
cm.exception.code.should.equal("InvalidVolume.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -95,7 +94,7 @@ def test_delete_attached_volume():
|
||||
@mock_ec2_deprecated
|
||||
def test_create_encrypted_volume_dryrun():
|
||||
conn = boto.ec2.connect_to_region("us-east-1")
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.create_volume(80, "us-east-1a", encrypted=True, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -109,7 +108,7 @@ def test_create_encrypted_volume():
|
||||
conn = boto.ec2.connect_to_region("us-east-1")
|
||||
volume = conn.create_volume(80, "us-east-1a", encrypted=True)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.create_volume(80, "us-east-1a", encrypted=True, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -134,7 +133,7 @@ def test_filter_volume_by_id():
|
||||
vol2 = conn.get_all_volumes(volume_ids=[volume1.id, volume2.id])
|
||||
vol2.should.have.length_of(2)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_volumes(volume_ids=["vol-does_not_exist"])
|
||||
cm.exception.code.should.equal("InvalidVolume.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -259,7 +258,7 @@ def test_volume_attach_and_detach():
|
||||
volume.update()
|
||||
volume.volume_state().should.equal("available")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
volume.attach(instance.id, "/dev/sdh", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -275,7 +274,7 @@ def test_volume_attach_and_detach():
|
||||
|
||||
volume.attach_data.instance_id.should.equal(instance.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
volume.detach(dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -288,19 +287,19 @@ def test_volume_attach_and_detach():
|
||||
volume.update()
|
||||
volume.volume_state().should.equal("available")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm1:
|
||||
with pytest.raises(EC2ResponseError) as cm1:
|
||||
volume.attach("i-1234abcd", "/dev/sdh")
|
||||
cm1.exception.code.should.equal("InvalidInstanceID.NotFound")
|
||||
cm1.exception.status.should.equal(400)
|
||||
cm1.exception.request_id.should_not.be.none
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm2:
|
||||
with pytest.raises(EC2ResponseError) as cm2:
|
||||
conn.detach_volume(volume.id, instance.id, "/dev/sdh")
|
||||
cm2.exception.code.should.equal("InvalidAttachment.NotFound")
|
||||
cm2.exception.status.should.equal(400)
|
||||
cm2.exception.request_id.should_not.be.none
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm3:
|
||||
with pytest.raises(EC2ResponseError) as cm3:
|
||||
conn.detach_volume(volume.id, "i-1234abcd", "/dev/sdh")
|
||||
cm3.exception.code.should.equal("InvalidInstanceID.NotFound")
|
||||
cm3.exception.status.should.equal(400)
|
||||
@ -312,7 +311,7 @@ def test_create_snapshot():
|
||||
conn = boto.ec2.connect_to_region("us-east-1")
|
||||
volume = conn.create_volume(80, "us-east-1a")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
snapshot = volume.create_snapshot("a dryrun snapshot", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -340,7 +339,7 @@ def test_create_snapshot():
|
||||
conn.get_all_snapshots().should.have.length_of(num_snapshots)
|
||||
|
||||
# Deleting something that was already deleted should throw an error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
snapshot.delete()
|
||||
cm.exception.code.should.equal("InvalidSnapshot.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -382,7 +381,7 @@ def test_filter_snapshot_by_id():
|
||||
s.volume_id.should.be.within([volume2.id, volume3.id])
|
||||
s.region.name.should.equal(conn.region.name)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_snapshots(snapshot_ids=["snap-does_not_exist"])
|
||||
cm.exception.code.should.equal("InvalidSnapshot.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -484,7 +483,7 @@ def test_snapshot_attribute():
|
||||
|
||||
# Add 'all' group and confirm
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.modify_snapshot_attribute(**dict(ADD_GROUP_ARGS, **{"dry_run": True}))
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -506,7 +505,7 @@ def test_snapshot_attribute():
|
||||
)
|
||||
|
||||
# Remove 'all' group and confirm
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.modify_snapshot_attribute(**dict(REMOVE_GROUP_ARGS, **{"dry_run": True}))
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -527,7 +526,7 @@ def test_snapshot_attribute():
|
||||
).should_not.throw(EC2ResponseError)
|
||||
|
||||
# Error: Add with group != 'all'
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.modify_snapshot_attribute(
|
||||
snapshot.id,
|
||||
attribute="createVolumePermission",
|
||||
@ -539,7 +538,7 @@ def test_snapshot_attribute():
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Add with invalid snapshot ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.modify_snapshot_attribute(
|
||||
"snapshot-abcd1234",
|
||||
attribute="createVolumePermission",
|
||||
@ -551,7 +550,7 @@ def test_snapshot_attribute():
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Remove with invalid snapshot ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.modify_snapshot_attribute(
|
||||
"snapshot-abcd1234",
|
||||
attribute="createVolumePermission",
|
||||
@ -740,7 +739,7 @@ def test_create_volume_from_snapshot():
|
||||
volume = conn.create_volume(80, "us-east-1a")
|
||||
snapshot = volume.create_snapshot("a test snapshot")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
snapshot = volume.create_snapshot("a test snapshot", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -786,7 +785,7 @@ def test_modify_attribute_blockDeviceMapping():
|
||||
|
||||
instance = reservation.instances[0]
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.modify_attribute(
|
||||
"blockDeviceMapping", {"/dev/sda1": True}, dry_run=True
|
||||
)
|
||||
@ -809,7 +808,7 @@ def test_volume_tag_escaping():
|
||||
vol = conn.create_volume(10, "us-east-1a")
|
||||
snapshot = conn.create_snapshot(vol.id, "Desc")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
snapshot.add_tags({"key": "</closed>"}, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -879,7 +878,7 @@ def test_copy_snapshot():
|
||||
getattr(source, attrib).should.equal(getattr(dest, attrib))
|
||||
|
||||
# Copy from non-existent source ID.
|
||||
with assert_raises(ClientError) as cm:
|
||||
with pytest.raises(ClientError) as cm:
|
||||
create_snapshot_error = ec2_client.create_snapshot(VolumeId="vol-abcd1234")
|
||||
cm.exception.response["Error"]["Code"].should.equal("InvalidVolume.NotFound")
|
||||
cm.exception.response["Error"]["Message"].should.equal(
|
||||
@ -889,7 +888,7 @@ def test_copy_snapshot():
|
||||
cm.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
|
||||
# Copy from non-existent source region.
|
||||
with assert_raises(ClientError) as cm:
|
||||
with pytest.raises(ClientError) as cm:
|
||||
copy_snapshot_response = dest_ec2_client.copy_snapshot(
|
||||
SourceSnapshotId=create_snapshot_response["SnapshotId"],
|
||||
SourceRegion="eu-west-2",
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto
|
||||
import boto3
|
||||
@ -21,7 +20,7 @@ def test_eip_allocate_classic():
|
||||
"""Allocate/release Classic EIP"""
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
standard = conn.allocate_address(dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -35,7 +34,7 @@ def test_eip_allocate_classic():
|
||||
standard.instance_id.should.be.none
|
||||
standard.domain.should.be.equal("standard")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
standard.release(dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -52,7 +51,7 @@ def test_eip_allocate_vpc():
|
||||
"""Allocate/release VPC EIP"""
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
vpc = conn.allocate_address(domain="vpc", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -84,7 +83,7 @@ def test_eip_allocate_invalid_domain():
|
||||
"""Allocate EIP invalid domain"""
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.allocate_address(domain="bogus")
|
||||
cm.exception.code.should.equal("InvalidParameterValue")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -102,13 +101,13 @@ def test_eip_associate_classic():
|
||||
eip = conn.allocate_address()
|
||||
eip.instance_id.should.be.none
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.associate_address(public_ip=eip.public_ip)
|
||||
cm.exception.code.should.equal("MissingParameter")
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.associate_address(
|
||||
instance_id=instance.id, public_ip=eip.public_ip, dry_run=True
|
||||
)
|
||||
@ -123,7 +122,7 @@ def test_eip_associate_classic():
|
||||
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
|
||||
eip.instance_id.should.be.equal(instance.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.disassociate_address(public_ip=eip.public_ip, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -153,7 +152,7 @@ def test_eip_associate_vpc():
|
||||
eip = conn.allocate_address(domain="vpc")
|
||||
eip.instance_id.should.be.none
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.associate_address(allocation_id=eip.allocation_id)
|
||||
cm.exception.code.should.equal("MissingParameter")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -169,7 +168,7 @@ def test_eip_associate_vpc():
|
||||
eip.instance_id.should.be.equal("")
|
||||
eip.association_id.should.be.none
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
eip.release(dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -241,7 +240,7 @@ def test_eip_associate_network_interface():
|
||||
eip = conn.allocate_address(domain="vpc")
|
||||
eip.network_interface_id.should.be.none
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.associate_address(network_interface_id=eni.id)
|
||||
cm.exception.code.should.equal("MissingParameter")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -276,7 +275,7 @@ def test_eip_reassociate():
|
||||
conn.associate_address(instance_id=instance1.id, public_ip=eip.public_ip)
|
||||
|
||||
# Different ID detects resource association
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.associate_address(
|
||||
instance_id=instance2.id, public_ip=eip.public_ip, allow_reassociation=False
|
||||
)
|
||||
@ -312,7 +311,7 @@ def test_eip_reassociate_nic():
|
||||
conn.associate_address(network_interface_id=eni1.id, public_ip=eip.public_ip)
|
||||
|
||||
# Different ID detects resource association
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.associate_address(network_interface_id=eni2.id, public_ip=eip.public_ip)
|
||||
cm.exception.code.should.equal("Resource.AlreadyAssociated")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -336,7 +335,7 @@ def test_eip_associate_invalid_args():
|
||||
|
||||
eip = conn.allocate_address()
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.associate_address(instance_id=instance.id)
|
||||
cm.exception.code.should.equal("MissingParameter")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -350,7 +349,7 @@ def test_eip_disassociate_bogus_association():
|
||||
"""Disassociate bogus EIP"""
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.disassociate_address(association_id="bogus")
|
||||
cm.exception.code.should.equal("InvalidAssociationID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -362,7 +361,7 @@ def test_eip_release_bogus_eip():
|
||||
"""Release bogus EIP"""
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.release_address(allocation_id="bogus")
|
||||
cm.exception.code.should.equal("InvalidAllocationID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -374,7 +373,7 @@ def test_eip_disassociate_arg_error():
|
||||
"""Invalid arguments disassociate address"""
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.disassociate_address()
|
||||
cm.exception.code.should.equal("MissingParameter")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -386,7 +385,7 @@ def test_eip_release_arg_error():
|
||||
"""Invalid arguments release address"""
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.release_address()
|
||||
cm.exception.code.should.equal("MissingParameter")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -438,7 +437,7 @@ def test_eip_describe_none():
|
||||
"""Error when search for bogus IP"""
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_addresses(addresses=["256.256.256.256"])
|
||||
cm.exception.code.should.equal("InvalidAddress.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
@ -21,7 +20,7 @@ def test_elastic_network_interfaces():
|
||||
vpc = conn.create_vpc("10.0.0.0/16")
|
||||
subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
eni = conn.create_network_interface(subnet.id, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -38,7 +37,7 @@ def test_elastic_network_interfaces():
|
||||
eni.private_ip_addresses.should.have.length_of(1)
|
||||
eni.private_ip_addresses[0].private_ip_address.startswith("10.").should.be.true
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.delete_network_interface(eni.id, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -51,7 +50,7 @@ def test_elastic_network_interfaces():
|
||||
all_enis = conn.get_all_network_interfaces()
|
||||
all_enis.should.have.length_of(0)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_network_interface(eni.id)
|
||||
cm.exception.error_code.should.equal("InvalidNetworkInterfaceID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -62,7 +61,7 @@ def test_elastic_network_interfaces():
|
||||
def test_elastic_network_interfaces_subnet_validation():
|
||||
conn = boto.connect_vpc("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_network_interface("subnet-abcd1234")
|
||||
cm.exception.error_code.should.equal("InvalidSubnetID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -133,7 +132,7 @@ def test_elastic_network_interfaces_modify_attribute():
|
||||
eni.groups.should.have.length_of(1)
|
||||
eni.groups[0].id.should.equal(security_group1.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.modify_network_interface_attribute(
|
||||
eni.id, "groupset", [security_group2.id], dry_run=True
|
||||
)
|
||||
@ -228,7 +227,7 @@ def test_elastic_network_interfaces_get_by_tag_name():
|
||||
SubnetId=subnet.id, PrivateIpAddress="10.0.10.5"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
eni1.create_tags(Tags=[{"Key": "Name", "Value": "eni1"}], DryRun=True)
|
||||
ex.exception.response["Error"]["Code"].should.equal("DryRunOperation")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
|
@ -1,7 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import tests.backport_assert_raises # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto3
|
||||
|
||||
@ -36,7 +35,7 @@ def test_create_flow_logs_s3():
|
||||
CreateBucketConfiguration={"LocationConstraint": "us-west-1"},
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_flow_logs(
|
||||
ResourceType="VPC",
|
||||
ResourceIds=[vpc["VpcId"]],
|
||||
@ -87,7 +86,7 @@ def test_create_flow_logs_cloud_watch():
|
||||
vpc = client.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"]
|
||||
logs_client.create_log_group(logGroupName="test-group")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_flow_logs(
|
||||
ResourceType="VPC",
|
||||
ResourceIds=[vpc["VpcId"]],
|
||||
@ -243,7 +242,7 @@ def test_delete_flow_logs_delete_many():
|
||||
def test_delete_flow_logs_non_existing():
|
||||
client = boto3.client("ec2", region_name="us-west-1")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.delete_flow_logs(FlowLogIds=["fl-1a2b3c4d"])
|
||||
ex.exception.response["Error"]["Code"].should.equal("InvalidFlowLogId.NotFound")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
@ -251,7 +250,7 @@ def test_delete_flow_logs_non_existing():
|
||||
"These flow log ids in the input list are not found: [TotalCount: 1] fl-1a2b3c4d"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.delete_flow_logs(FlowLogIds=["fl-1a2b3c4d", "fl-2b3c4d5e"])
|
||||
ex.exception.response["Error"]["Code"].should.equal("InvalidFlowLogId.NotFound")
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
@ -304,7 +303,7 @@ def test_create_flow_logs_invalid_parameters():
|
||||
CreateBucketConfiguration={"LocationConstraint": "us-west-1"},
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_flow_logs(
|
||||
ResourceType="VPC",
|
||||
ResourceIds=[vpc["VpcId"]],
|
||||
@ -319,7 +318,7 @@ def test_create_flow_logs_invalid_parameters():
|
||||
"Invalid Flow Log Max Aggregation Interval"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_flow_logs(
|
||||
ResourceType="VPC",
|
||||
ResourceIds=[vpc["VpcId"]],
|
||||
@ -332,7 +331,7 @@ def test_create_flow_logs_invalid_parameters():
|
||||
"LogDestination can't be empty if LogGroupName is not provided."
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_flow_logs(
|
||||
ResourceType="VPC",
|
||||
ResourceIds=[vpc["VpcId"]],
|
||||
@ -346,7 +345,7 @@ def test_create_flow_logs_invalid_parameters():
|
||||
"LogDestination type must be cloud-watch-logs if LogGroupName is provided."
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_flow_logs(
|
||||
ResourceType="VPC",
|
||||
ResourceIds=[vpc["VpcId"]],
|
||||
@ -368,7 +367,7 @@ def test_create_flow_logs_invalid_parameters():
|
||||
)["FlowLogIds"]
|
||||
response.should.have.length_of(1)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_flow_logs(
|
||||
ResourceType="VPC",
|
||||
ResourceIds=[vpc["VpcId"]],
|
||||
@ -391,7 +390,7 @@ def test_create_flow_logs_invalid_parameters():
|
||||
)["FlowLogIds"]
|
||||
response.should.have.length_of(1)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_flow_logs(
|
||||
ResourceType="VPC",
|
||||
ResourceIds=[vpc["VpcId"]],
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto
|
||||
import boto3
|
||||
@ -25,7 +24,7 @@ def test_console_output():
|
||||
def test_console_output_without_instance():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_console_output("i-1234abcd")
|
||||
cm.exception.code.should.equal("InvalidInstanceID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
|
@ -3,8 +3,7 @@ from __future__ import unicode_literals
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import base64
|
||||
import ipaddress
|
||||
@ -52,7 +51,7 @@ def test_add_servers():
|
||||
def test_instance_launch_and_terminate():
|
||||
conn = boto.ec2.connect_to_region("us-east-1")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
reservation = conn.run_instances("ami-1234abcd", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -87,7 +86,7 @@ def test_instance_launch_and_terminate():
|
||||
volume.attach_data.instance_id.should.equal(instance.id)
|
||||
volume.status.should.equal("in-use")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.terminate_instances([instance.id], dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -290,7 +289,7 @@ def test_get_instances_by_id():
|
||||
instance_ids.should.equal([instance1.id, instance2.id])
|
||||
|
||||
# Call get_all_instances with a bad id should raise an error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_instances(instance_ids=[instance1.id, "i-1234abcd"])
|
||||
cm.exception.code.should.equal("InvalidInstanceID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -743,7 +742,7 @@ def test_instance_start_and_stop():
|
||||
|
||||
instance_ids = [instance.id for instance in instances]
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
stopped_instances = conn.stop_instances(instance_ids, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -756,7 +755,7 @@ def test_instance_start_and_stop():
|
||||
for instance in stopped_instances:
|
||||
instance.state.should.equal("stopping")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
started_instances = conn.start_instances([instances[0].id], dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -774,7 +773,7 @@ def test_instance_reboot():
|
||||
reservation = conn.run_instances("ami-1234abcd")
|
||||
instance = reservation.instances[0]
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.reboot(dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -792,7 +791,7 @@ def test_instance_attribute_instance_type():
|
||||
reservation = conn.run_instances("ami-1234abcd")
|
||||
instance = reservation.instances[0]
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.modify_attribute("instanceType", "m1.small", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -820,7 +819,7 @@ def test_modify_instance_attribute_security_groups():
|
||||
"test security group 2", "this is a test security group 2"
|
||||
).id
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.modify_attribute("groupSet", [sg_id, sg_id2], dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -843,7 +842,7 @@ def test_instance_attribute_user_data():
|
||||
reservation = conn.run_instances("ami-1234abcd")
|
||||
instance = reservation.instances[0]
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.modify_attribute("userData", "this is my user data", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -873,7 +872,7 @@ def test_instance_attribute_source_dest_check():
|
||||
|
||||
# Set to false (note: Boto converts bool to string, eg 'false')
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.modify_attribute("sourceDestCheck", False, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -919,7 +918,7 @@ def test_user_data_with_run_instance():
|
||||
def test_run_instance_with_security_group_name():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
group = conn.create_security_group("group1", "some description", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -1196,7 +1195,7 @@ def test_instance_with_nic_attach_detach():
|
||||
set([group.id for group in eni.groups]).should.equal(set([security_group2.id]))
|
||||
|
||||
# Attach
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.attach_network_interface(eni.id, instance.id, device_index=1, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -1223,7 +1222,7 @@ def test_instance_with_nic_attach_detach():
|
||||
)
|
||||
|
||||
# Detach
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.detach_network_interface(instance_eni.attachment.id, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -1242,7 +1241,7 @@ def test_instance_with_nic_attach_detach():
|
||||
set([group.id for group in eni.groups]).should.equal(set([security_group2.id]))
|
||||
|
||||
# Detach with invalid attachment ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.detach_network_interface("eni-attach-1234abcd")
|
||||
cm.exception.code.should.equal("InvalidAttachmentID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -1410,7 +1409,7 @@ def test_describe_instance_status_with_instance_filter_deprecated():
|
||||
all_status[0].id.should.equal(instance.id)
|
||||
|
||||
# Call get_all_instance_status with a bad id should raise an error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_instance_status(instance_ids=[instance.id, "i-1234abcd"])
|
||||
cm.exception.code.should.equal("InvalidInstanceID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -1537,7 +1536,7 @@ def test_get_instance_by_security_group():
|
||||
|
||||
security_group = conn.create_security_group("test", "test")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.modify_instance_attribute(
|
||||
instance.id, "groupSet", [security_group.id], dry_run=True
|
||||
)
|
||||
@ -1661,7 +1660,7 @@ def test_describe_instance_attribute():
|
||||
]
|
||||
|
||||
for invalid_instance_attribute in invalid_instance_attributes:
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.describe_instance_attribute(
|
||||
InstanceId=instance_id, Attribute=invalid_instance_attribute
|
||||
)
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import re
|
||||
|
||||
@ -28,7 +27,7 @@ def test_igw_create():
|
||||
|
||||
conn.get_all_internet_gateways().should.have.length_of(0)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
igw = conn.create_internet_gateway(dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -51,7 +50,7 @@ def test_igw_attach():
|
||||
igw = conn.create_internet_gateway()
|
||||
vpc = conn.create_vpc(VPC_CIDR)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.attach_internet_gateway(igw.id, vpc.id, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -71,7 +70,7 @@ def test_igw_attach_bad_vpc():
|
||||
conn = boto.connect_vpc("the_key", "the_secret")
|
||||
igw = conn.create_internet_gateway()
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.attach_internet_gateway(igw.id, BAD_VPC)
|
||||
cm.exception.code.should.equal("InvalidVpcID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -87,7 +86,7 @@ def test_igw_attach_twice():
|
||||
vpc2 = conn.create_vpc(VPC_CIDR)
|
||||
conn.attach_internet_gateway(igw.id, vpc1.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.attach_internet_gateway(igw.id, vpc2.id)
|
||||
cm.exception.code.should.equal("Resource.AlreadyAssociated")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -102,7 +101,7 @@ def test_igw_detach():
|
||||
vpc = conn.create_vpc(VPC_CIDR)
|
||||
conn.attach_internet_gateway(igw.id, vpc.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.detach_internet_gateway(igw.id, vpc.id, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -124,7 +123,7 @@ def test_igw_detach_wrong_vpc():
|
||||
vpc2 = conn.create_vpc(VPC_CIDR)
|
||||
conn.attach_internet_gateway(igw.id, vpc1.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.detach_internet_gateway(igw.id, vpc2.id)
|
||||
cm.exception.code.should.equal("Gateway.NotAttached")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -139,7 +138,7 @@ def test_igw_detach_invalid_vpc():
|
||||
vpc = conn.create_vpc(VPC_CIDR)
|
||||
conn.attach_internet_gateway(igw.id, vpc.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.detach_internet_gateway(igw.id, BAD_VPC)
|
||||
cm.exception.code.should.equal("Gateway.NotAttached")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -153,7 +152,7 @@ def test_igw_detach_unattached():
|
||||
igw = conn.create_internet_gateway()
|
||||
vpc = conn.create_vpc(VPC_CIDR)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.detach_internet_gateway(igw.id, vpc.id)
|
||||
cm.exception.code.should.equal("Gateway.NotAttached")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -169,7 +168,7 @@ def test_igw_delete():
|
||||
igw = conn.create_internet_gateway()
|
||||
conn.get_all_internet_gateways().should.have.length_of(1)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.delete_internet_gateway(igw.id, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -189,7 +188,7 @@ def test_igw_delete_attached():
|
||||
vpc = conn.create_vpc(VPC_CIDR)
|
||||
conn.attach_internet_gateway(igw.id, vpc.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_internet_gateway(igw.id)
|
||||
cm.exception.code.should.equal("DependencyViolation")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -209,7 +208,7 @@ def test_igw_desribe():
|
||||
def test_igw_describe_bad_id():
|
||||
""" internet gateway fail to fetch by bad id """
|
||||
conn = boto.connect_vpc("the_key", "the_secret")
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_internet_gateways([BAD_IGW])
|
||||
cm.exception.code.should.equal("InvalidInternetGatewayID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto
|
||||
import sure # noqa
|
||||
@ -56,7 +55,7 @@ def test_key_pairs_empty():
|
||||
def test_key_pairs_invalid_id():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_key_pairs("foo")
|
||||
cm.exception.code.should.equal("InvalidKeyPair.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -67,7 +66,7 @@ def test_key_pairs_invalid_id():
|
||||
def test_key_pairs_create():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.create_key_pair("foo", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -110,7 +109,7 @@ def test_key_pairs_create_exist():
|
||||
conn.create_key_pair("foo")
|
||||
assert len(conn.get_all_key_pairs()) == 1
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_key_pair("foo")
|
||||
cm.exception.code.should.equal("InvalidKeyPair.Duplicate")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -130,7 +129,7 @@ def test_key_pairs_delete_exist():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
conn.create_key_pair("foo")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
r = conn.delete_key_pair("foo", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -147,7 +146,7 @@ def test_key_pairs_delete_exist():
|
||||
def test_key_pairs_import():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.import_key_pair("foo", RSA_PUBLIC_KEY_OPENSSH, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -176,7 +175,7 @@ def test_key_pairs_import_exist():
|
||||
assert kp.name == "foo"
|
||||
assert len(conn.get_all_key_pairs()) == 1
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_key_pair("foo")
|
||||
cm.exception.code.should.equal("InvalidKeyPair.Duplicate")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -187,19 +186,19 @@ def test_key_pairs_import_exist():
|
||||
def test_key_pairs_invalid():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.import_key_pair("foo", b"")
|
||||
ex.exception.error_code.should.equal("InvalidKeyPair.Format")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal("Key is not in valid OpenSSH public key format")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.import_key_pair("foo", b"garbage")
|
||||
ex.exception.error_code.should.equal("InvalidKeyPair.Format")
|
||||
ex.exception.status.should.equal(400)
|
||||
ex.exception.message.should.equal("Key is not in valid OpenSSH public key format")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.import_key_pair("foo", DSA_PUBLIC_KEY_OPENSSH)
|
||||
ex.exception.error_code.should.equal("InvalidKeyPair.Format")
|
||||
ex.exception.status.should.equal(400)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import boto3
|
||||
import sure # noqa
|
||||
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from botocore.client import ClientError
|
||||
|
||||
from moto import mock_ec2
|
||||
@ -30,7 +30,7 @@ def test_launch_template_create():
|
||||
lt["DefaultVersionNumber"].should.equal(1)
|
||||
lt["LatestVersionNumber"].should.equal(1)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
cli.create_launch_template(
|
||||
LaunchTemplateName="test-template",
|
||||
LaunchTemplateData={
|
||||
|
@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||
import boto
|
||||
import boto3
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
from moto import mock_ec2_deprecated, mock_ec2
|
||||
@ -261,7 +261,7 @@ def test_duplicate_network_acl_entry():
|
||||
RuleNumber=rule_number,
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
default_network_acl.create_entry(
|
||||
CidrBlock="10.0.0.0/0",
|
||||
Egress=egress,
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto
|
||||
import boto3
|
||||
@ -61,7 +60,7 @@ def test_route_tables_additional():
|
||||
local_route.state.should.equal("active")
|
||||
local_route.destination_cidr_block.should.equal(vpc.cidr_block)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_vpc(vpc.id)
|
||||
cm.exception.code.should.equal("DependencyViolation")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -72,7 +71,7 @@ def test_route_tables_additional():
|
||||
all_route_tables = conn.get_all_route_tables(filters={"vpc-id": vpc.id})
|
||||
all_route_tables.should.have.length_of(1)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_route_table("rtb-1234abcd")
|
||||
cm.exception.code.should.equal("InvalidRouteTableID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -197,7 +196,7 @@ def test_route_table_associations():
|
||||
association_id_idempotent.should.equal(association_id)
|
||||
|
||||
# Error: Attempt delete associated route table.
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_route_table(route_table.id)
|
||||
cm.exception.code.should.equal("DependencyViolation")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -211,21 +210,21 @@ def test_route_table_associations():
|
||||
route_table.associations.should.have.length_of(0)
|
||||
|
||||
# Error: Disassociate with invalid association ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.disassociate_route_table(association_id)
|
||||
cm.exception.code.should.equal("InvalidAssociationID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Associate with invalid subnet ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.associate_route_table(route_table.id, "subnet-1234abcd")
|
||||
cm.exception.code.should.equal("InvalidSubnetID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Associate with invalid route table ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.associate_route_table("rtb-1234abcd", subnet.id)
|
||||
cm.exception.code.should.equal("InvalidRouteTableID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -293,7 +292,7 @@ def test_route_table_replace_route_table_association():
|
||||
association_id_idempotent.should.equal(association_id2)
|
||||
|
||||
# Error: Replace association with invalid association ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.replace_route_table_association_with_assoc(
|
||||
"rtbassoc-1234abcd", route_table1.id
|
||||
)
|
||||
@ -302,7 +301,7 @@ def test_route_table_replace_route_table_association():
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Error: Replace association with invalid route table ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.replace_route_table_association_with_assoc(association_id2, "rtb-1234abcd")
|
||||
cm.exception.code.should.equal("InvalidRouteTableID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -389,7 +388,7 @@ def test_routes_additional():
|
||||
]
|
||||
new_routes.should.have.length_of(0)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_route(main_route_table.id, ROUTE_CIDR)
|
||||
cm.exception.code.should.equal("InvalidRoute.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -442,7 +441,7 @@ def test_routes_replace():
|
||||
target_route.state.should.equal("active")
|
||||
target_route.destination_cidr_block.should.equal(ROUTE_CIDR)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.replace_route("rtb-1234abcd", ROUTE_CIDR, gateway_id=igw.id)
|
||||
cm.exception.code.should.equal("InvalidRouteTableID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -571,7 +570,7 @@ def test_create_route_with_invalid_destination_cidr_block_parameter():
|
||||
internet_gateway.reload()
|
||||
|
||||
destination_cidr_block = "1000.1.0.0/20"
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
route = route_table.create_route(
|
||||
DestinationCidrBlock=destination_cidr_block, GatewayId=internet_gateway.id
|
||||
)
|
||||
|
@ -4,8 +4,7 @@ import copy
|
||||
import json
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto3
|
||||
import boto
|
||||
@ -20,7 +19,7 @@ from moto import mock_ec2, mock_ec2_deprecated
|
||||
def test_create_and_describe_security_group():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
security_group = conn.create_security_group(
|
||||
"test security group", "this is a test security group", dry_run=True
|
||||
)
|
||||
@ -38,7 +37,7 @@ def test_create_and_describe_security_group():
|
||||
security_group.description.should.equal("this is a test security group")
|
||||
|
||||
# Trying to create another group with the same name should throw an error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_security_group(
|
||||
"test security group", "this is a test security group"
|
||||
)
|
||||
@ -57,7 +56,7 @@ def test_create_and_describe_security_group():
|
||||
def test_create_security_group_without_description_raises_error():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_security_group("test security group", "")
|
||||
cm.exception.code.should.equal("MissingParameter")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -87,7 +86,7 @@ def test_create_and_describe_vpc_security_group():
|
||||
|
||||
# Trying to create another group with the same name in the same VPC should
|
||||
# throw an error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_security_group(
|
||||
"test security group", "this is a test security group", vpc_id
|
||||
)
|
||||
@ -146,14 +145,14 @@ def test_deleting_security_groups():
|
||||
conn.get_all_security_groups().should.have.length_of(4)
|
||||
|
||||
# Deleting a group that doesn't exist should throw an error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_security_group("foobar")
|
||||
cm.exception.code.should.equal("InvalidGroup.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Delete by name
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.delete_security_group("test2", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -184,7 +183,7 @@ def test_authorize_ip_range_and_revoke():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
security_group = conn.create_security_group("test", "test")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
success = security_group.authorize(
|
||||
ip_protocol="tcp",
|
||||
from_port="22",
|
||||
@ -208,7 +207,7 @@ def test_authorize_ip_range_and_revoke():
|
||||
security_group.rules[0].grants[0].cidr_ip.should.equal("123.123.123.123/32")
|
||||
|
||||
# Wrong Cidr should throw error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
security_group.revoke(
|
||||
ip_protocol="tcp",
|
||||
from_port="22",
|
||||
@ -220,7 +219,7 @@ def test_authorize_ip_range_and_revoke():
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Actually revoke
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
security_group.revoke(
|
||||
ip_protocol="tcp",
|
||||
from_port="22",
|
||||
@ -246,7 +245,7 @@ def test_authorize_ip_range_and_revoke():
|
||||
"testegress", "testegress", vpc_id="vpc-3432589"
|
||||
)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
success = conn.authorize_security_group_egress(
|
||||
egress_security_group.id,
|
||||
"tcp",
|
||||
@ -285,7 +284,7 @@ def test_authorize_ip_range_and_revoke():
|
||||
).should.throw(EC2ResponseError)
|
||||
|
||||
# Actually revoke
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.revoke_security_group_egress(
|
||||
egress_security_group.id,
|
||||
"tcp",
|
||||
@ -335,7 +334,7 @@ def test_authorize_other_group_and_revoke():
|
||||
security_group.rules[0].grants[0].group_id.should.equal(other_security_group.id)
|
||||
|
||||
# Wrong source group should throw error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
security_group.revoke(
|
||||
ip_protocol="tcp", from_port="22", to_port="2222", src_group=wrong_group
|
||||
)
|
||||
@ -440,7 +439,7 @@ def test_get_all_security_groups():
|
||||
resp.should.have.length_of(1)
|
||||
resp[0].id.should.equal(sg1.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_security_groups(groupnames=["does_not_exist"])
|
||||
cm.exception.code.should.equal("InvalidGroup.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -469,7 +468,7 @@ def test_get_all_security_groups():
|
||||
def test_authorize_bad_cidr_throws_invalid_parameter_value():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
security_group = conn.create_security_group("test", "test")
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
security_group.authorize(
|
||||
ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123"
|
||||
)
|
||||
@ -485,7 +484,7 @@ def test_security_group_tagging():
|
||||
|
||||
sg = conn.create_security_group("test-sg", "Test SG", vpc.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
sg.add_tag("Test", "Tag", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -534,7 +533,7 @@ def test_sec_group_rule_limit():
|
||||
other_sg = ec2_conn.create_security_group("test_2", "test_other")
|
||||
|
||||
# INGRESS
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group(
|
||||
group_id=sg.id,
|
||||
ip_protocol="-1",
|
||||
@ -556,13 +555,13 @@ def test_sec_group_rule_limit():
|
||||
)
|
||||
success.should.be.true
|
||||
# verify that we cannot authorize past the limit for a CIDR IP
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group(
|
||||
group_id=sg.id, ip_protocol="-1", cidr_ip=["100.0.0.0/0"]
|
||||
)
|
||||
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
|
||||
# verify that we cannot authorize past the limit for a different sec group
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group(
|
||||
group_id=sg.id, ip_protocol="-1", src_security_group_group_id=other_sg.id
|
||||
)
|
||||
@ -581,13 +580,13 @@ def test_sec_group_rule_limit():
|
||||
group_id=sg.id, ip_protocol="-1", cidr_ip="{0}.0.0.0/0".format(i)
|
||||
)
|
||||
# verify that we cannot authorize past the limit for a CIDR IP
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group_egress(
|
||||
group_id=sg.id, ip_protocol="-1", cidr_ip="101.0.0.0/0"
|
||||
)
|
||||
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
|
||||
# verify that we cannot authorize past the limit for a different sec group
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group_egress(
|
||||
group_id=sg.id, ip_protocol="-1", src_group_id=other_sg.id
|
||||
)
|
||||
@ -605,7 +604,7 @@ def test_sec_group_rule_limit_vpc():
|
||||
other_sg = ec2_conn.create_security_group("test_2", "test", vpc_id=vpc.id)
|
||||
|
||||
# INGRESS
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group(
|
||||
group_id=sg.id,
|
||||
ip_protocol="-1",
|
||||
@ -627,13 +626,13 @@ def test_sec_group_rule_limit_vpc():
|
||||
)
|
||||
# verify that we cannot authorize past the limit for a CIDR IP
|
||||
success.should.be.true
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group(
|
||||
group_id=sg.id, ip_protocol="-1", cidr_ip=["100.0.0.0/0"]
|
||||
)
|
||||
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
|
||||
# verify that we cannot authorize past the limit for a different sec group
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group(
|
||||
group_id=sg.id, ip_protocol="-1", src_security_group_group_id=other_sg.id
|
||||
)
|
||||
@ -652,13 +651,13 @@ def test_sec_group_rule_limit_vpc():
|
||||
group_id=sg.id, ip_protocol="-1", cidr_ip="{0}.0.0.0/0".format(i)
|
||||
)
|
||||
# verify that we cannot authorize past the limit for a CIDR IP
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group_egress(
|
||||
group_id=sg.id, ip_protocol="-1", cidr_ip="50.0.0.0/0"
|
||||
)
|
||||
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
|
||||
# verify that we cannot authorize past the limit for a different sec group
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group_egress(
|
||||
group_id=sg.id, ip_protocol="-1", src_group_id=other_sg.id
|
||||
)
|
||||
@ -689,7 +688,7 @@ def test_add_same_rule_twice_throws_error():
|
||||
]
|
||||
sg.authorize_ingress(IpPermissions=ip_permissions)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
sg.authorize_ingress(IpPermissions=ip_permissions)
|
||||
|
||||
|
||||
@ -761,7 +760,7 @@ def test_security_group_tagging_boto3():
|
||||
|
||||
sg = conn.create_security_group(GroupName="test-sg", Description="Test SG")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
conn.create_tags(
|
||||
Resources=[sg["GroupId"]],
|
||||
Tags=[{"Key": "Test", "Value": "Tag"}],
|
||||
@ -926,7 +925,7 @@ def test_get_all_security_groups_filter_with_same_vpc_id():
|
||||
)
|
||||
security_groups.should.have.length_of(1)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_security_groups(group_ids=["does_not_exist"])
|
||||
cm.exception.code.should.equal("InvalidGroup.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
|
@ -1,5 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
import datetime
|
||||
|
||||
import boto
|
||||
@ -31,7 +31,7 @@ def test_request_spot_instances():
|
||||
start = iso_8601_datetime_with_milliseconds(start_dt)
|
||||
end = iso_8601_datetime_with_milliseconds(end_dt)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
request = conn.request_spot_instances(
|
||||
SpotPrice="0.5",
|
||||
InstanceCount=1,
|
||||
@ -155,7 +155,7 @@ def test_cancel_spot_instance_request():
|
||||
requests = conn.get_all_spot_instance_requests()
|
||||
requests.should.have.length_of(1)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.cancel_spot_instance_requests([requests[0].id], dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto3
|
||||
import boto
|
||||
@ -30,7 +29,7 @@ def test_subnets():
|
||||
all_subnets = conn.get_all_subnets()
|
||||
all_subnets.should.have.length_of(0 + len(ec2.get_all_zones()))
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_subnet(subnet.id)
|
||||
cm.exception.code.should.equal("InvalidSubnetID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -41,7 +40,7 @@ def test_subnets():
|
||||
def test_subnet_create_vpc_validation():
|
||||
conn = boto.connect_vpc("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_subnet("vpc-abcd1234", "10.0.0.0/18")
|
||||
cm.exception.code.should.equal("InvalidVpcID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -202,7 +201,7 @@ def test_modify_subnet_attribute_validation():
|
||||
VpcId=vpc.id, CidrBlock="10.0.0.0/24", AvailabilityZone="us-west-1a"
|
||||
)
|
||||
|
||||
with assert_raises(ParamValidationError):
|
||||
with pytest.raises(ParamValidationError):
|
||||
client.modify_subnet_attribute(
|
||||
SubnetId=subnet.id, MapPublicIpOnLaunch={"Value": "invalid"}
|
||||
)
|
||||
@ -228,7 +227,7 @@ def test_subnet_get_by_id():
|
||||
subnetA.id.should.be.within(subnets_by_id)
|
||||
subnetB1.id.should.be.within(subnets_by_id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_subnets(subnet_ids=["subnet-does_not_exist"])
|
||||
cm.exception.code.should.equal("InvalidSubnetID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -386,7 +385,7 @@ def test_create_subnet_with_invalid_availability_zone():
|
||||
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
|
||||
|
||||
subnet_availability_zone = "asfasfas"
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
subnet = client.create_subnet(
|
||||
VpcId=vpc.id,
|
||||
CidrBlock="10.0.0.0/24",
|
||||
@ -409,7 +408,7 @@ def test_create_subnet_with_invalid_cidr_range():
|
||||
vpc.is_default.shouldnt.be.ok
|
||||
|
||||
subnet_cidr_block = "10.1.0.0/20"
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock=subnet_cidr_block)
|
||||
str(ex.exception).should.equal(
|
||||
"An error occurred (InvalidSubnet.Range) when calling the CreateSubnet "
|
||||
@ -444,7 +443,7 @@ def test_create_subnet_with_invalid_cidr_block_parameter():
|
||||
vpc.is_default.shouldnt.be.ok
|
||||
|
||||
subnet_cidr_block = "1000.1.0.0/20"
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock=subnet_cidr_block)
|
||||
str(ex.exception).should.equal(
|
||||
"An error occurred (InvalidParameterValue) when calling the CreateSubnet "
|
||||
@ -503,7 +502,7 @@ def test_create_subnets_with_overlapping_cidr_blocks():
|
||||
vpc.is_default.shouldnt.be.ok
|
||||
|
||||
subnet_cidr_block = "10.0.0.0/24"
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
subnet1 = ec2.create_subnet(VpcId=vpc.id, CidrBlock=subnet_cidr_block)
|
||||
subnet2 = ec2.create_subnet(VpcId=vpc.id, CidrBlock=subnet_cidr_block)
|
||||
str(ex.exception).should.equal(
|
||||
|
@ -1,5 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import itertools
|
||||
|
||||
@ -11,7 +11,7 @@ from boto.ec2.instance import Reservation
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_ec2_deprecated, mock_ec2
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
@ -20,7 +20,7 @@ def test_add_tag():
|
||||
reservation = conn.run_instances("ami-1234abcd")
|
||||
instance = reservation.instances[0]
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.add_tag("a key", "some value", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -51,7 +51,7 @@ def test_remove_tag():
|
||||
tag.name.should.equal("a key")
|
||||
tag.value.should.equal("some value")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
instance.remove_tag("a key", dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -106,7 +106,7 @@ def test_create_tags():
|
||||
"blank key": "",
|
||||
}
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.create_tags(instance.id, tag_dict, dry_run=True)
|
||||
ex.exception.error_code.should.equal("DryRunOperation")
|
||||
ex.exception.status.should.equal(400)
|
||||
@ -131,14 +131,14 @@ def test_tag_limit_exceeded():
|
||||
for i in range(51):
|
||||
tag_dict["{0:02d}".format(i + 1)] = ""
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_tags(instance.id, tag_dict)
|
||||
cm.exception.code.should.equal("TagLimitExceeded")
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
instance.add_tag("a key", "a value")
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_tags(instance.id, tag_dict)
|
||||
cm.exception.code.should.equal("TagLimitExceeded")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -157,7 +157,7 @@ def test_invalid_parameter_tag_null():
|
||||
reservation = conn.run_instances("ami-1234abcd")
|
||||
instance = reservation.instances[0]
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
instance.add_tag("a key", None)
|
||||
cm.exception.code.should.equal("InvalidParameterValue")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -167,13 +167,13 @@ def test_invalid_parameter_tag_null():
|
||||
@mock_ec2_deprecated
|
||||
def test_invalid_id():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_tags("ami-blah", {"key": "tag"})
|
||||
cm.exception.code.should.equal("InvalidID")
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_tags("blah-blah", {"key": "tag"})
|
||||
cm.exception.code.should.equal("InvalidID")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -449,7 +449,7 @@ def test_create_tag_empty_resource():
|
||||
# create ec2 client in us-west-1
|
||||
client = boto3.client("ec2", region_name="us-west-1")
|
||||
# create tag with empty resource
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.create_tags(Resources=[], Tags=[{"Key": "Value"}])
|
||||
ex.exception.response["Error"]["Code"].should.equal("MissingParameter")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
@ -462,7 +462,7 @@ def test_delete_tag_empty_resource():
|
||||
# create ec2 client in us-west-1
|
||||
client = boto3.client("ec2", region_name="us-west-1")
|
||||
# delete tag with empty resource
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.delete_tags(Resources=[], Tags=[{"Key": "Value"}])
|
||||
ex.exception.response["Error"]["Code"].should.equal("MissingParameter")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from moto.ec2.exceptions import EC2ClientError
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
@ -49,7 +48,7 @@ def test_vpc_peering_connections_accept():
|
||||
vpc_pcx = conn.accept_vpc_peering_connection(vpc_pcx.id)
|
||||
vpc_pcx._status.code.should.equal("active")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.reject_vpc_peering_connection(vpc_pcx.id)
|
||||
cm.exception.code.should.equal("InvalidStateTransition")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -69,7 +68,7 @@ def test_vpc_peering_connections_reject():
|
||||
verdict = conn.reject_vpc_peering_connection(vpc_pcx.id)
|
||||
verdict.should.equal(True)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.accept_vpc_peering_connection(vpc_pcx.id)
|
||||
cm.exception.code.should.equal("InvalidStateTransition")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -93,7 +92,7 @@ def test_vpc_peering_connections_delete():
|
||||
all_vpc_pcxs.should.have.length_of(1)
|
||||
all_vpc_pcxs[0]._status.code.should.equal("deleted")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_vpc_peering_connection("pcx-1234abcd")
|
||||
cm.exception.code.should.equal("InvalidVpcPeeringConnectionId.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -129,7 +128,7 @@ def test_vpc_peering_connections_cross_region_fail():
|
||||
ec2_apn1 = boto3.resource("ec2", region_name="ap-northeast-1")
|
||||
vpc_apn1 = ec2_apn1.create_vpc(CidrBlock="10.20.0.0/16")
|
||||
# create peering wrong region with no vpc
|
||||
with assert_raises(ClientError) as cm:
|
||||
with pytest.raises(ClientError) as cm:
|
||||
ec2_usw1.create_vpc_peering_connection(
|
||||
VpcId=vpc_usw1.id, PeerVpcId=vpc_apn1.id, PeerRegion="ap-northeast-2"
|
||||
)
|
||||
@ -253,7 +252,7 @@ def test_vpc_peering_connections_cross_region_accept_wrong_region():
|
||||
# accept wrong peering from us-west-1 which will raise error
|
||||
ec2_apn1 = boto3.client("ec2", region_name="ap-northeast-1")
|
||||
ec2_usw1 = boto3.client("ec2", region_name="us-west-1")
|
||||
with assert_raises(ClientError) as cm:
|
||||
with pytest.raises(ClientError) as cm:
|
||||
ec2_usw1.accept_vpc_peering_connection(VpcPeeringConnectionId=vpc_pcx_usw1.id)
|
||||
cm.exception.response["Error"]["Code"].should.equal("OperationNotPermitted")
|
||||
exp_msg = (
|
||||
@ -278,7 +277,7 @@ def test_vpc_peering_connections_cross_region_reject_wrong_region():
|
||||
# reject wrong peering from us-west-1 which will raise error
|
||||
ec2_apn1 = boto3.client("ec2", region_name="ap-northeast-1")
|
||||
ec2_usw1 = boto3.client("ec2", region_name="us-west-1")
|
||||
with assert_raises(ClientError) as cm:
|
||||
with pytest.raises(ClientError) as cm:
|
||||
ec2_usw1.reject_vpc_peering_connection(VpcPeeringConnectionId=vpc_pcx_usw1.id)
|
||||
cm.exception.response["Error"]["Code"].should.equal("OperationNotPermitted")
|
||||
exp_msg = (
|
||||
|
@ -1,8 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from moto.ec2.exceptions import EC2ClientError
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
@ -31,7 +30,7 @@ def test_vpcs():
|
||||
all_vpcs = conn.get_all_vpcs()
|
||||
all_vpcs.should.have.length_of(1)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.delete_vpc("vpc-1234abcd")
|
||||
cm.exception.code.should.equal("InvalidVpcID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -114,7 +113,7 @@ def test_vpc_get_by_id():
|
||||
vpc1.id.should.be.within(vpc_ids)
|
||||
vpc2.id.should.be.within(vpc_ids)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.get_all_vpcs(vpc_ids=["vpc-does_not_exist"])
|
||||
cm.exception.code.should.equal("InvalidVpcID.NotFound")
|
||||
cm.exception.status.should.equal(400)
|
||||
@ -402,7 +401,7 @@ def test_associate_vpc_ipv4_cidr_block():
|
||||
)
|
||||
|
||||
# Check error on adding 6th association.
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
response = ec2.meta.client.associate_vpc_cidr_block(
|
||||
VpcId=vpc.id, CidrBlock="10.10.50.0/22"
|
||||
)
|
||||
@ -447,7 +446,7 @@ def test_disassociate_vpc_ipv4_cidr_block():
|
||||
)
|
||||
|
||||
# Error attempting to delete a non-existent CIDR_BLOCK association
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
response = ec2.meta.client.disassociate_vpc_cidr_block(
|
||||
AssociationId="vpc-cidr-assoc-BORING123"
|
||||
)
|
||||
@ -469,7 +468,7 @@ def test_disassociate_vpc_ipv4_cidr_block():
|
||||
{},
|
||||
)["AssociationId"]
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
response = ec2.meta.client.disassociate_vpc_cidr_block(
|
||||
AssociationId=vpc_base_cidr_assoc_id
|
||||
)
|
||||
@ -549,7 +548,7 @@ def test_vpc_associate_ipv6_cidr_block():
|
||||
ipv6_cidr_block_association_set["AssociationId"].should.contain("vpc-cidr-assoc")
|
||||
|
||||
# Test Fail on adding 2nd IPV6 association - AWS only allows 1 at this time!
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
response = ec2.meta.client.associate_vpc_cidr_block(
|
||||
VpcId=vpc.id, AmazonProvidedIpv6CidrBlock=True
|
||||
)
|
||||
@ -657,7 +656,7 @@ def test_create_vpc_with_invalid_cidr_block_parameter():
|
||||
ec2 = boto3.resource("ec2", region_name="us-west-1")
|
||||
|
||||
vpc_cidr_block = "1000.1.0.0/20"
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
vpc = ec2.create_vpc(CidrBlock=vpc_cidr_block)
|
||||
str(ex.exception).should.equal(
|
||||
"An error occurred (InvalidParameterValue) when calling the CreateVpc "
|
||||
@ -672,7 +671,7 @@ def test_create_vpc_with_invalid_cidr_range():
|
||||
ec2 = boto3.resource("ec2", region_name="us-west-1")
|
||||
|
||||
vpc_cidr_block = "10.1.0.0/29"
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
vpc = ec2.create_vpc(CidrBlock=vpc_cidr_block)
|
||||
str(ex.exception).should.equal(
|
||||
"An error occurred (InvalidVpc.Range) when calling the CreateVpc "
|
||||
|
@ -1,11 +1,11 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import boto
|
||||
import boto3
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
import sure # noqa
|
||||
from boto.exception import EC2ResponseError
|
||||
|
||||
from moto import mock_ec2_deprecated, mock_ec2
|
||||
from moto import mock_ec2, mock_ec2_deprecated
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
@ -35,7 +35,7 @@ def test_delete_vpn_connections():
|
||||
@mock_ec2_deprecated
|
||||
def test_delete_vpn_connections_bad_id():
|
||||
conn = boto.connect_vpc("the_key", "the_secret")
|
||||
with assert_raises(EC2ResponseError):
|
||||
with pytest.raises(EC2ResponseError):
|
||||
conn.delete_vpn_connection("vpn-0123abcd")
|
||||
|
||||
|
||||
|
1
tests/test_ecr/__init__.py
Normal file
1
tests/test_ecr/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -15,7 +15,7 @@ from botocore.exceptions import ClientError, ParamValidationError
|
||||
from dateutil.tz import tzlocal
|
||||
|
||||
from moto import mock_ecr
|
||||
from nose import SkipTest
|
||||
from unittest import SkipTest
|
||||
|
||||
|
||||
def _create_image_digest(contents=None):
|
||||
|
1
tests/test_ecs/__init__.py
Normal file
1
tests/test_ecs/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -10,7 +10,7 @@ from uuid import UUID
|
||||
|
||||
from moto import mock_ecs
|
||||
from moto import mock_ec2
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
|
||||
@mock_ecs
|
||||
@ -860,7 +860,7 @@ def test_deregister_container_instance():
|
||||
containerInstances=[container_instance_id],
|
||||
startedBy="moto",
|
||||
)
|
||||
with assert_raises(Exception) as e:
|
||||
with pytest.raises(Exception) as e:
|
||||
ecs_client.deregister_container_instance(
|
||||
cluster=test_cluster_name, containerInstance=container_instance_id
|
||||
).should.have.raised(Exception)
|
||||
@ -952,7 +952,7 @@ def test_describe_container_instances():
|
||||
instance.keys().should.contain("pendingTasksCount")
|
||||
instance["registeredAt"].should.be.a("datetime.datetime")
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
ecs_client.describe_container_instances(
|
||||
cluster=test_cluster_name, containerInstances=[]
|
||||
)
|
||||
|
1
tests/test_elb/__init__.py
Normal file
1
tests/test_elb/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -11,7 +11,7 @@ from boto.ec2.elb.attributes import (
|
||||
)
|
||||
from botocore.exceptions import ClientError
|
||||
from boto.exception import BotoServerError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_elb, mock_ec2, mock_elb_deprecated, mock_ec2_deprecated
|
||||
@ -123,7 +123,7 @@ def test_create_and_delete_boto3_support():
|
||||
def test_create_load_balancer_with_no_listeners_defined():
|
||||
client = boto3.client("elb", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.create_load_balancer(
|
||||
LoadBalancerName="my-lb",
|
||||
Listeners=[],
|
||||
@ -180,7 +180,7 @@ def test_apply_security_groups_to_load_balancer():
|
||||
assert balancer["SecurityGroups"] == [security_group.id]
|
||||
|
||||
# Using a not-real security group raises an error
|
||||
with assert_raises(ClientError) as error:
|
||||
with pytest.raises(ClientError) as error:
|
||||
response = client.apply_security_groups_to_load_balancer(
|
||||
LoadBalancerName="my-lb", SecurityGroups=["not-really-a-security-group"]
|
||||
)
|
||||
@ -255,7 +255,7 @@ def test_create_and_delete_listener_boto3_support():
|
||||
balancer["ListenerDescriptions"][1]["Listener"]["InstancePort"].should.equal(8443)
|
||||
|
||||
# Creating this listener with an conflicting definition throws error
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.create_load_balancer_listeners(
|
||||
LoadBalancerName="my-lb",
|
||||
Listeners=[
|
||||
|
1
tests/test_elbv2/__init__.py
Normal file
1
tests/test_elbv2/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -4,7 +4,7 @@ import os
|
||||
import boto3
|
||||
import botocore
|
||||
from botocore.exceptions import ClientError, ParamValidationError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_elbv2, mock_ec2, mock_acm
|
||||
@ -96,9 +96,9 @@ def test_describe_load_balancers():
|
||||
response = conn.describe_load_balancers(Names=["my-lb"])
|
||||
response.get("LoadBalancers")[0].get("LoadBalancerName").should.equal("my-lb")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.describe_load_balancers(LoadBalancerArns=["not-a/real/arn"])
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.describe_load_balancers(Names=["nope"])
|
||||
|
||||
|
||||
@ -132,7 +132,7 @@ def test_add_remove_tags():
|
||||
lbs.should.have.length_of(1)
|
||||
lb = lbs[0]
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.add_tags(ResourceArns=["missing-arn"], Tags=[{"Key": "a", "Value": "b"}])
|
||||
|
||||
conn.add_tags(
|
||||
@ -274,7 +274,7 @@ def test_create_target_group_and_listeners():
|
||||
load_balancer_arn = response.get("LoadBalancers")[0].get("LoadBalancerArn")
|
||||
|
||||
# Can't create a target group with an invalid protocol
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_target_group(
|
||||
Name="a-target",
|
||||
Protocol="HTTP",
|
||||
@ -389,7 +389,7 @@ def test_create_target_group_and_listeners():
|
||||
|
||||
# Try to delete the target group and it fails because there's a
|
||||
# listener referencing it
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
conn.delete_target_group(TargetGroupArn=target_group.get("TargetGroupArn"))
|
||||
e.exception.operation_name.should.equal("DeleteTargetGroup")
|
||||
e.exception.args.should.equal(
|
||||
@ -477,7 +477,7 @@ def test_create_invalid_target_group():
|
||||
|
||||
# Fail to create target group with name which length is 33
|
||||
long_name = "A" * 33
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_target_group(
|
||||
Name=long_name,
|
||||
Protocol="HTTP",
|
||||
@ -495,7 +495,7 @@ def test_create_invalid_target_group():
|
||||
|
||||
invalid_names = ["-name", "name-", "-name-", "example.com", "test@test", "Na--me"]
|
||||
for name in invalid_names:
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_target_group(
|
||||
Name=name,
|
||||
Protocol="HTTP",
|
||||
@ -941,7 +941,7 @@ def test_handle_listener_rules():
|
||||
load_balancer_arn = response.get("LoadBalancers")[0].get("LoadBalancerArn")
|
||||
|
||||
# Can't create a target group with an invalid protocol
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_target_group(
|
||||
Name="a-target",
|
||||
Protocol="HTTP",
|
||||
@ -1032,7 +1032,7 @@ def test_handle_listener_rules():
|
||||
)
|
||||
|
||||
# test for PriorityInUse
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_rule(
|
||||
ListenerArn=http_listener_arn,
|
||||
Priority=priority,
|
||||
@ -1079,11 +1079,11 @@ def test_handle_listener_rules():
|
||||
)
|
||||
|
||||
# test for invalid describe rule request
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.describe_rules()
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.describe_rules(RuleArns=[])
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.describe_rules(
|
||||
ListenerArn=http_listener_arn, RuleArns=[first_rule["RuleArn"]]
|
||||
)
|
||||
@ -1125,7 +1125,7 @@ def test_handle_listener_rules():
|
||||
}
|
||||
]
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.set_rule_priorities(
|
||||
RulePriorities=[
|
||||
{"RuleArn": first_rule["RuleArn"], "Priority": 999},
|
||||
@ -1141,7 +1141,7 @@ def test_handle_listener_rules():
|
||||
|
||||
# test for invalid action type
|
||||
safe_priority = 2
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_rule(
|
||||
ListenerArn=http_listener_arn,
|
||||
Priority=safe_priority,
|
||||
@ -1160,7 +1160,7 @@ def test_handle_listener_rules():
|
||||
# test for invalid action type
|
||||
safe_priority = 2
|
||||
invalid_target_group_arn = target_group.get("TargetGroupArn") + "x"
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_rule(
|
||||
ListenerArn=http_listener_arn,
|
||||
Priority=safe_priority,
|
||||
@ -1173,7 +1173,7 @@ def test_handle_listener_rules():
|
||||
|
||||
# test for invalid condition field_name
|
||||
safe_priority = 2
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_rule(
|
||||
ListenerArn=http_listener_arn,
|
||||
Priority=safe_priority,
|
||||
@ -1188,7 +1188,7 @@ def test_handle_listener_rules():
|
||||
|
||||
# test for emptry condition value
|
||||
safe_priority = 2
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_rule(
|
||||
ListenerArn=http_listener_arn,
|
||||
Priority=safe_priority,
|
||||
@ -1203,7 +1203,7 @@ def test_handle_listener_rules():
|
||||
|
||||
# test for multiple condition value
|
||||
safe_priority = 2
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_rule(
|
||||
ListenerArn=http_listener_arn,
|
||||
Priority=safe_priority,
|
||||
@ -1260,7 +1260,7 @@ def test_describe_invalid_target_group():
|
||||
)
|
||||
|
||||
# Check error raises correctly
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.describe_target_groups(Names=["invalid"])
|
||||
|
||||
|
||||
@ -1358,7 +1358,7 @@ def test_set_ip_address_type():
|
||||
arn = response["LoadBalancers"][0]["LoadBalancerArn"]
|
||||
|
||||
# Internal LBs cant be dualstack yet
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.set_ip_address_type(LoadBalancerArn=arn, IpAddressType="dualstack")
|
||||
|
||||
# Create internet facing one
|
||||
@ -1410,7 +1410,7 @@ def test_set_security_groups():
|
||||
resp = client.describe_load_balancers(LoadBalancerArns=[arn])
|
||||
len(resp["LoadBalancers"][0]["SecurityGroups"]).should.equal(2)
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.set_security_groups(LoadBalancerArn=arn, SecurityGroups=["non_existent"])
|
||||
|
||||
|
||||
@ -1451,11 +1451,11 @@ def test_set_subnets():
|
||||
len(resp["LoadBalancers"][0]["AvailabilityZones"]).should.equal(3)
|
||||
|
||||
# Only 1 AZ
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.set_subnets(LoadBalancerArn=arn, Subnets=[subnet1.id])
|
||||
|
||||
# Multiple subnets in same AZ
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.set_subnets(
|
||||
LoadBalancerArn=arn, Subnets=[subnet1.id, subnet2.id, subnet2.id]
|
||||
)
|
||||
@ -1644,7 +1644,7 @@ def test_modify_listener_http_to_https():
|
||||
listener.certificate.should.equal(yahoo_arn)
|
||||
|
||||
# No default cert
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.modify_listener(
|
||||
ListenerArn=listener_arn,
|
||||
Port=443,
|
||||
@ -1655,7 +1655,7 @@ def test_modify_listener_http_to_https():
|
||||
)
|
||||
|
||||
# Bad cert
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.modify_listener(
|
||||
ListenerArn=listener_arn,
|
||||
Port=443,
|
||||
@ -1884,7 +1884,7 @@ def test_fixed_response_action_listener_rule_validates_status_code():
|
||||
"MessageBody": "This page does not exist",
|
||||
},
|
||||
}
|
||||
with assert_raises(ParamValidationError):
|
||||
with pytest.raises(ParamValidationError):
|
||||
conn.create_listener(
|
||||
LoadBalancerArn=load_balancer_arn,
|
||||
Protocol="HTTP",
|
||||
@ -1934,7 +1934,7 @@ def test_fixed_response_action_listener_rule_validates_status_code():
|
||||
"MessageBody": "This page does not exist",
|
||||
},
|
||||
}
|
||||
with assert_raises(ParamValidationError):
|
||||
with pytest.raises(ParamValidationError):
|
||||
conn.create_listener(
|
||||
LoadBalancerArn=load_balancer_arn,
|
||||
Protocol="HTTP",
|
||||
@ -1951,7 +1951,7 @@ def test_fixed_response_action_listener_rule_validates_status_code():
|
||||
},
|
||||
}
|
||||
|
||||
with assert_raises(ClientError) as invalid_status_code_exception:
|
||||
with pytest.raises(ClientError) as invalid_status_code_exception:
|
||||
conn.create_listener(
|
||||
LoadBalancerArn=load_balancer_arn,
|
||||
Protocol="HTTP",
|
||||
@ -1998,7 +1998,7 @@ def test_fixed_response_action_listener_rule_validates_content_type():
|
||||
"StatusCode": "200",
|
||||
},
|
||||
}
|
||||
with assert_raises(ClientError) as invalid_content_type_exception:
|
||||
with pytest.raises(ClientError) as invalid_content_type_exception:
|
||||
conn.create_listener(
|
||||
LoadBalancerArn=load_balancer_arn,
|
||||
Protocol="HTTP",
|
||||
|
1
tests/test_emr/__init__.py
Normal file
1
tests/test_emr/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -9,7 +9,7 @@ import pytz
|
||||
import six
|
||||
import sure # noqa
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_emr
|
||||
|
||||
@ -395,7 +395,7 @@ def test_run_job_flow():
|
||||
@mock_emr
|
||||
def test_run_job_flow_with_invalid_params():
|
||||
client = boto3.client("emr", region_name="us-east-1")
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
# cannot set both AmiVersion and ReleaseLabel
|
||||
args = deepcopy(run_job_flow_args)
|
||||
args["AmiVersion"] = "2.4"
|
||||
@ -592,7 +592,7 @@ def _patch_cluster_id_placeholder_in_autoscaling_policy(
|
||||
def test_run_job_flow_with_custom_ami():
|
||||
client = boto3.client("emr", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
# CustomAmiId available in Amazon EMR 5.7.0 and later
|
||||
args = deepcopy(run_job_flow_args)
|
||||
args["CustomAmiId"] = "MyEmrCustomId"
|
||||
@ -601,7 +601,7 @@ def test_run_job_flow_with_custom_ami():
|
||||
ex.exception.response["Error"]["Code"].should.equal("ValidationException")
|
||||
ex.exception.response["Error"]["Message"].should.equal("Custom AMI is not allowed")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
args = deepcopy(run_job_flow_args)
|
||||
args["CustomAmiId"] = "MyEmrCustomId"
|
||||
args["AmiVersion"] = "3.8.1"
|
||||
@ -611,7 +611,7 @@ def test_run_job_flow_with_custom_ami():
|
||||
"Custom AMI is not supported in this version of EMR"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
# AMI version and release label exception raises before CustomAmi exception
|
||||
args = deepcopy(run_job_flow_args)
|
||||
args["CustomAmiId"] = "MyEmrCustomId"
|
||||
|
1
tests/test_events/__init__.py
Normal file
1
tests/test_events/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -6,7 +6,7 @@ import boto3
|
||||
import sure # noqa
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto.core import ACCOUNT_ID
|
||||
from moto.core.exceptions import JsonRESTError
|
||||
@ -331,7 +331,7 @@ def test_put_events():
|
||||
response["FailedEntryCount"].should.equal(0)
|
||||
response["Entries"].should.have.length_of(1)
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.put_events(Entries=[event] * 20)
|
||||
|
||||
|
||||
|
1
tests/test_glacier/__init__.py
Normal file
1
tests/test_glacier/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import sure # noqa
|
||||
import re
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
import boto3
|
||||
from botocore.client import ClientError
|
||||
|
||||
@ -32,7 +32,7 @@ def test_create_database_already_exists():
|
||||
database_name = "cantcreatethisdatabasetwice"
|
||||
helpers.create_database(client, database_name)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.create_database(client, database_name)
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("AlreadyExistsException")
|
||||
@ -43,7 +43,7 @@ def test_get_database_not_exits():
|
||||
client = boto3.client("glue", region_name="us-east-1")
|
||||
database_name = "nosuchdatabase"
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.get_database(client, database_name)
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("EntityNotFoundException")
|
||||
@ -102,7 +102,7 @@ def test_create_table_already_exists():
|
||||
table_name = "cantcreatethistabletwice"
|
||||
helpers.create_table(client, database_name, table_name)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.create_table(client, database_name, table_name)
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("AlreadyExistsException")
|
||||
@ -192,7 +192,7 @@ def test_get_table_version_not_found():
|
||||
helpers.create_database(client, database_name)
|
||||
helpers.create_table(client, database_name, table_name)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.get_table_version(client, database_name, "myfirsttable", "20")
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("EntityNotFoundException")
|
||||
@ -207,7 +207,7 @@ def test_get_table_version_invalid_input():
|
||||
helpers.create_database(client, database_name)
|
||||
helpers.create_table(client, database_name, table_name)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.get_table_version(client, database_name, "myfirsttable", "10not-an-int")
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("InvalidInputException")
|
||||
@ -219,7 +219,7 @@ def test_get_table_not_exits():
|
||||
database_name = "myspecialdatabase"
|
||||
helpers.create_database(client, database_name)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.get_table(client, database_name, "myfirsttable")
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("EntityNotFoundException")
|
||||
@ -233,7 +233,7 @@ def test_get_table_when_database_not_exits():
|
||||
client = boto3.client("glue", region_name="us-east-1")
|
||||
database_name = "nosuchdatabase"
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.get_table(client, database_name, "myfirsttable")
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("EntityNotFoundException")
|
||||
@ -256,7 +256,7 @@ def test_delete_table():
|
||||
result["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
# confirm table is deleted
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.get_table(client, database_name, table_name)
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("EntityNotFoundException")
|
||||
@ -281,7 +281,7 @@ def test_batch_delete_table():
|
||||
result["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
# confirm table is deleted
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.get_table(client, database_name, table_name)
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("EntityNotFoundException")
|
||||
@ -350,7 +350,7 @@ def test_create_partition_already_exist():
|
||||
|
||||
helpers.create_partition(client, database_name, table_name, values=values)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.create_partition(client, database_name, table_name, values=values)
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("AlreadyExistsException")
|
||||
@ -366,7 +366,7 @@ def test_get_partition_not_found():
|
||||
|
||||
helpers.create_table(client, database_name, table_name)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.get_partition(client, database_name, table_name, values)
|
||||
|
||||
exc.exception.response["Error"]["Code"].should.equal("EntityNotFoundException")
|
||||
@ -542,7 +542,7 @@ def test_update_partition_not_found_moving():
|
||||
helpers.create_database(client, database_name)
|
||||
helpers.create_table(client, database_name, table_name)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.update_partition(
|
||||
client,
|
||||
database_name,
|
||||
@ -565,7 +565,7 @@ def test_update_partition_not_found_change_in_place():
|
||||
helpers.create_database(client, database_name)
|
||||
helpers.create_table(client, database_name, table_name)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.update_partition(
|
||||
client, database_name, table_name, old_values=values, values=values
|
||||
)
|
||||
@ -588,7 +588,7 @@ def test_update_partition_cannot_overwrite():
|
||||
helpers.create_partition(client, database_name, table_name, values=values[0])
|
||||
helpers.create_partition(client, database_name, table_name, values=values[1])
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.update_partition(
|
||||
client, database_name, table_name, old_values=values[0], values=values[1]
|
||||
)
|
||||
@ -648,7 +648,7 @@ def test_update_partition_move():
|
||||
columns=[{"Name": "country", "Type": "string"}],
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
helpers.get_partition(client, database_name, table_name, values)
|
||||
|
||||
# Old partition shouldn't exist anymore
|
||||
@ -697,7 +697,7 @@ def test_delete_partition_bad_partition():
|
||||
helpers.create_database(client, database_name)
|
||||
helpers.create_table(client, database_name, table_name)
|
||||
|
||||
with assert_raises(ClientError) as exc:
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.delete_partition(
|
||||
DatabaseName=database_name, TableName=table_name, PartitionValues=values
|
||||
)
|
||||
|
1
tests/test_iam/__init__.py
Normal file
1
tests/test_iam/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -13,8 +13,7 @@ from moto import mock_config, mock_iam, mock_iam_deprecated, settings
|
||||
from moto.core import ACCOUNT_ID
|
||||
from moto.iam.models import aws_managed_policies
|
||||
from moto.backends import get_backend
|
||||
from nose.tools import assert_raises, assert_equals
|
||||
from nose.tools import raises
|
||||
import pytest
|
||||
|
||||
from datetime import datetime
|
||||
from tests.helpers import requires_boto_gte
|
||||
@ -93,7 +92,7 @@ def test_get_all_server_certs():
|
||||
def test_get_server_cert_doesnt_exist():
|
||||
conn = boto.connect_iam()
|
||||
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_server_certificate("NonExistant")
|
||||
|
||||
|
||||
@ -128,14 +127,14 @@ def test_delete_server_cert():
|
||||
conn.upload_server_cert("certname", "certbody", "privatekey")
|
||||
conn.get_server_certificate("certname")
|
||||
conn.delete_server_cert("certname")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_server_certificate("certname")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.delete_server_cert("certname")
|
||||
|
||||
|
||||
@mock_iam_deprecated()
|
||||
@raises(BotoServerError)
|
||||
@pytest.mark.xfail(raises=BotoServerError)
|
||||
def test_get_role__should_throw__when_role_does_not_exist():
|
||||
conn = boto.connect_iam()
|
||||
|
||||
@ -143,7 +142,7 @@ def test_get_role__should_throw__when_role_does_not_exist():
|
||||
|
||||
|
||||
@mock_iam_deprecated()
|
||||
@raises(BotoServerError)
|
||||
@pytest.mark.xfail(raises=BotoServerError)
|
||||
def test_get_instance_profile__should_throw__when_instance_profile_does_not_exist():
|
||||
conn = boto.connect_iam()
|
||||
|
||||
@ -181,7 +180,7 @@ def test_create_role_and_instance_profile():
|
||||
def test_create_instance_profile_should_throw_when_name_is_not_unique():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
conn.create_instance_profile(InstanceProfileName="unique-instance-profile")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_instance_profile(InstanceProfileName="unique-instance-profile")
|
||||
|
||||
|
||||
@ -214,13 +213,13 @@ def test_delete_instance_profile():
|
||||
conn.add_role_to_instance_profile(
|
||||
InstanceProfileName="my-profile", RoleName="my-role"
|
||||
)
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_instance_profile(InstanceProfileName="my-profile")
|
||||
conn.remove_role_from_instance_profile(
|
||||
InstanceProfileName="my-profile", RoleName="my-role"
|
||||
)
|
||||
conn.delete_instance_profile(InstanceProfileName="my-profile")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
profile = conn.get_instance_profile(InstanceProfileName="my-profile")
|
||||
|
||||
|
||||
@ -253,7 +252,7 @@ def test_update_login_profile():
|
||||
def test_delete_role():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
# Test deletion failure with a managed policy
|
||||
@ -264,12 +263,12 @@ def test_delete_role():
|
||||
PolicyName="my-managed-policy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
conn.attach_role_policy(PolicyArn=response["Policy"]["Arn"], RoleName="my-role")
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
conn.detach_role_policy(PolicyArn=response["Policy"]["Arn"], RoleName="my-role")
|
||||
conn.delete_policy(PolicyArn=response["Policy"]["Arn"])
|
||||
conn.delete_role(RoleName="my-role")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_role(RoleName="my-role")
|
||||
|
||||
# Test deletion failure with an inline policy
|
||||
@ -279,11 +278,11 @@ def test_delete_role():
|
||||
conn.put_role_policy(
|
||||
RoleName="my-role", PolicyName="my-role-policy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
conn.delete_role_policy(RoleName="my-role", PolicyName="my-role-policy")
|
||||
conn.delete_role(RoleName="my-role")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_role(RoleName="my-role")
|
||||
|
||||
# Test deletion failure with attachment to an instance profile
|
||||
@ -294,13 +293,13 @@ def test_delete_role():
|
||||
conn.add_role_to_instance_profile(
|
||||
InstanceProfileName="my-profile", RoleName="my-role"
|
||||
)
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
conn.remove_role_from_instance_profile(
|
||||
InstanceProfileName="my-profile", RoleName="my-role"
|
||||
)
|
||||
conn.delete_role(RoleName="my-role")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_role(RoleName="my-role")
|
||||
|
||||
# Test deletion with no conflicts
|
||||
@ -308,7 +307,7 @@ def test_delete_role():
|
||||
RoleName="my-role", AssumeRolePolicyDocument="some policy", Path="/my-path/"
|
||||
)
|
||||
conn.delete_role(RoleName="my-role")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_role(RoleName="my-role")
|
||||
|
||||
|
||||
@ -389,7 +388,7 @@ def test_list_role_policies():
|
||||
role.policy_names.should.have.length_of(1)
|
||||
role.policy_names[0].should.equal("test policy 2")
|
||||
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.delete_role_policy("my-role", "test policy")
|
||||
|
||||
|
||||
@ -412,7 +411,7 @@ def test_get_role_policy():
|
||||
conn.create_role(
|
||||
RoleName="my-role", AssumeRolePolicyDocument="some policy", Path="my-path"
|
||||
)
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_role_policy(RoleName="my-role", PolicyName="does-not-exist")
|
||||
|
||||
|
||||
@ -442,7 +441,7 @@ def test_create_policy_already_exists():
|
||||
response = conn.create_policy(
|
||||
PolicyName="TestCreatePolicy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
with assert_raises(conn.exceptions.EntityAlreadyExistsException) as ex:
|
||||
with pytest.raises(conn.exceptions.EntityAlreadyExistsException) as ex:
|
||||
response = conn.create_policy(
|
||||
PolicyName="TestCreatePolicy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
@ -467,7 +466,7 @@ def test_delete_policy():
|
||||
@mock_iam
|
||||
def test_create_policy_versions():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_policy_version(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestCreatePolicyVersion".format(
|
||||
ACCOUNT_ID
|
||||
@ -508,7 +507,7 @@ def test_create_many_policy_versions():
|
||||
),
|
||||
PolicyDocument=MOCK_POLICY,
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_policy_version(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestCreateManyPolicyVersions".format(
|
||||
ACCOUNT_ID
|
||||
@ -639,7 +638,7 @@ def test_get_policy_version():
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestGetPolicyVersion".format(ACCOUNT_ID),
|
||||
PolicyDocument=MOCK_POLICY,
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.get_policy_version(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestGetPolicyVersion".format(ACCOUNT_ID),
|
||||
VersionId="v2-does-not-exist",
|
||||
@ -661,7 +660,7 @@ def test_get_aws_managed_policy_version():
|
||||
managed_policy_version_create_date = datetime.strptime(
|
||||
"2015-04-09T15:03:43+00:00", "%Y-%m-%dT%H:%M:%S+00:00"
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.get_policy_version(
|
||||
PolicyArn=managed_policy_arn, VersionId="v2-does-not-exist"
|
||||
)
|
||||
@ -679,7 +678,7 @@ def test_get_aws_managed_policy_v4_version():
|
||||
managed_policy_version_create_date = datetime.strptime(
|
||||
"2018-10-08T21:33:45+00:00", "%Y-%m-%dT%H:%M:%S+00:00"
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.get_policy_version(
|
||||
PolicyArn=managed_policy_arn, VersionId="v2-does-not-exist"
|
||||
)
|
||||
@ -693,7 +692,7 @@ def test_get_aws_managed_policy_v4_version():
|
||||
@mock_iam
|
||||
def test_list_policy_versions():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
versions = conn.list_policy_versions(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestListPolicyVersions".format(ACCOUNT_ID)
|
||||
)
|
||||
@ -729,7 +728,7 @@ def test_delete_policy_version():
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestDeletePolicyVersion".format(ACCOUNT_ID),
|
||||
PolicyDocument=MOCK_POLICY,
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_policy_version(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestDeletePolicyVersion".format(
|
||||
ACCOUNT_ID
|
||||
@ -754,7 +753,7 @@ def test_delete_default_policy_version():
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestDeletePolicyVersion".format(ACCOUNT_ID),
|
||||
PolicyDocument=MOCK_POLICY_2,
|
||||
)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_policy_version(
|
||||
PolicyArn="arn:aws:iam::{}:policy/TestDeletePolicyVersion".format(
|
||||
ACCOUNT_ID
|
||||
@ -767,14 +766,14 @@ def test_delete_default_policy_version():
|
||||
def test_create_user():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_user("my-user")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.create_user("my-user")
|
||||
|
||||
|
||||
@mock_iam_deprecated()
|
||||
def test_get_user():
|
||||
conn = boto.connect_iam()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_user("my-user")
|
||||
conn.create_user("my-user")
|
||||
conn.get_user("my-user")
|
||||
@ -783,13 +782,13 @@ def test_get_user():
|
||||
@mock_iam()
|
||||
def test_update_user():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.update_user(UserName="my-user")
|
||||
conn.create_user(UserName="my-user")
|
||||
conn.update_user(UserName="my-user", NewPath="/new-path/", NewUserName="new-user")
|
||||
response = conn.get_user(UserName="new-user")
|
||||
response["User"].get("Path").should.equal("/new-path/")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_user(UserName="my-user")
|
||||
|
||||
|
||||
@ -846,11 +845,11 @@ def test_user_policies():
|
||||
@mock_iam_deprecated()
|
||||
def test_create_login_profile():
|
||||
conn = boto.connect_iam()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.create_login_profile("my-user", "my-pass")
|
||||
conn.create_user("my-user")
|
||||
conn.create_login_profile("my-user", "my-pass")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.create_login_profile("my-user", "my-pass")
|
||||
|
||||
|
||||
@ -858,7 +857,7 @@ def test_create_login_profile():
|
||||
def test_delete_login_profile():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_user("my-user")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.delete_login_profile("my-user")
|
||||
conn.create_login_profile("my-user", "my-pass")
|
||||
conn.delete_login_profile("my-user")
|
||||
@ -867,7 +866,7 @@ def test_delete_login_profile():
|
||||
@mock_iam
|
||||
def test_create_access_key():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_access_key(UserName="my-user")
|
||||
conn.create_user(UserName="my-user")
|
||||
access_key = conn.create_access_key(UserName="my-user")["AccessKey"]
|
||||
@ -899,22 +898,19 @@ def test_get_all_access_keys():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_user("my-user")
|
||||
response = conn.get_all_access_keys("my-user")
|
||||
assert_equals(
|
||||
assert \
|
||||
response["list_access_keys_response"]["list_access_keys_result"][
|
||||
"access_key_metadata"
|
||||
],
|
||||
[],
|
||||
)
|
||||
] == []
|
||||
conn.create_access_key("my-user")
|
||||
response = conn.get_all_access_keys("my-user")
|
||||
assert_equals(
|
||||
assert \
|
||||
sorted(
|
||||
response["list_access_keys_response"]["list_access_keys_result"][
|
||||
"access_key_metadata"
|
||||
][0].keys()
|
||||
),
|
||||
sorted(["status", "create_date", "user_name", "access_key_id"]),
|
||||
)
|
||||
) == \
|
||||
sorted(["status", "create_date", "user_name", "access_key_id"])
|
||||
|
||||
|
||||
@mock_iam
|
||||
@ -922,13 +918,12 @@ def test_list_access_keys():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
conn.create_user(UserName="my-user")
|
||||
response = conn.list_access_keys(UserName="my-user")
|
||||
assert_equals(response["AccessKeyMetadata"], [])
|
||||
assert response["AccessKeyMetadata"] == []
|
||||
access_key = conn.create_access_key(UserName="my-user")["AccessKey"]
|
||||
response = conn.list_access_keys(UserName="my-user")
|
||||
assert_equals(
|
||||
sorted(response["AccessKeyMetadata"][0].keys()),
|
||||
sorted(["Status", "CreateDate", "UserName", "AccessKeyId"]),
|
||||
)
|
||||
assert \
|
||||
sorted(response["AccessKeyMetadata"][0].keys()) == \
|
||||
sorted(["Status", "CreateDate", "UserName", "AccessKeyId"]
|
||||
conn = boto3.client(
|
||||
"iam",
|
||||
region_name="us-east-1",
|
||||
@ -936,10 +931,9 @@ def test_list_access_keys():
|
||||
aws_secret_access_key=access_key["SecretAccessKey"],
|
||||
)
|
||||
response = conn.list_access_keys()
|
||||
assert_equals(
|
||||
sorted(response["AccessKeyMetadata"][0].keys()),
|
||||
sorted(["Status", "CreateDate", "UserName", "AccessKeyId"]),
|
||||
)
|
||||
assert \
|
||||
sorted(response["AccessKeyMetadata"][0].keys()) == \
|
||||
sorted(["Status", "CreateDate", "UserName", "AccessKeyId"])
|
||||
|
||||
|
||||
@mock_iam_deprecated()
|
||||
@ -1188,7 +1182,7 @@ def test_enable_virtual_mfa_device():
|
||||
@mock_iam_deprecated()
|
||||
def test_delete_user_deprecated():
|
||||
conn = boto.connect_iam()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.delete_user("my-user")
|
||||
conn.create_user("my-user")
|
||||
conn.delete_user("my-user")
|
||||
@ -1197,7 +1191,7 @@ def test_delete_user_deprecated():
|
||||
@mock_iam()
|
||||
def test_delete_user():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.delete_user(UserName="my-user")
|
||||
|
||||
# Test deletion failure with a managed policy
|
||||
@ -1206,12 +1200,12 @@ def test_delete_user():
|
||||
PolicyName="my-managed-policy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
conn.attach_user_policy(PolicyArn=response["Policy"]["Arn"], UserName="my-user")
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_user(UserName="my-user")
|
||||
conn.detach_user_policy(PolicyArn=response["Policy"]["Arn"], UserName="my-user")
|
||||
conn.delete_policy(PolicyArn=response["Policy"]["Arn"])
|
||||
conn.delete_user(UserName="my-user")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_user(UserName="my-user")
|
||||
|
||||
# Test deletion failure with an inline policy
|
||||
@ -1219,17 +1213,17 @@ def test_delete_user():
|
||||
conn.put_user_policy(
|
||||
UserName="my-user", PolicyName="my-user-policy", PolicyDocument=MOCK_POLICY
|
||||
)
|
||||
with assert_raises(conn.exceptions.DeleteConflictException):
|
||||
with pytest.raises(conn.exceptions.DeleteConflictException):
|
||||
conn.delete_user(UserName="my-user")
|
||||
conn.delete_user_policy(UserName="my-user", PolicyName="my-user-policy")
|
||||
conn.delete_user(UserName="my-user")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_user(UserName="my-user")
|
||||
|
||||
# Test deletion with no conflicts
|
||||
conn.create_user(UserName="my-user")
|
||||
conn.delete_user(UserName="my-user")
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
with pytest.raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_user(UserName="my-user")
|
||||
|
||||
|
||||
@ -1259,7 +1253,7 @@ def test_boto3_generate_credential_report():
|
||||
def test_get_credential_report():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_user("my-user")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_credential_report()
|
||||
result = conn.generate_credential_report()
|
||||
while (
|
||||
@ -1282,7 +1276,7 @@ def test_get_credential_report():
|
||||
def test_boto3_get_credential_report():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
conn.create_user(UserName="my-user")
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.get_credential_report()
|
||||
result = conn.generate_credential_report()
|
||||
while result["State"] != "COMPLETE":
|
||||
@ -1306,7 +1300,7 @@ def test_boto3_get_credential_report_content():
|
||||
if not settings.TEST_SERVER_MODE:
|
||||
iam_backend = get_backend("iam")["global"]
|
||||
iam_backend.users[username].access_keys[1].last_used = timestamp
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.get_credential_report()
|
||||
result = conn.generate_credential_report()
|
||||
while result["State"] != "COMPLETE":
|
||||
@ -1336,7 +1330,7 @@ def test_get_access_key_last_used_when_used():
|
||||
client = iam.meta.client
|
||||
username = "test-user"
|
||||
iam.create_user(UserName=username)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.get_access_key_last_used(AccessKeyId="non-existent-key-id")
|
||||
create_key_response = client.create_access_key(UserName=username)["AccessKey"]
|
||||
# Set last used date using the IAM backend. Moto currently does not have a mechanism for tracking usage of access keys
|
||||
@ -1448,12 +1442,12 @@ def test_managed_policy():
|
||||
"attached_policies"
|
||||
].should.have.length_of(1)
|
||||
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.detach_role_policy(
|
||||
"arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole", role_name
|
||||
)
|
||||
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.detach_role_policy("arn:aws:iam::aws:policy/Nonexistent", role_name)
|
||||
|
||||
|
||||
@ -1461,13 +1455,13 @@ def test_managed_policy():
|
||||
def test_boto3_create_login_profile():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_login_profile(UserName="my-user", Password="Password")
|
||||
|
||||
conn.create_user(UserName="my-user")
|
||||
conn.create_login_profile(UserName="my-user", Password="Password")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_login_profile(UserName="my-user", Password="Password")
|
||||
|
||||
|
||||
@ -1506,7 +1500,7 @@ def test_update_access_key():
|
||||
client = iam.meta.client
|
||||
username = "test-user"
|
||||
iam.create_user(UserName=username)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.update_access_key(
|
||||
UserName=username, AccessKeyId="non-existent-key", Status="Inactive"
|
||||
)
|
||||
@ -1527,7 +1521,7 @@ def test_get_access_key_last_used_when_unused():
|
||||
client = iam.meta.client
|
||||
username = "test-user"
|
||||
iam.create_user(UserName=username)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.get_access_key_last_used(AccessKeyId="non-existent-key-id")
|
||||
create_key_response = client.create_access_key(UserName=username)["AccessKey"]
|
||||
resp = client.get_access_key_last_used(
|
||||
@ -1566,7 +1560,7 @@ def test_get_ssh_public_key():
|
||||
iam.create_user(UserName=username)
|
||||
public_key = MOCK_CERT
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.get_ssh_public_key(
|
||||
UserName=username, SSHPublicKeyId="xxnon-existent-keyxx", Encoding="SSH"
|
||||
)
|
||||
@ -1607,7 +1601,7 @@ def test_update_ssh_public_key():
|
||||
iam.create_user(UserName=username)
|
||||
public_key = MOCK_CERT
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.update_ssh_public_key(
|
||||
UserName=username, SSHPublicKeyId="xxnon-existent-keyxx", Status="Inactive"
|
||||
)
|
||||
@ -1634,7 +1628,7 @@ def test_delete_ssh_public_key():
|
||||
iam.create_user(UserName=username)
|
||||
public_key = MOCK_CERT
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.delete_ssh_public_key(
|
||||
UserName=username, SSHPublicKeyId="xxnon-existent-keyxx"
|
||||
)
|
||||
@ -1827,14 +1821,14 @@ def test_signing_certs():
|
||||
assert resp["CertificateId"]
|
||||
|
||||
# Upload a the cert with an invalid body:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.upload_signing_certificate(
|
||||
UserName="testing", CertificateBody="notacert"
|
||||
)
|
||||
assert ce.exception.response["Error"]["Code"] == "MalformedCertificate"
|
||||
|
||||
# Upload with an invalid user:
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.upload_signing_certificate(
|
||||
UserName="notauser", CertificateBody=MOCK_CERT
|
||||
)
|
||||
@ -1844,12 +1838,12 @@ def test_signing_certs():
|
||||
UserName="testing", CertificateId=cert_id, Status="Inactive"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.update_signing_certificate(
|
||||
UserName="notauser", CertificateId=cert_id, Status="Inactive"
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
client.update_signing_certificate(
|
||||
UserName="testing", CertificateId="x" * 32, Status="Inactive"
|
||||
)
|
||||
@ -1864,13 +1858,13 @@ def test_signing_certs():
|
||||
assert resp[0]["CertificateBody"] == MOCK_CERT
|
||||
assert resp[0]["Status"] == "Inactive" # Changed with the update call above.
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.list_signing_certificates(UserName="notauser")
|
||||
|
||||
# Delete:
|
||||
client.delete_signing_certificate(UserName="testing", CertificateId=cert_id)
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.delete_signing_certificate(UserName="notauser", CertificateId=cert_id)
|
||||
|
||||
|
||||
@ -1921,7 +1915,7 @@ def test_delete_saml_provider():
|
||||
conn.create_user(UserName="testing")
|
||||
|
||||
cert_id = "123456789012345678901234"
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.delete_signing_certificate(UserName="testing", CertificateId=cert_id)
|
||||
|
||||
assert ce.exception.response["Error"][
|
||||
@ -1982,7 +1976,7 @@ def test_create_role_with_tags():
|
||||
|
||||
# Test creating tags with invalid values:
|
||||
# With more than 50 tags:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
too_many_tags = list(
|
||||
map(lambda x: {"Key": str(x), "Value": str(x)}, range(0, 51))
|
||||
)
|
||||
@ -1995,7 +1989,7 @@ def test_create_role_with_tags():
|
||||
)
|
||||
|
||||
# With a duplicate tag:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.create_role(
|
||||
RoleName="my-role3",
|
||||
AssumeRolePolicyDocument="{}",
|
||||
@ -2007,7 +2001,7 @@ def test_create_role_with_tags():
|
||||
)
|
||||
|
||||
# Duplicate tag with different casing:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.create_role(
|
||||
RoleName="my-role3",
|
||||
AssumeRolePolicyDocument="{}",
|
||||
@ -2019,7 +2013,7 @@ def test_create_role_with_tags():
|
||||
)
|
||||
|
||||
# With a really big key:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.create_role(
|
||||
RoleName="my-role3",
|
||||
AssumeRolePolicyDocument="{}",
|
||||
@ -2031,7 +2025,7 @@ def test_create_role_with_tags():
|
||||
)
|
||||
|
||||
# With a really big value:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.create_role(
|
||||
RoleName="my-role3",
|
||||
AssumeRolePolicyDocument="{}",
|
||||
@ -2043,7 +2037,7 @@ def test_create_role_with_tags():
|
||||
)
|
||||
|
||||
# With an invalid character:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.create_role(
|
||||
RoleName="my-role3",
|
||||
AssumeRolePolicyDocument="{}",
|
||||
@ -2125,7 +2119,7 @@ def test_tag_role():
|
||||
|
||||
# Test creating tags with invalid values:
|
||||
# With more than 50 tags:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
too_many_tags = list(
|
||||
map(lambda x: {"Key": str(x), "Value": str(x)}, range(0, 51))
|
||||
)
|
||||
@ -2136,7 +2130,7 @@ def test_tag_role():
|
||||
)
|
||||
|
||||
# With a duplicate tag:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.tag_role(
|
||||
RoleName="my-role",
|
||||
Tags=[{"Key": "0", "Value": ""}, {"Key": "0", "Value": ""}],
|
||||
@ -2147,7 +2141,7 @@ def test_tag_role():
|
||||
)
|
||||
|
||||
# Duplicate tag with different casing:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.tag_role(
|
||||
RoleName="my-role",
|
||||
Tags=[{"Key": "a", "Value": ""}, {"Key": "A", "Value": ""}],
|
||||
@ -2158,7 +2152,7 @@ def test_tag_role():
|
||||
)
|
||||
|
||||
# With a really big key:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.tag_role(RoleName="my-role", Tags=[{"Key": "0" * 129, "Value": ""}])
|
||||
assert (
|
||||
"Member must have length less than or equal to 128."
|
||||
@ -2166,7 +2160,7 @@ def test_tag_role():
|
||||
)
|
||||
|
||||
# With a really big value:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.tag_role(RoleName="my-role", Tags=[{"Key": "0", "Value": "0" * 257}])
|
||||
assert (
|
||||
"Member must have length less than or equal to 256."
|
||||
@ -2174,7 +2168,7 @@ def test_tag_role():
|
||||
)
|
||||
|
||||
# With an invalid character:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.tag_role(RoleName="my-role", Tags=[{"Key": "NOWAY!", "Value": ""}])
|
||||
assert (
|
||||
"Member must satisfy regular expression pattern: [\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]+"
|
||||
@ -2182,7 +2176,7 @@ def test_tag_role():
|
||||
)
|
||||
|
||||
# With a role that doesn't exist:
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.tag_role(RoleName="notarole", Tags=[{"Key": "some", "Value": "value"}])
|
||||
|
||||
|
||||
@ -2214,7 +2208,7 @@ def test_untag_role():
|
||||
|
||||
# Test removing tags with invalid values:
|
||||
# With more than 50 tags:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.untag_role(RoleName="my-role", TagKeys=[str(x) for x in range(0, 51)])
|
||||
assert (
|
||||
"failed to satisfy constraint: Member must have length less than or equal to 50."
|
||||
@ -2223,7 +2217,7 @@ def test_untag_role():
|
||||
assert "tagKeys" in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# With a really big key:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.untag_role(RoleName="my-role", TagKeys=["0" * 129])
|
||||
assert (
|
||||
"Member must have length less than or equal to 128."
|
||||
@ -2232,7 +2226,7 @@ def test_untag_role():
|
||||
assert "tagKeys" in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# With an invalid character:
|
||||
with assert_raises(ClientError) as ce:
|
||||
with pytest.raises(ClientError) as ce:
|
||||
conn.untag_role(RoleName="my-role", TagKeys=["NOWAY!"])
|
||||
assert (
|
||||
"Member must satisfy regular expression pattern: [\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]+"
|
||||
@ -2241,7 +2235,7 @@ def test_untag_role():
|
||||
assert "tagKeys" in ce.exception.response["Error"]["Message"]
|
||||
|
||||
# With a role that doesn't exist:
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.untag_role(RoleName="notarole", TagKeys=["somevalue"])
|
||||
|
||||
|
||||
@ -2249,7 +2243,7 @@ def test_untag_role():
|
||||
def test_update_role_description():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
conn.create_role(
|
||||
@ -2264,7 +2258,7 @@ def test_update_role_description():
|
||||
def test_update_role():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
conn.create_role(
|
||||
@ -2278,7 +2272,7 @@ def test_update_role():
|
||||
def test_update_role():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
conn.create_role(
|
||||
@ -2292,7 +2286,7 @@ def test_update_role():
|
||||
def test_update_role_defaults():
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
conn.create_role(
|
||||
@ -2436,12 +2430,12 @@ def test_create_role_with_permissions_boundary():
|
||||
|
||||
invalid_boundary_arn = "arn:aws:iam::123456789:not_a_boundary"
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.put_role_permissions_boundary(
|
||||
RoleName="my-role", PermissionsBoundary=invalid_boundary_arn
|
||||
)
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
conn.create_role(
|
||||
RoleName="bad-boundary",
|
||||
AssumeRolePolicyDocument="some policy",
|
||||
@ -2461,7 +2455,7 @@ def test_create_role_with_same_name_should_fail():
|
||||
RoleName=test_role_name, AssumeRolePolicyDocument="policy", Description="test"
|
||||
)
|
||||
# Create the role again, and verify that it fails
|
||||
with assert_raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as err:
|
||||
iam.create_role(
|
||||
RoleName=test_role_name,
|
||||
AssumeRolePolicyDocument="policy",
|
||||
@ -2479,7 +2473,7 @@ def test_create_policy_with_same_name_should_fail():
|
||||
test_policy_name = str(uuid4())
|
||||
policy = iam.create_policy(PolicyName=test_policy_name, PolicyDocument=MOCK_POLICY)
|
||||
# Create the role again, and verify that it fails
|
||||
with assert_raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as err:
|
||||
iam.create_policy(PolicyName=test_policy_name, PolicyDocument=MOCK_POLICY)
|
||||
err.exception.response["Error"]["Code"].should.equal("EntityAlreadyExists")
|
||||
err.exception.response["Error"]["Message"].should.equal(
|
||||
|
@ -2,7 +2,7 @@ import boto3
|
||||
import yaml
|
||||
import sure # noqa
|
||||
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
from moto import mock_iam, mock_cloudformation, mock_s3, mock_sts
|
||||
@ -111,7 +111,7 @@ Resources:
|
||||
|
||||
cf_client.update_stack(StackName=stack_name, TemplateBody=template)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
iam_client.get_user(UserName=original_user_name)
|
||||
e.exception.response["Error"]["Code"].should.equal("NoSuchEntity")
|
||||
|
||||
@ -175,7 +175,7 @@ Resources:
|
||||
second_user_name.should.equal(second_provisioned_user["PhysicalResourceId"])
|
||||
|
||||
iam_client.get_user(UserName=second_user_name)
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
iam_client.get_user(UserName=first_user_name)
|
||||
e.exception.response["Error"]["Code"].should.equal("NoSuchEntity")
|
||||
|
||||
@ -205,7 +205,7 @@ Resources:
|
||||
|
||||
cf_client.delete_stack(StackName=stack_name)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
user = iam_client.get_user(UserName=user_name)
|
||||
e.exception.response["Error"]["Code"].should.equal("NoSuchEntity")
|
||||
|
||||
@ -235,7 +235,7 @@ Resources:
|
||||
|
||||
cf_client.delete_stack(StackName=stack_name)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
user = iam_client.get_user(UserName=user_name)
|
||||
e.exception.response["Error"]["Code"].should.equal("NoSuchEntity")
|
||||
|
||||
|
@ -6,7 +6,7 @@ import boto
|
||||
import boto3
|
||||
import sure # noqa
|
||||
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from boto.exception import BotoServerError
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_iam, mock_iam_deprecated
|
||||
@ -29,7 +29,7 @@ MOCK_POLICY = """
|
||||
def test_create_group():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_group("my-group")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.create_group("my-group")
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ def test_get_group():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_group("my-group")
|
||||
conn.get_group("my-group")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_group("not-group")
|
||||
|
||||
|
||||
@ -77,10 +77,10 @@ def test_get_all_groups():
|
||||
@mock_iam_deprecated()
|
||||
def test_add_user_to_group():
|
||||
conn = boto.connect_iam()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.add_user_to_group("my-group", "my-user")
|
||||
conn.create_group("my-group")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.add_user_to_group("my-group", "my-user")
|
||||
conn.create_user("my-user")
|
||||
conn.add_user_to_group("my-group", "my-user")
|
||||
@ -89,11 +89,11 @@ def test_add_user_to_group():
|
||||
@mock_iam_deprecated()
|
||||
def test_remove_user_from_group():
|
||||
conn = boto.connect_iam()
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.remove_user_from_group("my-group", "my-user")
|
||||
conn.create_group("my-group")
|
||||
conn.create_user("my-user")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.remove_user_from_group("my-group", "my-user")
|
||||
conn.add_user_to_group("my-group", "my-user")
|
||||
conn.remove_user_from_group("my-group", "my-user")
|
||||
@ -150,7 +150,7 @@ def test_attach_group_policies():
|
||||
def test_get_group_policy():
|
||||
conn = boto.connect_iam()
|
||||
conn.create_group("my-group")
|
||||
with assert_raises(BotoServerError):
|
||||
with pytest.raises(BotoServerError):
|
||||
conn.get_group_policy("my-group", "my-policy")
|
||||
|
||||
conn.put_group_policy("my-group", "my-policy", MOCK_POLICY)
|
||||
|
@ -2,7 +2,7 @@ import json
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
from moto import mock_iam
|
||||
|
||||
@ -1624,7 +1624,7 @@ def test_create_policy_with_valid_policy_documents():
|
||||
@mock_iam
|
||||
def check_create_policy_with_invalid_policy_document(test_case):
|
||||
conn = boto3.client("iam", region_name="us-east-1")
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
conn.create_policy(
|
||||
PolicyName="TestCreatePolicy",
|
||||
PolicyDocument=json.dumps(test_case["document"]),
|
||||
|
1
tests/test_iot/__init__.py
Normal file
1
tests/test_iot/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -6,7 +6,7 @@ import boto3
|
||||
|
||||
from moto import mock_iot
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
|
||||
def generate_thing_group_tree(iot_client, tree_dict, _parent=None):
|
||||
@ -643,7 +643,7 @@ def test_delete_policy_validation():
|
||||
client.create_policy(policyName=policy_name, policyDocument=doc)
|
||||
client.attach_principal_policy(policyName=policy_name, principal=cert_arn)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.delete_policy(policyName=policy_name)
|
||||
e.exception.response["Error"]["Message"].should.contain(
|
||||
"The policy cannot be deleted as the policy is attached to one or more principals (name=%s)"
|
||||
@ -684,7 +684,7 @@ def test_delete_certificate_validation():
|
||||
client.create_thing(thingName=thing_name)
|
||||
client.attach_thing_principal(thingName=thing_name, principal=cert_arn)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.delete_certificate(certificateId=cert_id)
|
||||
e.exception.response["Error"]["Message"].should.contain(
|
||||
"Certificate must be deactivated (not ACTIVE) before deletion."
|
||||
@ -693,7 +693,7 @@ def test_delete_certificate_validation():
|
||||
res.should.have.key("certificates").which.should.have.length_of(1)
|
||||
|
||||
client.update_certificate(certificateId=cert_id, newStatus="REVOKED")
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.delete_certificate(certificateId=cert_id)
|
||||
e.exception.response["Error"]["Message"].should.contain(
|
||||
"Things must be detached before deletion (arn: %s)" % cert_arn
|
||||
@ -702,7 +702,7 @@ def test_delete_certificate_validation():
|
||||
res.should.have.key("certificates").which.should.have.length_of(1)
|
||||
|
||||
client.detach_thing_principal(thingName=thing_name, principal=cert_arn)
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.delete_certificate(certificateId=cert_id)
|
||||
e.exception.response["Error"]["Message"].should.contain(
|
||||
"Certificate policies must be detached before deletion (arn: %s)" % cert_arn
|
||||
@ -798,7 +798,7 @@ def test_principal_policy():
|
||||
res.should.have.key("policies").which.should.have.length_of(0)
|
||||
res = client.list_policy_principals(policyName=policy_name)
|
||||
res.should.have.key("principals").which.should.have.length_of(0)
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
client.detach_policy(policyName=policy_name, target=cert_arn)
|
||||
e.exception.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
||||
|
||||
|
1
tests/test_iotdata/__init__.py
Normal file
1
tests/test_iotdata/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||
import json
|
||||
import boto3
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_iotdata, mock_iot
|
||||
|
||||
@ -17,7 +17,7 @@ def test_basic():
|
||||
raw_payload = b'{"state": {"desired": {"led": "on"}}}'
|
||||
iot_client.create_thing(thingName=name)
|
||||
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.get_thing_shadow(thingName=name)
|
||||
|
||||
res = client.update_thing_shadow(thingName=name, payload=raw_payload)
|
||||
@ -42,7 +42,7 @@ def test_basic():
|
||||
payload.should.have.key("timestamp")
|
||||
|
||||
client.delete_thing_shadow(thingName=name)
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.get_thing_shadow(thingName=name)
|
||||
|
||||
|
||||
@ -99,7 +99,7 @@ def test_update():
|
||||
payload.should.have.key("timestamp")
|
||||
|
||||
raw_payload = b'{"state": {"desired": {"led": "on"}}, "version": 1}'
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
client.update_thing_shadow(thingName=name, payload=raw_payload)
|
||||
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(409)
|
||||
ex.exception.response["Error"]["Message"].should.equal("Version conflict")
|
||||
|
1
tests/test_kinesis/__init__.py
Normal file
1
tests/test_kinesis/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
1
tests/test_kinesisvideo/__init__.py
Normal file
1
tests/test_kinesisvideo/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import boto3
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
from moto import mock_kinesisvideo
|
||||
from botocore.exceptions import ClientError
|
||||
import json
|
||||
@ -28,7 +28,7 @@ def test_create_stream_with_same_name():
|
||||
client.create_stream(StreamName=stream_name, DeviceName=device_name)
|
||||
|
||||
# cannot create with same stream name
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.create_stream(StreamName=stream_name, DeviceName=device_name)
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ def test_describe_stream():
|
||||
stream_arn = res["StreamARN"]
|
||||
|
||||
# cannot create with existing stream name
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.create_stream(StreamName=stream_name, DeviceName=device_name)
|
||||
|
||||
# stream can be described with name
|
||||
@ -69,7 +69,7 @@ def test_describe_stream_with_name_not_exist():
|
||||
stream_name_not_exist = "not-exist-stream"
|
||||
|
||||
# cannot describe with not exist stream name
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.describe_stream(StreamName=stream_name_not_exist)
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ def test_delete_stream_with_arn_not_exist():
|
||||
|
||||
# cannot delete with not exist stream
|
||||
stream_arn_not_exist = stream_2_arn
|
||||
with assert_raises(ClientError):
|
||||
with pytest.raises(ClientError):
|
||||
client.delete_stream(StreamARN=stream_arn_not_exist)
|
||||
|
||||
|
||||
|
1
tests/test_kinesisvideoarchivedmedia/__init__.py
Normal file
1
tests/test_kinesisvideoarchivedmedia/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
1
tests/test_kms/__init__.py
Normal file
1
tests/test_kms/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# This file is intentionally left blank.
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user