"""Test application.""" from unittest.mock import patch import app from src.exceptions import ApproveRequestBlockedException from src.exceptions import NotSubmittedException from src.exceptions import OwsRequestException @patch('app.file_parsing') @patch('app.ows') def test_main_success(_, mock_fp): """Test main.""" mock_fp.get_product_ids_from_csv.return_value = {1, 2, 3} actual = app.main() assert actual == {'approved_ids': [1, 2, 3], 'errors': []} @patch('app.file_parsing') @patch('app.ows') def test_main_error_handling(mock_ows, mock_fp): """Test main error handling.""" mock_fp.get_product_ids_from_csv.return_value = {1, 2, 3, 4} mock_ows.approve_by_id.side_effect = [ NotSubmittedException('foo'), ApproveRequestBlockedException('bar'), OwsRequestException('review queue', 'baz'), None ] actual = app.main() assert actual == { 'approved_ids': [4], 'errors': [ (1, 'Product not currently submitted.'), (2, 'Approval was blocked with response: bar'), (3, 'Failed to call review queue endpoint with error: baz'), ] }