"""Tests for ows-product_digital Model.""" from collections import namedtuple from flexmock import flexmock from owsrequest import request as requests from sales_goals import api from sales_goals.models import ows_product_digital Response = namedtuple('Response', ['json', 'status_code']) def test_get_marketing_priorities_success( valid_get_header, context): """Test calls ows product_digital successfully.""" with context, api.app.test_request_context(headers=valid_get_header): (flexmock(requests) .should_receive('get') .with_args('ows-product-digital', '/product/1/mkt_priority') .and_return(Response(lambda: {'mkt_priority': []}, 200))) response = ows_product_digital.get_marketing_priorities(1) assert response.status == 200 assert response.message == [] def test_get_marketing_priorities_fail( valid_get_header, context): """Test calls ows product_digital failing.""" with context, api.app.test_request_context(headers=valid_get_header): (flexmock(requests) .should_receive('get') .with_args('ows-product-digital', '/product/1/mkt_priority') .and_return(Response(None, 500))) response = ows_product_digital.get_marketing_priorities(1) assert response.status == 500 def test_dataload_marketing_priorities_success( valid_get_header, context): """Test calls ows product_digital successfully.""" product_ids = [1, 2, 3] with context, api.app.test_request_context(headers=valid_get_header): (flexmock(requests) .should_receive('post') .with_args( 'ows-product-digital', '/product/mkt_priority/dataloader', json=product_ids) .and_return(Response(lambda: {'mkt_priority': []}, 200))) response = ows_product_digital.dataload_marketing_priorities(product_ids) assert response.status == 200 assert response.message == [] def test_set_marketing_priorities_success( valid_get_header, context): """Test calls ows product_digital successfully.""" with context, api.app.test_request_context(headers=valid_get_header): (flexmock(requests) .should_receive('post') .with_args( 'ows-product-digital', '/product/1/mkt_priority', json={'country_id': 2, 'priority': 'a'}) .and_return(Response(None, 200))) response = ows_product_digital.set_marketing_priority(1, 2, 'a') assert response.status == 200 def test_delete_marketing_priorities_success( valid_get_header, context): """Test calls ows product_digital successfully.""" with context, api.app.test_request_context(headers=valid_get_header): (flexmock(requests) .should_receive('delete') .with_args('ows-product-digital', '/product/1/mkt_priority/2') .and_return(Response(None, 200))) response = ows_product_digital.delete_marketing_priority(1, 2) assert response.status == 200 def test_delete_marketing_priorities_for_product_success( valid_get_header, context): """Test calls ows product_digital successfully.""" with context, api.app.test_request_context(headers=valid_get_header): (flexmock(requests) .should_receive('delete') .with_args('ows-product-digital', '/product/1/mkt_priority') .and_return(Response(None, 200))) response = ows_product_digital.delete_marketing_priority_for_product(1) assert response.status == 200 def test_get_project_for_product( valid_get_header, context): """Test calls ows product_digital successfully.""" with context, api.app.test_request_context(headers=valid_get_header): (flexmock(requests) .should_receive('get') .with_args('ows-product-digital', '/product/audio/1') .and_return(Response(lambda: {'project_id': 2}, 200))) response = ows_product_digital.get_project_for_product(1) assert response == 2