<s> from decimal import Decimal as D <EOL> from django . test import TestCase <EOL> from oscar . apps . offer import models , utils <EOL> from oscar . apps . shipping . repository import Repository <EOL> from oscar . apps . shipping . models import WeightBased <EOL> from oscar . test . basket import add_product <EOL> from oscar . test import factories <EOL> def create_offer ( ) : <EOL> range = models . Range . objects . create ( <EOL> name = "<STR_LIT>" , includes_all_products = True ) <EOL> condition = models . CountCondition . objects . create ( <EOL> range = range , <EOL> type = models . Condition . COUNT , <EOL> value = <NUM_LIT:1> ) <EOL> benefit = models . ShippingFixedPriceBenefit . objects . create ( <EOL> type = models . Benefit . SHIPPING_FIXED_PRICE , <EOL> value = D ( '<STR_LIT>' ) ) <EOL> return models . ConditionalOffer . objects . create ( <EOL> condition = condition , <EOL> benefit = benefit , <EOL> offer_type = models . ConditionalOffer . SITE ) <EOL> class TestWeightBasedShippingBenefit ( TestCase ) : <EOL> def setUp ( self ) : <EOL> product = factories . create_product ( attributes = { '<STR_LIT>' : <NUM_LIT:5> } , num_in_stock = <NUM_LIT:10> ) <EOL> factories . create_shipping_weight_band ( <NUM_LIT:10> , <NUM_LIT:10> ) <EOL> self . basket = factories . create_basket ( empty = True ) <EOL> self . basket . add_product ( product ) <EOL> self . offer = create_offer ( ) <EOL> def test_has_discount_recorded_correctly_when_order_is_placed ( self ) : <EOL> add_product ( self . basket , D ( '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> utils . Applicator ( ) . apply ( self . basket ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . basket . offer_applications ) ) <EOL> shipping_method = WeightBased . objects . first ( ) <EOL> shipping_method = Repository ( ) . apply_shipping_offer ( <EOL> self . basket , shipping_method , self . offer ) <EOL> order = factories . create_order ( basket = self . basket , <EOL> shipping_method = shipping_method ) <EOL> discounts = order . discounts . all ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( discounts ) ) <EOL> discount = discounts [ <NUM_LIT:0> ] <EOL> self . assertTrue ( discount . is_shipping_discount ) <EOL> self . assertEqual ( D ( '<STR_LIT>' ) , discount . amount ) </s>
