<s> from datetime import datetime <EOL> from decimal import Decimal <EOL> from django . test import TestCase <EOL> from models import Carrier , QuantityTier , Shipper <EOL> def make_tiers ( carrier , prices , expires = None ) : <EOL> for qty , handling , price in prices : <EOL> t = QuantityTier ( carrier = carrier , <EOL> handling = Decimal ( "<STR_LIT>" % handling ) , <EOL> price = Decimal ( "<STR_LIT>" % price ) , <EOL> quantity = Decimal ( qty ) , <EOL> expires = expires <EOL> ) <EOL> t . save ( ) <EOL> class TieredCarrierSimpleTest ( TestCase ) : <EOL> fixtures = [ ] <EOL> def testCreate ( self ) : <EOL> c = Carrier ( key = "<STR_LIT:test>" , active = True ) <EOL> c . save ( ) <EOL> t = QuantityTier ( carrier = c , <EOL> quantity = Decimal ( '<STR_LIT:1>' ) , <EOL> handling = Decimal ( "<STR_LIT>" ) , <EOL> price = Decimal ( "<STR_LIT>" ) , <EOL> ) <EOL> t . save ( ) <EOL> self . assertEqual ( c . price ( <NUM_LIT:1> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( c . price ( <NUM_LIT:4> ) , Decimal ( "<STR_LIT>" ) ) <EOL> class TieredCarrierPricingTest ( TestCase ) : <EOL> fixtures = [ ] <EOL> def setUp ( self ) : <EOL> self . carrier = Carrier ( name = "<STR_LIT>" , active = True ) <EOL> self . carrier . save ( ) <EOL> t = QuantityTier ( carrier = self . carrier , <EOL> quantity = Decimal ( '<STR_LIT:1>' ) , <EOL> handling = Decimal ( "<STR_LIT>" ) , <EOL> price = Decimal ( "<STR_LIT>" ) , <EOL> ) <EOL> t . save ( ) <EOL> def testBase ( self ) : <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:1> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:10> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:100> ) , Decimal ( "<STR_LIT>" ) ) <EOL> def test2Prices ( self ) : <EOL> t = QuantityTier ( carrier = self . carrier , <EOL> quantity = Decimal ( '<STR_LIT>' ) , <EOL> handling = Decimal ( "<STR_LIT>" ) , <EOL> price = Decimal ( "<STR_LIT>" ) , <EOL> ) <EOL> t . save ( ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:1> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:9> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:10> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:100> ) , Decimal ( "<STR_LIT>" ) ) <EOL> class TieredCarrierExpiringTest ( TestCase ) : <EOL> fixtures = [ ] <EOL> def setUp ( self ) : <EOL> self . carrier = Carrier ( name = "<STR_LIT>" , active = True ) <EOL> self . carrier . save ( ) <EOL> base_prices = ( <EOL> ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:1> ) , <EOL> ( <NUM_LIT:30> , <NUM_LIT:30> , <NUM_LIT:2> ) , <EOL> ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> ) <EOL> ) <EOL> make_tiers ( self . carrier , base_prices ) <EOL> def testExpired ( self ) : <EOL> dt = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> sale_prices = ( <EOL> ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:1> ) , <EOL> ( <NUM_LIT:30> , <NUM_LIT:3> , <NUM_LIT:1> ) , <EOL> ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) <EOL> ) <EOL> make_tiers ( self . carrier , sale_prices , expires = dt ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:1> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:20> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:30> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:100> ) , Decimal ( "<STR_LIT>" ) ) <EOL> def testNotExpired ( self ) : <EOL> now = datetime . now ( ) <EOL> nextyear = datetime ( now . year + <NUM_LIT:1> , now . month , now . day ) <EOL> sale_prices = ( <EOL> ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:1> ) , <EOL> ( <NUM_LIT:30> , <NUM_LIT:3> , <NUM_LIT:1> ) , <EOL> ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) <EOL> ) <EOL> make_tiers ( self . carrier , sale_prices , expires = nextyear ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:1> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:10> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:20> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:30> ) , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . carrier . price ( <NUM_LIT:100> ) , Decimal ( "<STR_LIT>" ) ) </s>
