"""Unit tests for default_account_pricing_tier model.""" from pricing.models import default_account_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_get_by_account_and_pricing_family_id(db_fixture): """Test that the default account pricing tier can be returned.""" result = default_account_pricing_tier.\ get_by_account_and_pricing_family_id('vendor', 1, 1) assert result retrieved = result.message assert retrieved['default_pricing_tier_id'] == 1 assert retrieved['account_type'] == 'vendor' assert retrieved['account_id'] == 1 assert retrieved['pricing_family_id'] == 1 assert retrieved['orchard_pricing_tier_id'] == 1 def test_get_by_account_and_pricing_family_id_not_found(db_fixture): """Test that an empty 404 response is returned if no result is found.""" result = default_account_pricing_tier.\ get_by_account_and_pricing_family_id('vendor', 1, 100) assert result.status == 404 assert not result.message def test_insert_row(db_fixture): """Test that default pricing tier can be set on an account first time.""" data = { 'default_pricing_tier_id': 10, 'orchard_pricing_tier_id': 1 } result = default_account_pricing_tier.\ insert_account_with_default_pricing_tier( 'vendor', 5, 1, data) assert result created = result.message assert created['account_type'] == 'vendor' assert created['account_id'] == 5 assert created['pricing_family_id'] == 1 assert created['orchard_pricing_tier_id'] == 1 assert created['active'] == 1 def test_delete_row(db_fixture): """Test that a default pricing tier can be soft deleted on an account.""" data = { 'created_by': 'alw:123' } result = default_account_pricing_tier.\ soft_delete_default_account_pricing_tier( 'vendor', 1, 1, data) soft_deleted = result.message assert soft_deleted['account_type'] == 'vendor' assert soft_deleted['account_id'] == 1 assert soft_deleted['pricing_family_id'] == 1 assert soft_deleted['active'] == 0 def test_delete_row_not_found(db_fixture): """Test that an empty 404 response is returned if no result is found.""" data = { 'created_by': 'alw:123' } result = default_account_pricing_tier.\ soft_delete_default_account_pricing_tier('vendor', 1, 100, data) assert result.status == 404 assert not result