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
146 changed files with 1172 additions and 1277 deletions
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue