<s> from decimal import Decimal as D <EOL> from oscar . core . loading import get_model <EOL> from django . test import TestCase <EOL> from oscar . test import factories <EOL> Partner = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> PartnerAddress = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> Country = get_model ( '<STR_LIT:address>' , '<STR_LIT>' ) <EOL> class TestStockRecord ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . product = factories . create_product ( ) <EOL> self . stockrecord = factories . create_stockrecord ( <EOL> self . product , price_excl_tax = D ( '<STR_LIT>' ) , num_in_stock = <NUM_LIT:10> ) <EOL> def test_get_price_excl_tax_returns_correct_value ( self ) : <EOL> self . assertEqual ( D ( '<STR_LIT>' ) , self . stockrecord . price_excl_tax ) <EOL> def test_net_stock_level_with_no_allocation ( self ) : <EOL> self . assertEqual ( <NUM_LIT:10> , self . stockrecord . net_stock_level ) <EOL> def test_net_stock_level_with_allocation ( self ) : <EOL> self . stockrecord . allocate ( <NUM_LIT:5> ) <EOL> self . assertEqual ( <NUM_LIT:10> - <NUM_LIT:5> , self . stockrecord . net_stock_level ) <EOL> def test_allocated_does_not_alter_num_in_stock ( self ) : <EOL> self . stockrecord . allocate ( <NUM_LIT:5> ) <EOL> self . assertEqual ( <NUM_LIT:10> , self . stockrecord . num_in_stock ) <EOL> self . assertEqual ( <NUM_LIT:5> , self . stockrecord . num_allocated ) <EOL> def test_allocation_handles_null_value ( self ) : <EOL> self . stockrecord . num_allocated = None <EOL> self . stockrecord . allocate ( <NUM_LIT:5> ) <EOL> def test_consuming_allocation ( self ) : <EOL> self . stockrecord . allocate ( <NUM_LIT:5> ) <EOL> self . stockrecord . consume_allocation ( <NUM_LIT:3> ) <EOL> self . assertEqual ( <NUM_LIT:2> , self . stockrecord . num_allocated ) <EOL> self . assertEqual ( <NUM_LIT:7> , self . stockrecord . num_in_stock ) <EOL> def test_cancelling_allocation ( self ) : <EOL> self . stockrecord . allocate ( <NUM_LIT:5> ) <EOL> self . stockrecord . cancel_allocation ( <NUM_LIT:4> ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . stockrecord . num_allocated ) <EOL> self . assertEqual ( <NUM_LIT:10> , self . stockrecord . num_in_stock ) <EOL> def test_cancelling_allocation_ignores_too_big_allocations ( self ) : <EOL> self . stockrecord . allocate ( <NUM_LIT:5> ) <EOL> self . stockrecord . cancel_allocation ( <NUM_LIT:6> ) <EOL> self . assertEqual ( <NUM_LIT:0> , self . stockrecord . num_allocated ) <EOL> self . assertEqual ( <NUM_LIT:10> , self . stockrecord . num_in_stock ) <EOL> class TestPartnerAddress ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . partner = Partner . _default_manager . create ( <EOL> name = "<STR_LIT>" ) <EOL> self . country = Country . _default_manager . create ( <EOL> iso_3166_1_a2 = '<STR_LIT>' , name = "<STR_LIT>" ) <EOL> self . address = PartnerAddress . _default_manager . create ( <EOL> title = "<STR_LIT>" , <EOL> first_name = "<STR_LIT>" , <EOL> last_name = "<STR_LIT>" , <EOL> country = self . country , <EOL> postcode = "<STR_LIT>" , <EOL> partner = self . partner ) <EOL> def test_can_get_primary_address ( self ) : <EOL> self . assertEqual ( self . partner . primary_address , self . address ) <EOL> def test_fails_on_two_addresses ( self ) : <EOL> self . address = PartnerAddress . _default_manager . create ( <EOL> title = "<STR_LIT>" , <EOL> first_name = "<STR_LIT>" , <EOL> last_name = "<STR_LIT>" , <EOL> postcode = "<STR_LIT>" , <EOL> country = self . country , <EOL> partner = self . partner ) <EOL> self . assertRaises ( <EOL> NotImplementedError , getattr , self . partner , '<STR_LIT>' ) </s>
