Skip to content

Commit

Permalink
Port test suite from nose to pytest.
Browse files Browse the repository at this point in the history
This just eliminates all errors on the tests collection. Elimination of
failures is left to the next commit.
  • Loading branch information
mcepl committed Nov 10, 2020
1 parent 47dbad2 commit 77dc60e
Show file tree
Hide file tree
Showing 146 changed files with 1,172 additions and 1,277 deletions.
4 changes: 2 additions & 2 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nose
pytest
sure==1.4.11
freezegun
parameterized>=0.7.0
parameterized>=0.7.0
6 changes: 0 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
[nosetests]
verbosity=1
detailed-errors=1
with-coverage=1
cover-package=moto

[bdist_wheel]
universal=1
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
logging.getLogger("boto").setLevel(logging.CRITICAL)
logging.getLogger("boto3").setLevel(logging.CRITICAL)
logging.getLogger("botocore").setLevel(logging.CRITICAL)
logging.getLogger("nose").setLevel(logging.CRITICAL)
41 changes: 0 additions & 41 deletions tests/backport_assert_raises.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import unicode_literals
import boto
from nose.plugins.skip import SkipTest
from unittest import SkipTest
import six


Expand Down
1 change: 1 addition & 0 deletions tests/test_acm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file is intentionally left blank.
1 change: 1 addition & 0 deletions tests/test_acm/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file is intentionally left blank.
1 change: 1 addition & 0 deletions tests/test_apigateway/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file is intentionally left blank.
52 changes: 26 additions & 26 deletions tests/test_apigateway/test_apigateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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")
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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="",
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -2030,23 +2030,23 @@ 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(
"Invalid API Key identifier specified"
)

# 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(
"Invalid Usage Plan ID specified"
)

# 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(
Expand Down
12 changes: 6 additions & 6 deletions tests/test_applicationautoscaling/test_applicationautoscaling.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 77dc60e

Please sign in to comment.