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:
Matěj Cepl 2020-10-06 07:54:49 +02:00
commit 77dc60ea97
146 changed files with 1172 additions and 1277 deletions

View file

@ -8,7 +8,7 @@ from boto.s3.lifecycle import Lifecycle, Transition, Expiration, Rule
import sure # noqa
from botocore.exceptions import ClientError
from datetime import datetime
from nose.tools import assert_raises
import pytest
from moto import mock_s3_deprecated, mock_s3
@ -56,7 +56,7 @@ def test_lifecycle_with_filters():
assert result["Rules"][0]["Filter"]["Prefix"] == ""
assert not result["Rules"][0]["Filter"].get("And")
assert not result["Rules"][0]["Filter"].get("Tag")
with assert_raises(KeyError):
with pytest.raises(KeyError):
assert result["Rules"][0]["Prefix"]
# Without any prefixes and an empty filter (this is by default a prefix for the whole bucket):
@ -75,12 +75,12 @@ def test_lifecycle_with_filters():
)
result = client.get_bucket_lifecycle_configuration(Bucket="bucket")
assert len(result["Rules"]) == 1
with assert_raises(KeyError):
with pytest.raises(KeyError):
assert result["Rules"][0]["Prefix"]
# If we remove the filter -- and don't specify a Prefix, then this is bad:
lfc["Rules"][0].pop("Filter")
with assert_raises(ClientError) as err:
with pytest.raises(ClientError) as err:
client.put_bucket_lifecycle_configuration(
Bucket="bucket", LifecycleConfiguration=lfc
)
@ -93,12 +93,12 @@ def test_lifecycle_with_filters():
)
result = client.get_bucket_lifecycle_configuration(Bucket="bucket")
assert len(result["Rules"]) == 1
with assert_raises(KeyError):
with pytest.raises(KeyError):
assert result["Rules"][0]["Filter"]["Prefix"]
assert not result["Rules"][0]["Filter"].get("And")
assert result["Rules"][0]["Filter"]["Tag"]["Key"] == "mytag"
assert result["Rules"][0]["Filter"]["Tag"]["Value"] == "mytagvalue"
with assert_raises(KeyError):
with pytest.raises(KeyError):
assert result["Rules"][0]["Prefix"]
# With And (single tag):
@ -118,7 +118,7 @@ def test_lifecycle_with_filters():
assert len(result["Rules"][0]["Filter"]["And"]["Tags"]) == 1
assert result["Rules"][0]["Filter"]["And"]["Tags"][0]["Key"] == "mytag"
assert result["Rules"][0]["Filter"]["And"]["Tags"][0]["Value"] == "mytagvalue"
with assert_raises(KeyError):
with pytest.raises(KeyError):
assert result["Rules"][0]["Prefix"]
# With multiple And tags:
@ -141,7 +141,7 @@ def test_lifecycle_with_filters():
assert result["Rules"][0]["Filter"]["And"]["Tags"][0]["Value"] == "mytagvalue"
assert result["Rules"][0]["Filter"]["And"]["Tags"][1]["Key"] == "mytag2"
assert result["Rules"][0]["Filter"]["And"]["Tags"][1]["Value"] == "mytagvalue2"
with assert_raises(KeyError):
with pytest.raises(KeyError):
assert result["Rules"][0]["Prefix"]
# And filter without Prefix but multiple Tags:
@ -156,26 +156,26 @@ def test_lifecycle_with_filters():
)
result = client.get_bucket_lifecycle_configuration(Bucket="bucket")
assert len(result["Rules"]) == 1
with assert_raises(KeyError):
with pytest.raises(KeyError):
assert result["Rules"][0]["Filter"]["And"]["Prefix"]
assert len(result["Rules"][0]["Filter"]["And"]["Tags"]) == 2
assert result["Rules"][0]["Filter"]["And"]["Tags"][0]["Key"] == "mytag"
assert result["Rules"][0]["Filter"]["And"]["Tags"][0]["Value"] == "mytagvalue"
assert result["Rules"][0]["Filter"]["And"]["Tags"][1]["Key"] == "mytag2"
assert result["Rules"][0]["Filter"]["And"]["Tags"][1]["Value"] == "mytagvalue2"
with assert_raises(KeyError):
with pytest.raises(KeyError):
assert result["Rules"][0]["Prefix"]
# Can't have both filter and prefix:
lfc["Rules"][0]["Prefix"] = ""
with assert_raises(ClientError) as err:
with pytest.raises(ClientError) as err:
client.put_bucket_lifecycle_configuration(
Bucket="bucket", LifecycleConfiguration=lfc
)
assert err.exception.response["Error"]["Code"] == "MalformedXML"
lfc["Rules"][0]["Prefix"] = "some/path"
with assert_raises(ClientError) as err:
with pytest.raises(ClientError) as err:
client.put_bucket_lifecycle_configuration(
Bucket="bucket", LifecycleConfiguration=lfc
)
@ -196,7 +196,7 @@ def test_lifecycle_with_filters():
"Prefix": "some/prefix",
"Tag": {"Key": "mytag", "Value": "mytagvalue"},
}
with assert_raises(ClientError) as err:
with pytest.raises(ClientError) as err:
client.put_bucket_lifecycle_configuration(
Bucket="bucket", LifecycleConfiguration=lfc
)
@ -212,7 +212,7 @@ def test_lifecycle_with_filters():
],
},
}
with assert_raises(ClientError) as err:
with pytest.raises(ClientError) as err:
client.put_bucket_lifecycle_configuration(
Bucket="bucket", LifecycleConfiguration=lfc
)
@ -279,7 +279,7 @@ def test_lifecycle_with_eodm():
# With failure:
lfc["Rules"][0]["Expiration"]["Days"] = 7
with assert_raises(ClientError) as err:
with pytest.raises(ClientError) as err:
client.put_bucket_lifecycle_configuration(
Bucket="bucket", LifecycleConfiguration=lfc
)
@ -287,7 +287,7 @@ def test_lifecycle_with_eodm():
del lfc["Rules"][0]["Expiration"]["Days"]
lfc["Rules"][0]["Expiration"]["Date"] = datetime(2015, 1, 1)
with assert_raises(ClientError) as err:
with pytest.raises(ClientError) as err:
client.put_bucket_lifecycle_configuration(
Bucket="bucket", LifecycleConfiguration=lfc
)
@ -383,7 +383,7 @@ def test_lifecycle_with_nvt():
# With failures for missing children:
del lfc["Rules"][0]["NoncurrentVersionTransitions"][0]["NoncurrentDays"]
with assert_raises(ClientError) as err:
with pytest.raises(ClientError) as err:
client.put_bucket_lifecycle_configuration(
Bucket="bucket", LifecycleConfiguration=lfc
)
@ -391,7 +391,7 @@ def test_lifecycle_with_nvt():
lfc["Rules"][0]["NoncurrentVersionTransitions"][0]["NoncurrentDays"] = 30
del lfc["Rules"][0]["NoncurrentVersionTransitions"][0]["StorageClass"]
with assert_raises(ClientError) as err:
with pytest.raises(ClientError) as err:
client.put_bucket_lifecycle_configuration(
Bucket="bucket", LifecycleConfiguration=lfc
)