Techdebt: Replace sure with regular assertions in ElasticTranscoder (#6545)

This commit is contained in:
Bert Blommers 2023-07-20 09:37:28 +00:00 committed by GitHub
parent 8db8556562
commit 774ff7cf6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 135 additions and 132 deletions

View File

@ -1,6 +1,5 @@
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
import boto3 import boto3
import sure # noqa # pylint: disable=unused-import
import pytest import pytest
from moto import mock_elastictranscoder from moto import mock_elastictranscoder
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
@ -18,29 +17,30 @@ def test_create_simple_pipeline():
OutputBucket="outputtest", OutputBucket="outputtest",
Role=role, Role=role,
) )
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(201) assert response["ResponseMetadata"]["HTTPStatusCode"] == 201
pipeline = response["Pipeline"] pipeline = response["Pipeline"]
pipeline.should.have.key("Id") assert pipeline["Name"] == "testpipeline"
pipeline.should.have.key("Name").being.equal("testpipeline") assert (
pipeline.should.have.key("Arn").being.equal( pipeline["Arn"]
f"arn:aws:elastictranscoder:{region}:{ACCOUNT_ID}:pipeline/{pipeline['Id']}" == f"arn:aws:elastictranscoder:{region}:{ACCOUNT_ID}:pipeline/{pipeline['Id']}"
) )
pipeline.should.have.key("Status").being.equal("Active") assert pipeline["Status"] == "Active"
pipeline.should.have.key("InputBucket").being.equal("inputtest") assert pipeline["InputBucket"] == "inputtest"
pipeline.should.have.key("OutputBucket").being.equal("outputtest") assert pipeline["OutputBucket"] == "outputtest"
pipeline.should.have.key("Role").being.equal(role) assert pipeline["Role"] == role
pipeline.should.have.key("Notifications").being.equal( assert pipeline["Notifications"] == {
{"Progressing": "", "Completed": "", "Warning": "", "Error": ""} "Progressing": "",
) "Completed": "",
pipeline.should.have.key("ContentConfig") "Warning": "",
pipeline["ContentConfig"].should.have.key("Bucket").being.equal("outputtest") "Error": "",
pipeline["ContentConfig"].should.have.key("Permissions").being.equal([]) }
pipeline.should.have.key("ThumbnailConfig") assert pipeline["ContentConfig"]["Bucket"] == "outputtest"
pipeline["ThumbnailConfig"].should.have.key("Bucket").being.equal("outputtest") assert pipeline["ContentConfig"]["Permissions"] == []
pipeline["ThumbnailConfig"].should.have.key("Permissions").being.equal([]) assert pipeline["ThumbnailConfig"]["Bucket"] == "outputtest"
assert pipeline["ThumbnailConfig"]["Permissions"] == []
response.should.have.key("Warnings").being.equal([]) assert response["Warnings"] == []
@mock_elastictranscoder @mock_elastictranscoder
@ -56,27 +56,28 @@ def test_create_pipeline_with_content_config():
ThumbnailConfig={"Bucket": "outputtest"}, ThumbnailConfig={"Bucket": "outputtest"},
Role=role, Role=role,
) )
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(201) assert response["ResponseMetadata"]["HTTPStatusCode"] == 201
pipeline = response["Pipeline"] pipeline = response["Pipeline"]
pipeline.should.have.key("Id") assert pipeline["Name"] == "testpipeline"
pipeline.should.have.key("Name").being.equal("testpipeline") assert (
pipeline.should.have.key("Arn").being.equal( pipeline["Arn"]
f"arn:aws:elastictranscoder:{region}:{ACCOUNT_ID}:pipeline/{pipeline['Id']}" == f"arn:aws:elastictranscoder:{region}:{ACCOUNT_ID}:pipeline/{pipeline['Id']}"
) )
pipeline.should.have.key("Status").being.equal("Active") assert pipeline["Status"] == "Active"
pipeline.should.have.key("InputBucket").being.equal("inputtest") assert pipeline["InputBucket"] == "inputtest"
pipeline.should.have.key("OutputBucket").being.equal("outputtest") assert pipeline["OutputBucket"] == "outputtest"
pipeline.should.have.key("Role").being.equal(role) assert pipeline["Role"] == role
pipeline.should.have.key("Notifications").being.equal( assert pipeline["Notifications"] == {
{"Progressing": "", "Completed": "", "Warning": "", "Error": ""} "Progressing": "",
) "Completed": "",
pipeline.should.have.key("ContentConfig") "Warning": "",
pipeline["ContentConfig"].should.have.key("Bucket").being.equal("outputtest") "Error": "",
pipeline["ContentConfig"].should.have.key("Permissions").being.equal([]) }
pipeline.should.have.key("ThumbnailConfig") assert pipeline["ContentConfig"]["Bucket"] == "outputtest"
pipeline["ThumbnailConfig"].should.have.key("Bucket").being.equal("outputtest") assert pipeline["ContentConfig"]["Permissions"] == []
pipeline["ThumbnailConfig"].should.have.key("Permissions").being.equal([]) assert pipeline["ThumbnailConfig"]["Bucket"] == "outputtest"
assert pipeline["ThumbnailConfig"]["Permissions"] == []
@mock_elastictranscoder @mock_elastictranscoder
@ -94,10 +95,8 @@ def test_create_pipeline_with_outputbucket_and_content_config():
Role=role, Role=role,
) )
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("ValidationException") assert err["Code"] == "ValidationException"
err["Message"].should.equal( assert err["Message"] == "[OutputBucket and ContentConfig are mutually exclusive.]"
"[OutputBucket and ContentConfig are mutually exclusive.]"
)
@mock_elastictranscoder @mock_elastictranscoder
@ -114,9 +113,10 @@ def test_create_pipeline_without_thumbnail_config():
Role=role, Role=role,
) )
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("ValidationException") assert err["Code"] == "ValidationException"
err["Message"].should.equal( assert (
"[ThumbnailConfig:Bucket is not allowed to be null if ContentConfig is specified.]" err["Message"]
== "[ThumbnailConfig:Bucket is not allowed to be null if ContentConfig is specified.]"
) )
@ -127,8 +127,8 @@ def test_create_pipeline_without_role():
with pytest.raises(ClientError) as ex: with pytest.raises(ClientError) as ex:
client.create_pipeline(Name="testpipeline", InputBucket="inputtest", Role="") client.create_pipeline(Name="testpipeline", InputBucket="inputtest", Role="")
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("ValidationException") assert err["Code"] == "ValidationException"
err["Message"].should.equal("Role cannot be blank") assert err["Message"] == "Role cannot be blank"
@mock_elastictranscoder @mock_elastictranscoder
@ -140,8 +140,8 @@ def test_create_pipeline_with_invalid_role():
Name="testpipeline", InputBucket="inputtest", Role="asdf" Name="testpipeline", InputBucket="inputtest", Role="asdf"
) )
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("ValidationException") assert err["Code"] == "ValidationException"
err["Message"].should.equal("Role ARN is invalid: asdf") assert err["Message"] == "Role ARN is invalid: asdf"
@mock_elastictranscoder @mock_elastictranscoder
@ -155,9 +155,10 @@ def test_create_pipeline_without_output():
Role=create_role_name("nonexistingrole"), Role=create_role_name("nonexistingrole"),
) )
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("ValidationException") assert err["Code"] == "ValidationException"
err["Message"].should.equal( assert (
"[OutputBucket and ContentConfig:Bucket are not allowed to both be null.]" err["Message"]
== "[OutputBucket and ContentConfig:Bucket are not allowed to both be null.]"
) )
@ -175,28 +176,29 @@ def test_list_pipelines():
) )
response = client.list_pipelines() response = client.list_pipelines()
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
response.should.have.key("Pipelines").being.length_of(1) assert len(response["Pipelines"]) == 1
pipeline = response["Pipelines"][0] pipeline = response["Pipelines"][0]
pipeline.should.have.key("Id") assert pipeline["Name"] == "testpipeline"
pipeline.should.have.key("Name").being.equal("testpipeline") assert (
pipeline.should.have.key("Arn").being.equal( pipeline["Arn"]
f"arn:aws:elastictranscoder:{region}:{ACCOUNT_ID}:pipeline/{pipeline['Id']}" == f"arn:aws:elastictranscoder:{region}:{ACCOUNT_ID}:pipeline/{pipeline['Id']}"
) )
pipeline.should.have.key("Status").being.equal("Active") assert pipeline["Status"] == "Active"
pipeline.should.have.key("InputBucket").being.equal("inputtest") assert pipeline["InputBucket"] == "inputtest"
pipeline.should.have.key("OutputBucket").being.equal("outputtest") assert pipeline["OutputBucket"] == "outputtest"
pipeline.should.have.key("Role").being.equal(role) assert pipeline["Role"] == role
pipeline.should.have.key("Notifications").being.equal( assert pipeline["Notifications"] == {
{"Progressing": "", "Completed": "", "Warning": "", "Error": ""} "Progressing": "",
) "Completed": "",
pipeline.should.have.key("ContentConfig") "Warning": "",
pipeline["ContentConfig"].should.have.key("Bucket").being.equal("outputtest") "Error": "",
pipeline["ContentConfig"].should.have.key("Permissions").being.equal([]) }
pipeline.should.have.key("ThumbnailConfig") assert pipeline["ContentConfig"]["Bucket"] == "outputtest"
pipeline["ThumbnailConfig"].should.have.key("Bucket").being.equal("outputtest") assert pipeline["ContentConfig"]["Permissions"] == []
pipeline["ThumbnailConfig"].should.have.key("Permissions").being.equal([]) assert pipeline["ThumbnailConfig"]["Bucket"] == "outputtest"
assert pipeline["ThumbnailConfig"]["Permissions"] == []
@mock_elastictranscoder @mock_elastictranscoder
@ -214,28 +216,28 @@ def test_read_pipeline():
response = client.read_pipeline(Id=pipeline["Id"]) response = client.read_pipeline(Id=pipeline["Id"])
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
response.should.have.key("Pipeline")
pipeline = response["Pipeline"] pipeline = response["Pipeline"]
pipeline.should.have.key("Id") assert pipeline["Name"] == "testpipeline"
pipeline.should.have.key("Name").being.equal("testpipeline") assert (
pipeline.should.have.key("Arn").being.equal( pipeline["Arn"]
f"arn:aws:elastictranscoder:{region}:{ACCOUNT_ID}:pipeline/{pipeline['Id']}" == f"arn:aws:elastictranscoder:{region}:{ACCOUNT_ID}:pipeline/{pipeline['Id']}"
) )
pipeline.should.have.key("Status").being.equal("Active") assert pipeline["Status"] == "Active"
pipeline.should.have.key("InputBucket").being.equal("inputtest") assert pipeline["InputBucket"] == "inputtest"
pipeline.should.have.key("OutputBucket").being.equal("outputtest") assert pipeline["OutputBucket"] == "outputtest"
pipeline.should.have.key("Role").being.equal(role) assert pipeline["Role"] == role
pipeline.should.have.key("Notifications").being.equal( assert pipeline["Notifications"] == {
{"Progressing": "", "Completed": "", "Warning": "", "Error": ""} "Progressing": "",
) "Completed": "",
pipeline.should.have.key("ContentConfig") "Warning": "",
pipeline["ContentConfig"].should.have.key("Bucket").being.equal("outputtest") "Error": "",
pipeline["ContentConfig"].should.have.key("Permissions").being.equal([]) }
pipeline.should.have.key("ThumbnailConfig") assert pipeline["ContentConfig"]["Bucket"] == "outputtest"
pipeline["ThumbnailConfig"].should.have.key("Bucket").being.equal("outputtest") assert pipeline["ContentConfig"]["Permissions"] == []
pipeline["ThumbnailConfig"].should.have.key("Permissions").being.equal([]) assert pipeline["ThumbnailConfig"]["Bucket"] == "outputtest"
assert pipeline["ThumbnailConfig"]["Permissions"] == []
@mock_elastictranscoder @mock_elastictranscoder
@ -246,9 +248,10 @@ def test_read_unknown_pipeline_format():
with pytest.raises(ClientError) as ex: with pytest.raises(ClientError) as ex:
client.read_pipeline(Id="unknown-pipeline") client.read_pipeline(Id="unknown-pipeline")
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("ValidationException") assert err["Code"] == "ValidationException"
err["Message"].should.equal( assert (
"1 validation error detected: Value 'unknown-pipeline' at 'id' failed to satisfy constraint: Member must satisfy regular expression pattern: ^\\d{13}-\\w{6}$" err["Message"]
== "1 validation error detected: Value 'unknown-pipeline' at 'id' failed to satisfy constraint: Member must satisfy regular expression pattern: ^\\d{13}-\\w{6}$"
) )
@ -261,9 +264,10 @@ def test_read_nonexisting_pipeline_format():
with pytest.raises(ClientError) as ex: with pytest.raises(ClientError) as ex:
client.read_pipeline(Id=pipeline_id) client.read_pipeline(Id=pipeline_id)
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException") assert err["Code"] == "ResourceNotFoundException"
err["Message"].should.equal( assert (
f"The specified pipeline was not found: account={ACCOUNT_ID}, pipelineId={pipeline_id}." err["Message"]
== f"The specified pipeline was not found: account={ACCOUNT_ID}, pipelineId={pipeline_id}."
) )
@ -281,28 +285,28 @@ def test_update_pipeline_name():
)["Pipeline"] )["Pipeline"]
response = client.update_pipeline(Id=pipeline["Id"], Name="newtestpipeline") response = client.update_pipeline(Id=pipeline["Id"], Name="newtestpipeline")
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
response.should.have.key("Pipeline")
pipeline = response["Pipeline"] pipeline = response["Pipeline"]
pipeline.should.have.key("Id") assert pipeline["Name"] == "newtestpipeline"
pipeline.should.have.key("Name").being.equal("newtestpipeline") assert (
pipeline.should.have.key("Arn").being.equal( pipeline["Arn"]
f"arn:aws:elastictranscoder:{region}:{ACCOUNT_ID}:pipeline/{pipeline['Id']}" == f"arn:aws:elastictranscoder:{region}:{ACCOUNT_ID}:pipeline/{pipeline['Id']}"
) )
pipeline.should.have.key("Status").being.equal("Active") assert pipeline["Status"] == "Active"
pipeline.should.have.key("InputBucket").being.equal("inputtest") assert pipeline["InputBucket"] == "inputtest"
pipeline.should.have.key("OutputBucket").being.equal("outputtest") assert pipeline["OutputBucket"] == "outputtest"
pipeline.should.have.key("Role").being.equal(role) assert pipeline["Role"] == role
pipeline.should.have.key("Notifications").being.equal( assert pipeline["Notifications"] == {
{"Progressing": "", "Completed": "", "Warning": "", "Error": ""} "Progressing": "",
) "Completed": "",
pipeline.should.have.key("ContentConfig") "Warning": "",
pipeline["ContentConfig"].should.have.key("Bucket").being.equal("outputtest") "Error": "",
pipeline["ContentConfig"].should.have.key("Permissions").being.equal([]) }
pipeline.should.have.key("ThumbnailConfig") assert pipeline["ContentConfig"]["Bucket"] == "outputtest"
pipeline["ThumbnailConfig"].should.have.key("Bucket").being.equal("outputtest") assert pipeline["ContentConfig"]["Permissions"] == []
pipeline["ThumbnailConfig"].should.have.key("Permissions").being.equal([]) assert pipeline["ThumbnailConfig"]["Bucket"] == "outputtest"
assert pipeline["ThumbnailConfig"]["Permissions"] == []
@mock_elastictranscoder @mock_elastictranscoder
@ -322,14 +326,13 @@ def test_update_pipeline_input_and_role():
Id=pipeline["Id"], InputBucket="inputtest2", Role=newrole Id=pipeline["Id"], InputBucket="inputtest2", Role=newrole
) )
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
response.should.have.key("Pipeline")
pipeline = response["Pipeline"] pipeline = response["Pipeline"]
pipeline.should.have.key("Id") assert "Id" in pipeline
pipeline.should.have.key("Name").being.equal("testpipeline") assert pipeline["Name"] == "testpipeline"
pipeline.should.have.key("InputBucket").being.equal("inputtest2") assert pipeline["InputBucket"] == "inputtest2"
pipeline.should.have.key("Role").being.equal(newrole) assert pipeline["Role"] == newrole
@mock_elastictranscoder @mock_elastictranscoder
@ -340,9 +343,10 @@ def test_update_pipeline_with_invalid_id():
with pytest.raises(ClientError) as ex: with pytest.raises(ClientError) as ex:
client.update_pipeline(Id="unknown-pipeline") client.update_pipeline(Id="unknown-pipeline")
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("ValidationException") assert err["Code"] == "ValidationException"
err["Message"].should.equal( assert (
"1 validation error detected: Value 'unknown-pipeline' at 'id' failed to satisfy constraint: Member must satisfy regular expression pattern: ^\\d{13}-\\w{6}$" err["Message"]
== "1 validation error detected: Value 'unknown-pipeline' at 'id' failed to satisfy constraint: Member must satisfy regular expression pattern: ^\\d{13}-\\w{6}$"
) )
@ -355,9 +359,10 @@ def test_update_nonexisting_pipeline():
with pytest.raises(ClientError) as ex: with pytest.raises(ClientError) as ex:
client.read_pipeline(Id=pipeline_id) client.read_pipeline(Id=pipeline_id)
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException") assert err["Code"] == "ResourceNotFoundException"
err["Message"].should.equal( assert (
f"The specified pipeline was not found: account={ACCOUNT_ID}, pipelineId={pipeline_id}." err["Message"]
== f"The specified pipeline was not found: account={ACCOUNT_ID}, pipelineId={pipeline_id}."
) )
@ -376,8 +381,8 @@ def test_delete_pipeline():
client.delete_pipeline(Id=pipeline["Id"]) client.delete_pipeline(Id=pipeline["Id"])
response = client.list_pipelines() response = client.list_pipelines()
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
response.should.have.key("Pipelines").being.length_of(0) assert len(response["Pipelines"]) == 0
def create_role_name(name): def create_role_name(name):

View File

@ -1,5 +1,3 @@
import sure # noqa # pylint: disable=unused-import
import moto.server as server import moto.server as server
from moto import mock_elastictranscoder from moto import mock_elastictranscoder
@ -14,4 +12,4 @@ def test_elastictranscoder_list():
test_client = backend.test_client() test_client = backend.test_client()
res = test_client.get("/2012-09-25/pipelines") res = test_client.get("/2012-09-25/pipelines")
res.data.should.contain(b"Pipelines") assert b"Pipelines" in res.data