"""Test for the ows_marketing module.""" import json from flexmock import flexmock from owsrequest import request import requests from salessheets.constants import field_const from salessheets.constants import ows_services from salessheets.models import ows_marketing TEST_RELEASE_ID = '12345' TEST_IMAGE_UPC = '123456789012' TEST_EMPTY_IMAGE_UPC = None TEST_EMPTY_RELEASE_ID = None TEST_PDF_DATA = { field_const.RELEASE_UPC: TEST_IMAGE_UPC } def test_get_marketing_highlights_exception_no_release_id(): """Test if get_marketing_highlights doesn't receive account_id.""" test_failure_content = { 'text': 'test_error' } test_content = flexmock( decode=lambda *args: test_failure_content ) failure_response = flexmock(requests.models.Response()) failure_response.status_code = 404 (flexmock(failure_response).should_receive('content') .and_return(test_content)) flexmock(json).should_receive('loads').and_return(test_content) flexmock(request).should_receive('process').and_return(failure_response) result = ows_marketing.get_marketing_highlights( ows_services.RELEASE, TEST_EMPTY_RELEASE_ID) assert not result assert result.errors == test_content def test_get_marketing_highlights_successful_result(): """Test if get_marketing_highlights returns successful result.""" success_test_content = { 'items': [{ 'scope': 'public', 'description': 'example_description', 'entity': 'example', 'entity_id': 1234567, 'client': 'example_client', 'mkt_program_id': 12345, 'attachment': 'example_attachment', 'highlight_id': 123456 }] } test_content = flexmock() (test_content.should_receive('decode').with_args('utf8') .and_return(success_test_content)) success_response = flexmock(requests.models.Response()) success_response.status_code = 200 success_response.should_receive('content').and_return(test_content) flexmock(json).should_receive('loads').and_return(success_test_content) flexmock(request).should_receive('process').and_return(success_response) result = ows_marketing.get_marketing_highlights( ows_services.RELEASE, TEST_RELEASE_ID) assert result assert result.message == success_test_content['items'] def test_filter_marketing_highlights( marketing_highlights_from_ows, filtered_marketing_highlights): """Test filter_marketing_highlights by mkt_program_id.""" result = ows_marketing.filter_marketing_highlights( marketing_highlights_from_ows, mkt_program_id=20) assert result == filtered_marketing_highlights