Techdebt: Replace sure with regular asserts in ECR (#6530)

This commit is contained in:
Bert Blommers 2023-07-17 10:21:32 +00:00 committed by GitHub
parent 79bd7c5bae
commit 58ad693c42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 703 additions and 811 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,8 @@
import copy
from string import Template
import boto3
import json
from moto import mock_cloudformation, mock_ecr
import sure # noqa # pylint: disable=unused-import
from string import Template
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
@ -45,12 +43,12 @@ def test_create_repository():
# then
repo_arn = f"arn:aws:ecr:eu-central-1:{ACCOUNT_ID}:repository/{name}"
stack = cfn_client.describe_stacks(StackName=stack_name)["Stacks"][0]
stack["Outputs"][0]["OutputValue"].should.equal(repo_arn)
assert stack["Outputs"][0]["OutputValue"] == repo_arn
ecr_client = boto3.client("ecr", region_name="eu-central-1")
response = ecr_client.describe_repositories(repositoryNames=[name])
response["repositories"][0]["repositoryArn"].should.equal(repo_arn)
assert response["repositories"][0]["repositoryArn"] == repo_arn
@mock_ecr
@ -78,10 +76,11 @@ def test_update_repository():
response = ecr_client.describe_repositories(repositoryNames=[name])
repo = response["repositories"][0]
repo["repositoryArn"].should.equal(
f"arn:aws:ecr:eu-central-1:{ACCOUNT_ID}:repository/{name}"
assert (
repo["repositoryArn"]
== f"arn:aws:ecr:eu-central-1:{ACCOUNT_ID}:repository/{name}"
)
repo["imageTagMutability"].should.equal("IMMUTABLE")
assert repo["imageTagMutability"] == "IMMUTABLE"
@mock_ecr
@ -100,4 +99,4 @@ def test_delete_repository():
# then
ecr_client = boto3.client("ecr", region_name="eu-central-1")
response = ecr_client.describe_repositories()["repositories"]
response.should.have.length_of(0)
assert len(response) == 0

View File

@ -1,7 +1,6 @@
import json
import pytest
import sure # noqa # pylint: disable=unused-import
from moto.ecr.exceptions import InvalidParameterException
from moto.ecr.policy_validation import EcrLifecyclePolicyValidator
@ -70,12 +69,11 @@ def test_validate_error_parse(policy):
# then
ex = e.value
ex.code.should.equal(400)
ex.error_type.should.equal("InvalidParameterException")
ex.message.should.equal(
"Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
"'Lifecycle policy validation failure: "
"Could not map policyString into LifecyclePolicy.'"
assert ex.code == 400
assert ex.error_type == "InvalidParameterException"
assert (
ex.message
== "Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: 'Lifecycle policy validation failure: Could not map policyString into LifecyclePolicy.'"
)
@ -108,12 +106,11 @@ def test_validate_error_extract_rules(policy):
# then
ex = e.value
ex.code.should.equal(400)
ex.error_type.should.equal("InvalidParameterException")
ex.message.should.equal(
"Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
"'Lifecycle policy validation failure: "
'object has missing required properties (["rules"])\''
assert ex.code == 400
assert ex.error_type == "InvalidParameterException"
assert (
ex.message
== "Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: 'Lifecycle policy validation failure: object has missing required properties ([\"rules\"])'"
)
@ -128,9 +125,9 @@ def test_validate_error_rule_type(rule):
# then
ex = e.value
ex.code.should.equal(400)
ex.error_type.should.equal("InvalidParameterException")
ex.message.should.equal(
assert ex.code == 400
assert ex.error_type == "InvalidParameterException"
assert ex.message == (
"Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
"'Lifecycle policy validation failure: "
f'instance type ({type(rule)}) does not match any allowed primitive type (allowed: ["object"])\''
@ -198,16 +195,11 @@ def test_validate_error_rule_properties(rule, error_msg):
# then
ex = e.value
ex.code.should.equal(400)
ex.error_type.should.equal("InvalidParameterException")
ex.message.should.equal(
"".join(
[
"Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
"'Lifecycle policy validation failure: ",
error_msg,
]
)
assert ex.code == 400
assert ex.error_type == "InvalidParameterException"
assert (
ex.message
== f"Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: 'Lifecycle policy validation failure: {error_msg}"
)
@ -258,16 +250,11 @@ def test_validate_error_action_properties(action, error_msg):
# then
ex = e.value
ex.code.should.equal(400)
ex.error_type.should.equal("InvalidParameterException")
ex.message.should.equal(
"".join(
[
"Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
"'Lifecycle policy validation failure: ",
error_msg,
]
)
assert ex.code == 400
assert ex.error_type == "InvalidParameterException"
assert (
ex.message
== f"Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: 'Lifecycle policy validation failure: {error_msg}"
)
@ -382,14 +369,9 @@ def test_validate_error_selection_properties(selection, error_msg):
# then
ex = e.value
ex.code.should.equal(400)
ex.error_type.should.equal("InvalidParameterException")
ex.message.should.equal(
"".join(
[
"Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
"'Lifecycle policy validation failure: ",
error_msg,
]
)
assert ex.code == 400
assert ex.error_type == "InvalidParameterException"
assert (
ex.message
== f"Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: 'Lifecycle policy validation failure: {error_msg}"
)