"""Unit tests for product_store_effective_price_code model.""" from pricing.models import product_store_effective_price_code import pytest from tests.utils import db_operations @pytest.fixture def db_fixture(): """Drop and re-create all the SQLite tables and seed them.""" db_operations.create_tables() db_operations.seed_data() def test_update_insert_row(): """Test that an effective price code can be set on product first time.""" product_id = 1 store_id = 696 data = { 'product_store_effective_price_code_id': 10, 'price_code': 'CD12', 'store_pricing_tier_name': 'CD Tier 12' } result = product_store_effective_price_code.\ update_product_store_effective_price_code(product_id, store_id, data) assert result created = result.message assert created['product_id'] == product_id assert created['store_id'] == store_id assert created['price_code'] == data['price_code'] assert created['store_pricing_tier_name'] == \ data['store_pricing_tier_name'] def test_update_update_row(): """Test that an orchard pricing tier can be set on a product again.""" product_id = 1 store_id = 696 data = { 'product_store_effective_price_code_id': 11, 'price_code': 'CD12', 'store_pricing_tier_name': 'CD Tier 12' } result = product_store_effective_price_code.\ update_product_store_effective_price_code(product_id, store_id, data) data = { 'price_code': 'CD13', 'store_pricing_tier_name': 'CD Tier 13' } result = product_store_effective_price_code.\ update_product_store_effective_price_code(product_id, store_id, data) assert result updated = result.message assert updated['product_id'] == product_id assert updated['store_id'] == store_id assert updated['price_code'] == data['price_code'] assert updated['store_pricing_tier_name'] == \ data['store_pricing_tier_name'] def test_update_empty_body(): """Test that a 400 response is returned if no data is provided.""" result = product_store_effective_price_code. \ update_product_store_effective_price_code( 1, 1, {}) assert result.status == 400 def test_get_by_product_id(db_fixture): """Test that the product store effective price codes can be retrieved.""" product_id = 100 result = product_store_effective_price_code.get_by_product_id(product_id) assert result message = result.message assert len(message) == 1 items = message['items'] assert len(items) == 1 assert items[0]['product_id'] == product_id assert items[0]['store_id'] == 696 assert items[0]['price_code'] == 'CD11' assert items[0]['store_pricing_tier_name'] == 'CD Tier 1'