<s> import locale <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth . models import AnonymousUser <EOL> from django . contrib . sessions . backends . file import SessionStore <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . test import TestCase <EOL> from django . test . client import Client <EOL> from lfs . catalog . models import Product , DeliveryTime <EOL> from lfs . cart . models import Cart <EOL> from lfs . cart . models import CartItem <EOL> from lfs . cart . views import add_to_cart <EOL> from lfs . cart import utils as cart_utils <EOL> from lfs . core . models import Country <EOL> from lfs . addresses . models import Address <EOL> from lfs . customer . models import Customer <EOL> from lfs . order . models import Order <EOL> from lfs . order . models import OrderItem <EOL> from lfs . order . utils import add_order <EOL> from lfs . order . settings import SUBMITTED <EOL> from lfs . payment . models import PaymentMethod <EOL> from lfs . shipping . models import ShippingMethod <EOL> from lfs . tax . models import Tax <EOL> from lfs . tests . utils import DummySession <EOL> from lfs . tests . utils import RequestFactory <EOL> class OrderTestCase ( TestCase ) : <EOL> """<STR_LIT:U+0020>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> """<STR_LIT:U+0020>""" <EOL> session = SessionStore ( ) <EOL> session . save ( ) <EOL> rf = RequestFactory ( ) <EOL> self . request = rf . get ( '<STR_LIT:/>' ) <EOL> self . request . session = session <EOL> self . request . user = AnonymousUser ( ) <EOL> tax = Tax . objects . create ( rate = <NUM_LIT> ) <EOL> delivery_time = DeliveryTime . objects . create ( min = <NUM_LIT:3> , max = <NUM_LIT:10> ) <EOL> shipping_method = ShippingMethod . objects . create ( <EOL> name = "<STR_LIT>" , <EOL> active = True , <EOL> price = <NUM_LIT:1.0> , <EOL> tax = tax , <EOL> delivery_time = delivery_time <EOL> ) <EOL> payment_method = PaymentMethod . objects . create ( <EOL> name = "<STR_LIT>" , <EOL> active = True , <EOL> tax = tax , <EOL> ) <EOL> us = Country . objects . get ( code = "<STR_LIT>" ) <EOL> ie = Country . objects . get ( code = "<STR_LIT>" ) <EOL> address1 = Address . objects . create ( <EOL> firstname = "<STR_LIT>" , <EOL> lastname = "<STR_LIT>" , <EOL> company_name = "<STR_LIT>" , <EOL> line1 = "<STR_LIT>" , <EOL> city = "<STR_LIT>" , <EOL> zip_code = "<STR_LIT>" , <EOL> country = ie , <EOL> phone = "<STR_LIT>" , <EOL> email = "<STR_LIT>" , <EOL> ) <EOL> address2 = Address . objects . create ( <EOL> firstname = "<STR_LIT>" , <EOL> lastname = "<STR_LIT>" , <EOL> company_name = "<STR_LIT>" , <EOL> line1 = "<STR_LIT>" , <EOL> city = "<STR_LIT>" , <EOL> zip_code = "<STR_LIT>" , <EOL> country = us , <EOL> phone = "<STR_LIT>" , <EOL> email = "<STR_LIT>" , <EOL> ) <EOL> address3 = Address . objects . create ( <EOL> firstname = "<STR_LIT>" , <EOL> lastname = "<STR_LIT>" , <EOL> company_name = "<STR_LIT>" , <EOL> line1 = "<STR_LIT>" , <EOL> city = "<STR_LIT>" , <EOL> zip_code = "<STR_LIT>" , <EOL> country = ie , <EOL> phone = "<STR_LIT>" , <EOL> email = "<STR_LIT>" , <EOL> ) <EOL> address4 = Address . objects . create ( <EOL> firstname = "<STR_LIT>" , <EOL> lastname = "<STR_LIT>" , <EOL> company_name = "<STR_LIT>" , <EOL> line1 = "<STR_LIT>" , <EOL> city = "<STR_LIT>" , <EOL> zip_code = "<STR_LIT>" , <EOL> country = us , <EOL> phone = "<STR_LIT>" , <EOL> email = "<STR_LIT>" , <EOL> ) <EOL> self . customer = Customer . objects . create ( <EOL> session = session . session_key , <EOL> selected_shipping_method = shipping_method , <EOL> selected_payment_method = payment_method , <EOL> selected_shipping_address = address1 , <EOL> selected_invoice_address = address2 , <EOL> default_shipping_address = address1 , <EOL> default_invoice_address = address2 , <EOL> ) <EOL> self . p1 = Product . objects . create ( <EOL> name = "<STR_LIT>" , <EOL> slug = "<STR_LIT>" , <EOL> sku = "<STR_LIT>" , <EOL> price = <NUM_LIT> , <EOL> tax = tax , <EOL> active = True , <EOL> ) <EOL> self . p2 = Product . objects . create ( <EOL> name = "<STR_LIT>" , <EOL> slug = "<STR_LIT>" , <EOL> sku = "<STR_LIT>" , <EOL> price = <NUM_LIT> , <EOL> tax = tax , <EOL> active = True , <EOL> ) <EOL> cart = Cart . objects . create ( <EOL> session = session . session_key <EOL> ) <EOL> item = CartItem . objects . create ( <EOL> cart = cart , <EOL> product = self . p1 , <EOL> amount = <NUM_LIT:2> , <EOL> ) <EOL> item = CartItem . objects . create ( <EOL> cart = cart , <EOL> product = self . p2 , <EOL> amount = <NUM_LIT:3> , <EOL> ) <EOL> def test_add_order ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <NUM_LIT:4> , Address . objects . count ( ) ) <EOL> order = add_order ( self . request ) <EOL> self . assertEqual ( <NUM_LIT:6> , Address . objects . count ( ) ) <EOL> self . assertEqual ( order . state , SUBMITTED ) <EOL> self . assertEqual ( "<STR_LIT>" % order . price , "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" % order . tax , "<STR_LIT>" ) <EOL> self . assertEqual ( order . shipping_method . name , "<STR_LIT>" ) <EOL> self . assertEqual ( order . shipping_price , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( "<STR_LIT>" % order . shipping_tax , "<STR_LIT>" ) <EOL> self . assertEqual ( order . payment_method . name , "<STR_LIT>" ) <EOL> self . assertEqual ( order . payment_price , <NUM_LIT:0.0> ) <EOL> self . assertEqual ( order . payment_tax , <NUM_LIT:0.0> ) <EOL> self . assertEqual ( order . shipping_address . firstname , "<STR_LIT>" ) <EOL> self . assertEqual ( order . shipping_address . lastname , "<STR_LIT>" ) <EOL> self . assertEqual ( order . shipping_address . line1 , "<STR_LIT>" ) <EOL> self . assertEqual ( order . shipping_address . line2 , None ) <EOL> self . assertEqual ( order . shipping_address . city , "<STR_LIT>" ) <EOL> self . assertEqual ( order . shipping_address . zip_code , "<STR_LIT>" ) <EOL> self . assertEqual ( order . shipping_address . phone , "<STR_LIT>" ) <EOL> self . assertEqual ( order . shipping_address . company_name , "<STR_LIT>" ) <EOL> self . assertEqual ( order . invoice_address . firstname , "<STR_LIT>" ) <EOL> self . assertEqual ( order . invoice_address . lastname , "<STR_LIT>" ) <EOL> self . assertEqual ( order . invoice_address . line1 , "<STR_LIT>" ) <EOL> self . assertEqual ( order . invoice_address . line2 , None ) <EOL> self . assertEqual ( order . invoice_address . city , "<STR_LIT>" ) <EOL> self . assertEqual ( order . invoice_address . zip_code , "<STR_LIT>" ) <EOL> self . assertEqual ( order . invoice_address . phone , "<STR_LIT>" ) <EOL> self . assertEqual ( order . invoice_address . company_name , "<STR_LIT>" ) <EOL> self . assertEqual ( len ( order . items . all ( ) ) , <NUM_LIT:2> ) <EOL> item = order . items . all ( ) . order_by ( '<STR_LIT:id>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( item . product_amount , <NUM_LIT:2> ) <EOL> self . assertEqual ( item . product_sku , "<STR_LIT>" ) <EOL> self . assertEqual ( item . product_name , "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" % item . product_price_gross , "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" % item . product_price_net , "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" % item . product_tax , "<STR_LIT>" ) <EOL> item = order . items . all ( ) . order_by ( '<STR_LIT:id>' ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( item . product_amount , <NUM_LIT:3> ) <EOL> self . assertEqual ( item . product_sku , "<STR_LIT>" ) <EOL> self . assertEqual ( item . product_name , "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" % item . product_price_gross , "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" % item . product_price_net , "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" % item . product_tax , "<STR_LIT>" ) <EOL> cart = cart_utils . get_cart ( self . request ) <EOL> self . assertEqual ( cart , None ) <EOL> self . assertTrue ( order . delivery_time is not None ) <EOL> def test_pay_link ( self ) : <EOL> """<STR_LIT>""" <EOL> locale . setlocale ( locale . LC_ALL , '<STR_LIT>' ) <EOL> from lfs . payment . utils import process_payment <EOL> result = process_payment ( self . request ) <EOL> order = Order . objects . filter ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( order . get_pay_link ( self . request ) , "<STR_LIT>" ) <EOL> def test_paypal_link ( self ) : <EOL> """<STR_LIT>""" <EOL> payment_method , created = PaymentMethod . objects . get_or_create ( <EOL> id = <NUM_LIT:3> , <EOL> name = "<STR_LIT>" , <EOL> active = True , <EOL> ) <EOL> self . customer . selected_payment_method = payment_method <EOL> self . customer . save ( ) <EOL> from lfs . payment . utils import process_payment <EOL> result = process_payment ( self . request ) <EOL> order = Order . objects . filter ( ) [ <NUM_LIT:0> ] <EOL> self . failIf ( order . get_pay_link ( self . request ) . find ( "<STR_LIT>" ) == - <NUM_LIT:1> ) <EOL> def test_delete_product ( self ) : <EOL> """<STR_LIT>""" <EOL> address = Address . objects . create ( ) <EOL> order = Order . objects . create ( invoice_address = address , shipping_address = address ) <EOL> order_item_1 = OrderItem . objects . create ( order = order , product = self . p1 ) <EOL> self . p1 . delete ( ) <EOL> OrderItem . objects . get ( pk = order_item_1 . id ) </s>
