"""Negative tests for oat endpoints.""" import pytest from tests.integration import config from tests.integration.consts import api from tests.integration.test_helpers import api as api_calls from tests.integration.test_helpers import utils pytestmark = pytest.mark.skipif( config.SKIP_NEGATIVE_TESTS, reason='tests skipped by config') def test_assets_by_ids_and_types_bad_type(): """Test GET /assets_by_ids_and_types fails with bad object type.""" response = api_calls.asset.get_by_ids_and_types(['1', '2'], ['episode', 'cow']) response_body = utils.validate_response_status(response, api.STATUS_BAD_REQUEST) assert response_body == { 'message': { 'object_types': [ 'Invalid object type passed in cow.' ] } } def test_assets_by_ids_and_types_count_mismatched(): """Test GET /assets_by_ids_and_types fails with not equal parameters number.""" response = api_calls.asset.get_by_ids_and_types(['1', '2'], ['episode', 'podcast', 'adupload']) response_body = utils.validate_response_status(response, api.STATUS_BAD_REQUEST) assert response_body == { 'message': { '_schema': [ 'object_ids and object_types arent the same size' ] } } def test_assets_by_ids_and_type_bad_type(): """Test GET /assets_by_ids_and_type fails with bad object type.""" response = api_calls.asset.get_by_ids_and_type(['1', '2'], 'cow') response_body = utils.validate_response_status(response, api.STATUS_BAD_REQUEST) assert response_body == { 'message': 'Invalid object type: cow' } def test_post_asset_upload_not_found(): """Test POST /upload fails if asset_upload is not found.""" response = api_calls.asset.post( object_id='test-asset-1', object_type='podcast', filename='some-non-existing-filename', original_filename='original-filename', asset_type=api.ASSET_TYPE_JPG ) response_body = utils.validate_response_status(response, api.STATUS_NOT_FOUND) assert response_body == {'message': 'Asset upload not found'} def test_post_asset_bad_schema(): """Test POST /upload fails for parameters validation.""" upload_token = utils.validate_response_status( api_calls.asset.get_upload_token() ) payload = dict( object_id=None, object_type=None, filename=upload_token['filename'], original_filename='original-filename', asset_type=api.ASSET_TYPE_JPG ) response = api_calls.asset.post(**payload) response_body = utils.validate_response_status(response, api.STATUS_BAD_REQUEST) assert response_body == { 'message': { 'object_type': [ 'Field may not be null.' ] } } def test_delete_asset_upload_not_found(): """Test DELETE /upload fails if asset_upload not found.""" response = api_calls.asset.delete( object_id='some-non-existing-id', object_type='test', asset_type='artwork' ) response_body = utils.validate_response_status(response, api.STATUS_NOT_FOUND) assert response_body == {'message': 'Asset upload not found'} def test_delete_asset_bad_schema(): """Test DELETE /upload fails for validation.""" response = api_calls.asset.delete( object_id='1', object_type='test', asset_type='JPG' ) response_body = utils.validate_response_status(response, api.STATUS_BAD_REQUEST) assert response_body == { 'message': { 'asset_type': [ 'Must be one of: artwork, audio.' ] } } def test_post_status_upload_not_found(): """Test POST /status fails if asset_upload not found.""" response = api_calls.asset.post_status( filename='non-existing-filename', status='encoding_processing', timestamp='2020-01-20T10:00:00.000Z' ) response_body = utils.validate_response_status(response, api.STATUS_NOT_FOUND) assert response_body == {'message': 'Asset upload not found'} def test_post_final_upload_not_found(): """Test POST /final fails if asset_upload not found.""" response = api_calls.asset.post_final( filename='non-existing-filename', status='encoding_processing', timestamp='2020-01-20T10:00:00.000Z', final_assets=[] ) response_body = utils.validate_response_status(response, api.STATUS_NOT_FOUND) assert response_body == {'message': 'Asset upload not found'} def test_get_status_upload_not_found(): """Test GET /status/ fails if asset_upload not found.""" response = api_calls.asset.get_status('non-existing-filename') response_body = utils.validate_response_status(response, api.STATUS_NOT_FOUND) assert response_body == {'message': 'Asset upload not found'}