"""Unit tests for store_pricing_tier model.""" from pricing.models import store_pricing_tier 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_create(db_fixture): """Test that a store pricing tier can be created.""" store_pricing_scheme_id = 1 data = { 'name': 'Test Tier', 'store_pricing_tier_id': 100, 'orchard_pricing_tier_id': 1 } result = store_pricing_tier.create_store_pricing_tier( store_pricing_scheme_id, data) created = result.message assert created['store_pricing_tier_id'] == 100 assert created['name'] == 'Test Tier' assert created['store_pricing_scheme_id'] == 1 assert created['orchard_pricing_tier_id'] == 1 def test_create_empty_body(db_fixture): """Test that a store pricing tier requires fields to be created.""" store_pricing_scheme_id = 1 data = {} result = store_pricing_tier.create_store_pricing_tier( store_pricing_scheme_id, data) assert result.status == 400 def test_update(db_fixture): """Test that a store pricing tier can be updated.""" store_pricing_tier_id = 1 data = { 'orchard_pricing_tier_id': 1 } result = store_pricing_tier.update_store_pricing_tier_by_id( store_pricing_tier_id, data) updated = result.message assert updated['store_pricing_tier_id'] == 1 assert updated['orchard_pricing_tier_id'] == 1 def test_update_empty_body(db_fixture): """Test that a store pricing tier requires fields to be updated.""" store_pricing_tier_id = 1 data = {} result = store_pricing_tier.update_store_pricing_tier_by_id( store_pricing_tier_id, data) assert result.status == 400 def test_update_not_found(db_fixture): """Test that updates fails if store pricing tier does not exist.""" store_pricing_tier_id = 100 data = { 'orchard_pricing_tier_id': 1 } result = store_pricing_tier.update_store_pricing_tier_by_id( store_pricing_tier_id, data) assert result.status == 404 def test_delete(db_fixture): """Test that a store pricing tier can be deleted.""" store_pricing_tier_id = 1 result = store_pricing_tier.delete(store_pricing_tier_id) deleted = result.message assert deleted['store_pricing_tier_id'] == 1 def test_delete_not_found(db_fixture): """Test that delete fails if the store pricing tier does not exist.""" store_pricing_tier_id = 100 result = store_pricing_tier.delete(store_pricing_tier_id) assert result.status == 404