"""Tests for OWS Transcoding API Client.""" from unittest.mock import MagicMock from unittest.mock import patch import pytest from requests import HTTPError from transcoding.connectors import ows_transcoding @patch('transcoding.connectors.ows_transcoding.client') def test_post_job_status_success(mock_client): """Test post_job_status with a successful response.""" mock_response = MagicMock() mock_response.status_code = 200 mock_client.post.return_value = mock_response ows_transcoding.post_job_status( 123, 'completed', 'Job finished successfully', {'key': 'value'}) mock_client.post.assert_called_once() call_kwargs = mock_client.post.call_args assert call_kwargs.kwargs['path'].endswith('transcoding-job/123/status') assert call_kwargs.kwargs['json']['status'] == 'completed' assert call_kwargs.kwargs['json']['status_description'] == 'Job finished successfully' assert call_kwargs.kwargs['json']['metadata'] == {'key': 'value'} @patch('transcoding.connectors.ows_transcoding.client') def test_post_job_status_without_metadata(mock_client): """Test post_job_status without optional metadata parameter.""" mock_response = MagicMock() mock_response.status_code = 200 mock_client.post.return_value = mock_response ows_transcoding.post_job_status(123, 'pending', 'Job queued') mock_client.post.assert_called_once() call_kwargs = mock_client.post.call_args assert 'metadata' not in call_kwargs.kwargs['json'] @patch('transcoding.connectors.ows_transcoding.client') def test_post_job_status_non_200_raised_exception(mock_client): """Test post_job_status raises Exception on non-200 status.""" mock_response = MagicMock() mock_response.status_code = 500 mock_response.text = 'Internal Server Error' mock_response.raise_for_status.side_effect = HTTPError('Post job status failed') mock_client.post.return_value = mock_response with pytest.raises(Exception, match='Post job status failed'): ows_transcoding.post_job_status(123, 'error', 'Failed', {'key': 'value'}) mock_client.post.assert_called_once() @patch('transcoding.connectors.ows_transcoding.client') def test_post_job_status_client_exception(mock_client): """Test post_job_status raises when client.post throws an exception.""" mock_client.post.side_effect = ConnectionError('Connection refused') with pytest.raises(ConnectionError, match='Connection refused'): ows_transcoding.post_job_status(123, 'error', 'desc', {'key': 'value'}) mock_client.post.assert_called_once()