"""Test validation of job messages.""" import pytest from transcoding.constants import exceptions as transcoding_exceptions from transcoding.validation.validate_job import validate_transcoding_job_schema @pytest.fixture def correct_sqs_message(): """Return valid job sqs message.""" return { 'transcoding_job_id': 1, 'input_bucket': 'ows-transcoding-raw', 'input_key': 'c85cc331-c08f-46fd-906d-793ef224eb1f.wav', 'output_bucket': 'ows-transcoding-raw', 'output_key': '4e6e4670-03f4-4a34-8d92-123123dc.wav', 'container': 'm4a', 'channels': 4, 'codec': 'PCM', 'sample_rate': 44100, 'bit_rate': 1411200, 'bit_depth': 16 } @pytest.fixture def correct_passthrough_sqs_message(): """Return valid passthrough job sqs message.""" return { 'transcoding_job_id': 1, 'input_bucket': 'ows-transcoding-raw', 'input_key': 'c85cc331-c08f-46fd-906d-793ef224eb1f.wav', 'output_bucket': 'ows-transcoding-raw', 'output_key': '4e6e4670-03f4-4a34-8d92-123123dc.wav', 'pass_thru': True } def test_validation_success(correct_sqs_message): """Test for validation of correct message.""" result = validate_transcoding_job_schema(correct_sqs_message, False) assert result is True def test_passthrough_validation_success(correct_passthrough_sqs_message): """Test for validation of correct passthrough message.""" result = validate_transcoding_job_schema( correct_passthrough_sqs_message, True) assert result is True @pytest.mark.parametrize( 'missing_field', ['transcoding_job_id', 'input_bucket', 'input_key', 'output_bucket', 'output_key', 'container', 'channels', 'codec', 'sample_rate', 'bit_rate', 'bit_depth']) def test_validation_missing_field(correct_sqs_message, missing_field): """Test for missing required field.""" del correct_sqs_message[missing_field] with pytest.raises(transcoding_exceptions.TranscodingFatalError): validate_transcoding_job_schema(correct_sqs_message, False) @pytest.mark.parametrize( 'missing_field', ['transcoding_job_id', 'input_bucket', 'input_key', 'output_bucket', 'output_key', 'pass_thru']) def test_passthrough_validation_missing_field( correct_passthrough_sqs_message, missing_field): """Test for missing required field in passthrough message.""" del correct_passthrough_sqs_message[missing_field] with pytest.raises(transcoding_exceptions.TranscodingFatalError): validate_transcoding_job_schema( correct_passthrough_sqs_message, True) @pytest.mark.parametrize( 'integer_field', ['transcoding_job_id', 'channels', 'sample_rate', 'bit_rate', 'bit_depth']) def test_validation_integer_field(correct_sqs_message, integer_field): """Test for integer fields validation.""" correct_sqs_message[integer_field] = str( correct_sqs_message[integer_field]) with pytest.raises(transcoding_exceptions.TranscodingFatalError): validate_transcoding_job_schema(correct_sqs_message, False) @pytest.mark.parametrize( 'integer_field', ['transcoding_job_id', 'channels', 'sample_rate', 'bit_rate', 'bit_depth']) def test_validation_integer_field_not_null( correct_sqs_message, integer_field): """Test for integer fields not null validation.""" correct_sqs_message[integer_field] = None with pytest.raises(transcoding_exceptions.TranscodingFatalError): validate_transcoding_job_schema(correct_sqs_message, False) @pytest.mark.parametrize( 'integer_field', ['transcoding_job_id', 'channels', 'sample_rate', 'bit_rate', 'bit_depth']) def test_validation_integer_field_not_empty( correct_sqs_message, integer_field): """Test for integer fields not empty validation.""" correct_sqs_message[integer_field] = '' with pytest.raises(transcoding_exceptions.TranscodingFatalError): validate_transcoding_job_schema(correct_sqs_message, False)