2021-08-28 06:30:40 +00:00
import boto3
import pytest
2023-11-30 15:55:51 +00:00
from botocore . exceptions import ClientError
2024-01-07 12:03:33 +00:00
from moto import mock_aws
2022-08-13 09:49:43 +00:00
from moto . core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
2021-08-28 06:30:40 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_create_simple_pipeline ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
role = create_role_name ( " nonexistingrole " )
response = client . create_pipeline (
Name = " testpipeline " ,
InputBucket = " inputtest " ,
OutputBucket = " outputtest " ,
Role = role ,
)
2023-07-20 09:37:28 +00:00
assert response [ " ResponseMetadata " ] [ " HTTPStatusCode " ] == 201
2021-08-28 06:30:40 +00:00
pipeline = response [ " Pipeline " ]
2023-07-20 09:37:28 +00:00
assert pipeline [ " Name " ] == " testpipeline "
assert (
pipeline [ " Arn " ]
== f " arn:aws:elastictranscoder: { region } : { ACCOUNT_ID } :pipeline/ { pipeline [ ' Id ' ] } "
2021-08-28 06:30:40 +00:00
)
2023-07-20 09:37:28 +00:00
assert pipeline [ " Status " ] == " Active "
assert pipeline [ " InputBucket " ] == " inputtest "
assert pipeline [ " OutputBucket " ] == " outputtest "
assert pipeline [ " Role " ] == role
assert pipeline [ " Notifications " ] == {
" Progressing " : " " ,
" Completed " : " " ,
" Warning " : " " ,
" Error " : " " ,
}
assert pipeline [ " ContentConfig " ] [ " Bucket " ] == " outputtest "
assert pipeline [ " ContentConfig " ] [ " Permissions " ] == [ ]
assert pipeline [ " ThumbnailConfig " ] [ " Bucket " ] == " outputtest "
assert pipeline [ " ThumbnailConfig " ] [ " Permissions " ] == [ ]
assert response [ " Warnings " ] == [ ]
2021-08-28 06:30:40 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_create_pipeline_with_content_config ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
role = create_role_name ( " nonexistingrole " )
response = client . create_pipeline (
Name = " testpipeline " ,
InputBucket = " inputtest " ,
ContentConfig = { " Bucket " : " outputtest " } ,
ThumbnailConfig = { " Bucket " : " outputtest " } ,
Role = role ,
)
2023-07-20 09:37:28 +00:00
assert response [ " ResponseMetadata " ] [ " HTTPStatusCode " ] == 201
2021-08-28 06:30:40 +00:00
pipeline = response [ " Pipeline " ]
2023-07-20 09:37:28 +00:00
assert pipeline [ " Name " ] == " testpipeline "
assert (
pipeline [ " Arn " ]
== f " arn:aws:elastictranscoder: { region } : { ACCOUNT_ID } :pipeline/ { pipeline [ ' Id ' ] } "
2021-08-28 06:30:40 +00:00
)
2023-07-20 09:37:28 +00:00
assert pipeline [ " Status " ] == " Active "
assert pipeline [ " InputBucket " ] == " inputtest "
assert pipeline [ " OutputBucket " ] == " outputtest "
assert pipeline [ " Role " ] == role
assert pipeline [ " Notifications " ] == {
" Progressing " : " " ,
" Completed " : " " ,
" Warning " : " " ,
" Error " : " " ,
}
assert pipeline [ " ContentConfig " ] [ " Bucket " ] == " outputtest "
assert pipeline [ " ContentConfig " ] [ " Permissions " ] == [ ]
assert pipeline [ " ThumbnailConfig " ] [ " Bucket " ] == " outputtest "
assert pipeline [ " ThumbnailConfig " ] [ " Permissions " ] == [ ]
2021-08-28 06:30:40 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_create_pipeline_with_outputbucket_and_content_config ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
role = create_role_name ( " nonexistingrole " )
with pytest . raises ( ClientError ) as ex :
client . create_pipeline (
Name = " testpipeline " ,
InputBucket = " inputtest " ,
OutputBucket = " outputtest " ,
ContentConfig = { " Bucket " : " configoutputtest " } ,
Role = role ,
)
err = ex . value . response [ " Error " ]
2023-07-20 09:37:28 +00:00
assert err [ " Code " ] == " ValidationException "
assert err [ " Message " ] == " [OutputBucket and ContentConfig are mutually exclusive.] "
2021-08-28 06:30:40 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_create_pipeline_without_thumbnail_config ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
role = create_role_name ( " nonexistingrole " )
with pytest . raises ( ClientError ) as ex :
client . create_pipeline (
Name = " testpipeline " ,
InputBucket = " inputtest " ,
ContentConfig = { " Bucket " : " outputtest " } ,
Role = role ,
)
err = ex . value . response [ " Error " ]
2023-07-20 09:37:28 +00:00
assert err [ " Code " ] == " ValidationException "
assert (
err [ " Message " ]
== " [ThumbnailConfig:Bucket is not allowed to be null if ContentConfig is specified.] "
2021-08-28 06:30:40 +00:00
)
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_create_pipeline_without_role ( ) :
client = boto3 . client ( " elastictranscoder " , region_name = " us-east-1 " )
with pytest . raises ( ClientError ) as ex :
client . create_pipeline ( Name = " testpipeline " , InputBucket = " inputtest " , Role = " " )
err = ex . value . response [ " Error " ]
2023-07-20 09:37:28 +00:00
assert err [ " Code " ] == " ValidationException "
assert err [ " Message " ] == " Role cannot be blank "
2021-08-28 06:30:40 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_create_pipeline_with_invalid_role ( ) :
client = boto3 . client ( " elastictranscoder " , region_name = " us-east-1 " )
with pytest . raises ( ClientError ) as ex :
client . create_pipeline (
Name = " testpipeline " , InputBucket = " inputtest " , Role = " asdf "
)
err = ex . value . response [ " Error " ]
2023-07-20 09:37:28 +00:00
assert err [ " Code " ] == " ValidationException "
assert err [ " Message " ] == " Role ARN is invalid: asdf "
2021-08-28 06:30:40 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_create_pipeline_without_output ( ) :
client = boto3 . client ( " elastictranscoder " , region_name = " us-east-1 " )
with pytest . raises ( ClientError ) as ex :
client . create_pipeline (
Name = " testpipeline " ,
InputBucket = " inputtest " ,
Role = create_role_name ( " nonexistingrole " ) ,
)
err = ex . value . response [ " Error " ]
2023-07-20 09:37:28 +00:00
assert err [ " Code " ] == " ValidationException "
assert (
err [ " Message " ]
== " [OutputBucket and ContentConfig:Bucket are not allowed to both be null.] "
2021-08-28 06:30:40 +00:00
)
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_list_pipelines ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
role = create_role_name ( " nonexistingrole " )
client . create_pipeline (
Name = " testpipeline " ,
InputBucket = " inputtest " ,
OutputBucket = " outputtest " ,
Role = role ,
)
response = client . list_pipelines ( )
2023-07-20 09:37:28 +00:00
assert response [ " ResponseMetadata " ] [ " HTTPStatusCode " ] == 200
assert len ( response [ " Pipelines " ] ) == 1
2021-08-28 06:30:40 +00:00
pipeline = response [ " Pipelines " ] [ 0 ]
2023-07-20 09:37:28 +00:00
assert pipeline [ " Name " ] == " testpipeline "
assert (
pipeline [ " Arn " ]
== f " arn:aws:elastictranscoder: { region } : { ACCOUNT_ID } :pipeline/ { pipeline [ ' Id ' ] } "
2021-08-28 06:30:40 +00:00
)
2023-07-20 09:37:28 +00:00
assert pipeline [ " Status " ] == " Active "
assert pipeline [ " InputBucket " ] == " inputtest "
assert pipeline [ " OutputBucket " ] == " outputtest "
assert pipeline [ " Role " ] == role
assert pipeline [ " Notifications " ] == {
" Progressing " : " " ,
" Completed " : " " ,
" Warning " : " " ,
" Error " : " " ,
}
assert pipeline [ " ContentConfig " ] [ " Bucket " ] == " outputtest "
assert pipeline [ " ContentConfig " ] [ " Permissions " ] == [ ]
assert pipeline [ " ThumbnailConfig " ] [ " Bucket " ] == " outputtest "
assert pipeline [ " ThumbnailConfig " ] [ " Permissions " ] == [ ]
2021-08-28 06:30:40 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_read_pipeline ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
role = create_role_name ( " nonexistingrole " )
pipeline = client . create_pipeline (
Name = " testpipeline " ,
InputBucket = " inputtest " ,
OutputBucket = " outputtest " ,
Role = role ,
) [ " Pipeline " ]
response = client . read_pipeline ( Id = pipeline [ " Id " ] )
2023-07-20 09:37:28 +00:00
assert response [ " ResponseMetadata " ] [ " HTTPStatusCode " ] == 200
2021-08-28 06:30:40 +00:00
pipeline = response [ " Pipeline " ]
2023-07-20 09:37:28 +00:00
assert pipeline [ " Name " ] == " testpipeline "
assert (
pipeline [ " Arn " ]
== f " arn:aws:elastictranscoder: { region } : { ACCOUNT_ID } :pipeline/ { pipeline [ ' Id ' ] } "
2021-08-28 06:30:40 +00:00
)
2023-07-20 09:37:28 +00:00
assert pipeline [ " Status " ] == " Active "
assert pipeline [ " InputBucket " ] == " inputtest "
assert pipeline [ " OutputBucket " ] == " outputtest "
assert pipeline [ " Role " ] == role
assert pipeline [ " Notifications " ] == {
" Progressing " : " " ,
" Completed " : " " ,
" Warning " : " " ,
" Error " : " " ,
}
assert pipeline [ " ContentConfig " ] [ " Bucket " ] == " outputtest "
assert pipeline [ " ContentConfig " ] [ " Permissions " ] == [ ]
assert pipeline [ " ThumbnailConfig " ] [ " Bucket " ] == " outputtest "
assert pipeline [ " ThumbnailConfig " ] [ " Permissions " ] == [ ]
2021-08-28 06:30:40 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_read_unknown_pipeline_format ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
with pytest . raises ( ClientError ) as ex :
client . read_pipeline ( Id = " unknown-pipeline " )
err = ex . value . response [ " Error " ]
2023-07-20 09:37:28 +00:00
assert err [ " Code " ] == " ValidationException "
assert (
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} $ "
2021-08-28 06:30:40 +00:00
)
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_read_nonexisting_pipeline_format ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
pipeline_id = " 0000000000000-abcdef "
with pytest . raises ( ClientError ) as ex :
client . read_pipeline ( Id = pipeline_id )
err = ex . value . response [ " Error " ]
2023-07-20 09:37:28 +00:00
assert err [ " Code " ] == " ResourceNotFoundException "
assert (
err [ " Message " ]
== f " The specified pipeline was not found: account= { ACCOUNT_ID } , pipelineId= { pipeline_id } . "
2021-08-28 06:30:40 +00:00
)
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_update_pipeline_name ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
role = create_role_name ( " nonexistingrole " )
pipeline = client . create_pipeline (
Name = " testpipeline " ,
InputBucket = " inputtest " ,
OutputBucket = " outputtest " ,
Role = role ,
) [ " Pipeline " ]
response = client . update_pipeline ( Id = pipeline [ " Id " ] , Name = " newtestpipeline " )
2023-07-20 09:37:28 +00:00
assert response [ " ResponseMetadata " ] [ " HTTPStatusCode " ] == 200
2021-08-28 06:30:40 +00:00
pipeline = response [ " Pipeline " ]
2023-07-20 09:37:28 +00:00
assert pipeline [ " Name " ] == " newtestpipeline "
assert (
pipeline [ " Arn " ]
== f " arn:aws:elastictranscoder: { region } : { ACCOUNT_ID } :pipeline/ { pipeline [ ' Id ' ] } "
2021-08-28 06:30:40 +00:00
)
2023-07-20 09:37:28 +00:00
assert pipeline [ " Status " ] == " Active "
assert pipeline [ " InputBucket " ] == " inputtest "
assert pipeline [ " OutputBucket " ] == " outputtest "
assert pipeline [ " Role " ] == role
assert pipeline [ " Notifications " ] == {
" Progressing " : " " ,
" Completed " : " " ,
" Warning " : " " ,
" Error " : " " ,
}
assert pipeline [ " ContentConfig " ] [ " Bucket " ] == " outputtest "
assert pipeline [ " ContentConfig " ] [ " Permissions " ] == [ ]
assert pipeline [ " ThumbnailConfig " ] [ " Bucket " ] == " outputtest "
assert pipeline [ " ThumbnailConfig " ] [ " Permissions " ] == [ ]
2021-08-28 06:30:40 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_update_pipeline_input_and_role ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
role = create_role_name ( " nonexistingrole " )
newrole = create_role_name ( " newrole " )
pipeline = client . create_pipeline (
Name = " testpipeline " ,
InputBucket = " inputtest " ,
OutputBucket = " outputtest " ,
Role = role ,
) [ " Pipeline " ]
response = client . update_pipeline (
Id = pipeline [ " Id " ] , InputBucket = " inputtest2 " , Role = newrole
)
2023-07-20 09:37:28 +00:00
assert response [ " ResponseMetadata " ] [ " HTTPStatusCode " ] == 200
2021-08-28 06:30:40 +00:00
pipeline = response [ " Pipeline " ]
2023-07-20 09:37:28 +00:00
assert " Id " in pipeline
assert pipeline [ " Name " ] == " testpipeline "
assert pipeline [ " InputBucket " ] == " inputtest2 "
assert pipeline [ " Role " ] == newrole
2021-08-28 06:30:40 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_update_pipeline_with_invalid_id ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
with pytest . raises ( ClientError ) as ex :
client . update_pipeline ( Id = " unknown-pipeline " )
err = ex . value . response [ " Error " ]
2023-07-20 09:37:28 +00:00
assert err [ " Code " ] == " ValidationException "
assert (
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} $ "
2021-08-28 06:30:40 +00:00
)
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_update_nonexisting_pipeline ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
pipeline_id = " 0000000000000-abcdef "
with pytest . raises ( ClientError ) as ex :
client . read_pipeline ( Id = pipeline_id )
err = ex . value . response [ " Error " ]
2023-07-20 09:37:28 +00:00
assert err [ " Code " ] == " ResourceNotFoundException "
assert (
err [ " Message " ]
== f " The specified pipeline was not found: account= { ACCOUNT_ID } , pipelineId= { pipeline_id } . "
2021-08-28 06:30:40 +00:00
)
2024-01-07 12:03:33 +00:00
@mock_aws
2021-08-28 06:30:40 +00:00
def test_delete_pipeline ( ) :
region = " us-east-1 "
client = boto3 . client ( " elastictranscoder " , region_name = region )
role = create_role_name ( " nonexistingrole " )
pipeline = client . create_pipeline (
Name = " testpipeline " ,
InputBucket = " inputtest " ,
OutputBucket = " outputtest " ,
Role = role ,
) [ " Pipeline " ]
client . delete_pipeline ( Id = pipeline [ " Id " ] )
response = client . list_pipelines ( )
2023-07-20 09:37:28 +00:00
assert response [ " ResponseMetadata " ] [ " HTTPStatusCode " ] == 200
assert len ( response [ " Pipelines " ] ) == 0
2021-08-28 06:30:40 +00:00
def create_role_name ( name ) :
2022-11-17 22:41:08 +00:00
return f " arn:aws:iam:: { ACCOUNT_ID } :role/ { name } "