"""Test for ows-product-workflow model.""" from unittest.mock import MagicMock from flexmock import flexmock from owsrequest import request from product_digital.constants import services from product_digital.models import ows_product_review def test_get_rejection_correct_call( get_rejections_message, product_id): """Test correct call made to ows-product-review.""" workflow_payload = get_rejections_message mock_response = MagicMock(status_code=200) mock_response.json = MagicMock(return_value=workflow_payload) (flexmock(request).should_receive( 'get').with_args( services.OWS_PRODUCT_REVIEW, '/reject/{}'.format(product_id), ).and_return(mock_response)) ows_product_review.get_rejection( product_id) def test_get_rejection_expected_return( get_rejections_message, product_id): """Test correct call made to ows-product-review and check its status.""" workflow_payload = get_rejections_message mock_response = MagicMock(status_code=200) mock_response.json = MagicMock(return_value=workflow_payload) (flexmock(request).should_receive( 'get').with_args( services.OWS_PRODUCT_REVIEW, '/reject/{}'.format(product_id), ).and_return(mock_response)) result = ows_product_review.get_rejection( product_id) assert result.status == 200 assert result.message == workflow_payload def test_get_rejection_error_return(product_id): """Test incorrect call made to ows-product-review.""" mock_response = MagicMock(status_code=403) (flexmock(request).should_receive( 'get').with_args( services.OWS_PRODUCT_REVIEW, '/reject/{}'.format(product_id), ).and_return(mock_response)) result = ows_product_review.get_rejection( product_id) assert result.status == 403 def test_get_status_correct_call( get_status_message, product_id): """Test correct call made to ows-product-review.""" workflow_payload = get_status_message mock_response = MagicMock(status_code=200) mock_response.json = MagicMock(return_value=workflow_payload) (flexmock(request).should_receive( 'get').with_args( services.OWS_PRODUCT_REVIEW, '/status/{}'.format(product_id), ).and_return(mock_response)) ows_product_review.get_status( product_id) def test_get_status_expected_return( get_status_message, product_id): """Test correct call made to ows-product-review and check its status.""" workflow_payload = get_status_message mock_response = MagicMock(status_code=200) mock_response.json = MagicMock(return_value=workflow_payload) (flexmock(request).should_receive( 'get').with_args( services.OWS_PRODUCT_REVIEW, '/status/{}'.format(product_id), ).and_return(mock_response)) result = ows_product_review.get_status( product_id) assert result.status == 200 assert result.message == workflow_payload def test_get_status_error_return(product_id): """Test incorrect call made to ows-product-review.""" mock_response = MagicMock(status_code=403) (flexmock(request).should_receive( 'get').with_args( services.OWS_PRODUCT_REVIEW, '/status/{}'.format(product_id), ).and_return(mock_response)) result = ows_product_review.get_status( product_id) assert result.status == 403