"""Tests for ows-product-physical Model.""" from owsrequest import request from owsrequest import test_utils from pricing.constants import service_name from pricing.models import ows_product_physical import pytest @pytest.fixture def fixture_product_physical_change_history(): """Fixture for product physical change history.""" return { 'store_id': 696, 'new_price': 'new', 'field_name': 'wholesale_price' } def test_add_change_history_success(monkeypatch): """Test adding a product physical change history with success.""" product_id = 123 store_id = 696 new_price = 'new' expected_status = 200 path = '/product/{product_id}/change_history'.format(product_id=product_id) # The call spec list used by mock_ows_requests to mock these requests call_specs = [{ 'service': service_name.OWS_PRODUCT_PHYSICAL, 'path': path, 'status': expected_status, 'json': {'key': 'value'} }] monkeypatch.setattr( request, 'post', test_utils.mock_ows_requests(call_specs)) response = ows_product_physical.add_change_history( product_id, store_id, new_price) assert response.status == expected_status def test_add_change_history_failure(monkeypatch): """Test adding a product physical change history with failure.""" product_id = 123 store_id = 696 new_price = 'new' expected_status = 500 path = '/product/{product_id}/change_history'.format(product_id=product_id) # The call spec list used by mock_ows_requests to mock these requests call_specs = [{ 'service': service_name.OWS_PRODUCT_PHYSICAL, 'path': path, 'status': expected_status, 'json': {'key': 'value'} }] monkeypatch.setattr( request, 'post', test_utils.mock_ows_requests(call_specs)) response = ows_product_physical.add_change_history( product_id, store_id, new_price) assert response.status == expected_status