<s> from decimal import Decimal as D <EOL> from django . test import TestCase <EOL> from oscar . apps . offer import models , utils , custom <EOL> from oscar . test import factories <EOL> from oscar . test . basket import add_product <EOL> class CustomAction ( models . Benefit ) : <EOL> class Meta : <EOL> proxy = True <EOL> app_label = '<STR_LIT>' <EOL> def apply ( self , basket , condition , offer ) : <EOL> condition . consume_items ( offer , basket , ( ) ) <EOL> return models . PostOrderAction ( <EOL> "<STR_LIT>" ) <EOL> def apply_deferred ( self , basket , order , application ) : <EOL> return "<STR_LIT>" <EOL> @ property <EOL> def description ( self ) : <EOL> return "<STR_LIT>" <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 = custom . create_benefit ( CustomAction ) <EOL> return models . ConditionalOffer . objects . create ( <EOL> condition = condition , <EOL> benefit = benefit , <EOL> offer_type = models . ConditionalOffer . SITE ) <EOL> class TestAnOfferWithAPostOrderAction ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . basket = factories . create_basket ( empty = True ) <EOL> add_product ( self . basket , D ( '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> create_offer ( ) <EOL> utils . Applicator ( ) . apply ( self . basket ) <EOL> def test_applies_correctly_to_basket_which_meets_condition ( self ) : <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . basket . offer_applications ) ) <EOL> self . assertEqual ( <EOL> <NUM_LIT:1> , len ( self . basket . offer_applications . post_order_actions ) ) <EOL> action = self . basket . offer_applications . post_order_actions [ <NUM_LIT:0> ] <EOL> self . assertEqual ( '<STR_LIT>' , action [ '<STR_LIT:description>' ] ) <EOL> def test_has_discount_recorded_correctly_when_order_is_placed ( self ) : <EOL> order = factories . create_order ( basket = self . basket ) <EOL> discounts = order . discounts . all ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( discounts ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( order . post_order_actions ) ) <EOL> discount = discounts [ <NUM_LIT:0> ] <EOL> self . assertTrue ( discount . is_post_order_action ) <EOL> self . assertEqual ( D ( '<STR_LIT>' ) , discount . amount ) <EOL> self . assertEqual ( '<STR_LIT>' , discount . message ) </s>
