<s> from decimal import Decimal <EOL> from django . contrib . sites . models import Site <EOL> from django . core import urlresolvers <EOL> from django . core . urlresolvers import reverse as url <EOL> from django . test import TestCase <EOL> from django . test . client import Client <EOL> from l10n . models import * <EOL> from livesettings import config_get , config_get_group <EOL> from payment import utils <EOL> from product . models import * <EOL> from satchmo_store . contact . models import * <EOL> from satchmo_store . shop . models import * <EOL> from satchmo_utils . dynamic import lookup_template , lookup_url <EOL> from urls import make_urlpatterns <EOL> import keyedcache <EOL> alphabet = '<STR_LIT>' <EOL> def make_test_order ( country , state , site = None , orderitems = None ) : <EOL> if not orderitems : <EOL> orderitems = [ ( '<STR_LIT>' , <NUM_LIT:5> ) , ( '<STR_LIT>' , <NUM_LIT:1> ) ] <EOL> if not site : <EOL> site = Site . objects . get_current ( ) <EOL> c = Contact ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" , <EOL> role = ContactRole . objects . get ( pk = '<STR_LIT>' ) , email = "<STR_LIT>" ) <EOL> c . save ( ) <EOL> if not isinstance ( country , Country ) : <EOL> country = Country . objects . get ( iso2_code__iexact = country ) <EOL> ad = AddressBook ( contact = c , description = "<STR_LIT>" , <EOL> street1 = "<STR_LIT:test>" , state = state , city = "<STR_LIT>" , <EOL> country = country , is_default_shipping = True , <EOL> is_default_billing = True ) <EOL> ad . save ( ) <EOL> o = Order ( contact = c , shipping_cost = Decimal ( '<STR_LIT>' ) , site = site ) <EOL> o . save ( ) <EOL> for slug , qty in orderitems : <EOL> p = Product . objects . get ( slug = slug ) <EOL> price = p . unit_price <EOL> item = OrderItem ( order = o , product = p , quantity = qty , <EOL> unit_price = price , line_item_price = price * qty ) <EOL> item . save ( ) <EOL> return o <EOL> class TestModulesSettings ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . dummy = config_get_group ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> keyedcache . cache_delete ( ) <EOL> def testGetDummy ( self ) : <EOL> self . assert_ ( self . dummy != None ) <EOL> self . assertEqual ( self . dummy . LABEL , '<STR_LIT>' ) <EOL> def testLookupTemplateSet ( self ) : <EOL> t = lookup_template ( self . dummy , '<STR_LIT>' ) <EOL> self . assertEqual ( t , '<STR_LIT>' ) <EOL> def testLookupURL ( self ) : <EOL> try : <EOL> t = lookup_url ( self . dummy , '<STR_LIT>' ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except urlresolvers . NoReverseMatch : <EOL> pass <EOL> def testUrlPatterns ( self ) : <EOL> pats = make_urlpatterns ( ) <EOL> self . assertTrue ( len ( pats ) > <NUM_LIT:0> ) <EOL> class TestMinimumOrder ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> self . client = Client ( ) <EOL> def tearDown ( self ) : <EOL> keyedcache . cache_delete ( ) <EOL> def test_checkout_minimums ( self ) : <EOL> """<STR_LIT>""" <EOL> min_order = config_get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> min_order . update ( "<STR_LIT>" ) <EOL> producturl = urlresolvers . reverse ( "<STR_LIT>" , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> response = self . client . get ( producturl ) <EOL> self . assertContains ( response , "<STR_LIT>" , count = <NUM_LIT:2> , status_code = <NUM_LIT:200> ) <EOL> cartadd = urlresolvers . reverse ( '<STR_LIT>' ) <EOL> response = self . client . post ( cartadd , { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:1>" : "<STR_LIT:L>" , <EOL> "<STR_LIT:2>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT:2>' } ) <EOL> carturl = urlresolvers . reverse ( '<STR_LIT>' ) <EOL> self . assertRedirects ( response , carturl , <EOL> status_code = <NUM_LIT> , target_status_code = <NUM_LIT:200> ) <EOL> response = self . client . get ( carturl ) <EOL> self . assertContains ( response , "<STR_LIT>" , count = <NUM_LIT:1> , status_code = <NUM_LIT:200> ) <EOL> response = self . client . get ( url ( '<STR_LIT>' ) ) <EOL> self . assertContains ( response , "<STR_LIT>" , count = <NUM_LIT:1> , status_code = <NUM_LIT:200> ) <EOL> min_order . update ( "<STR_LIT>" ) <EOL> response = self . client . get ( url ( '<STR_LIT>' ) ) <EOL> self . assertContains ( response , "<STR_LIT>" , count = <NUM_LIT:1> , status_code = <NUM_LIT:200> ) <EOL> response = self . client . post ( cartadd , { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:1>" : "<STR_LIT:L>" , <EOL> "<STR_LIT:2>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT>' } ) <EOL> self . assertRedirects ( response , carturl , <EOL> status_code = <NUM_LIT> , target_status_code = <NUM_LIT:200> ) <EOL> response = self . client . get ( url ( '<STR_LIT>' ) ) <EOL> self . assertContains ( response , "<STR_LIT>" , count = <NUM_LIT:1> , status_code = <NUM_LIT:200> ) <EOL> class TestPaymentHandling ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> self . client = Client ( ) <EOL> self . US = Country . objects . get ( iso2_code__iexact = "<STR_LIT>" ) <EOL> def tearDown ( self ) : <EOL> keyedcache . cache_delete ( ) <EOL> def test_authorize ( self ) : <EOL> """<STR_LIT>""" <EOL> order = make_test_order ( self . US , '<STR_LIT>' ) <EOL> self . assertEqual ( order . balance , order . total ) <EOL> self . assertEqual ( order . total , Decimal ( '<STR_LIT>' ) ) <EOL> processor = utils . get_processor_by_key ( '<STR_LIT>' ) <EOL> processor . create_pending_payment ( order = order , amount = order . total ) <EOL> self . assertEqual ( order . pendingpayments . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( order . payments . count ( ) , <NUM_LIT:1> ) <EOL> pending = order . pendingpayments . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( pending . amount , order . total ) <EOL> payment = order . payments . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( payment . amount , Decimal ( '<STR_LIT:0>' ) ) <EOL> self . assertEqual ( pending . capture , payment ) <EOL> self . assertEqual ( order . balance_paid , Decimal ( '<STR_LIT:0>' ) ) <EOL> self . assertEqual ( order . authorized_remaining , Decimal ( '<STR_LIT:0>' ) ) <EOL> processor . prepare_data ( order ) <EOL> result = processor . authorize_payment ( ) <EOL> self . assertEqual ( result . success , True ) <EOL> auth = result . payment <EOL> self . assertEqual ( type ( auth ) , OrderAuthorization ) <EOL> self . assertEqual ( order . authorized_remaining , Decimal ( '<STR_LIT>' ) ) <EOL> result = processor . capture_authorized_payment ( auth ) <EOL> self . assertEqual ( result . success , True ) <EOL> payment = result . payment <EOL> self . assertEqual ( auth . capture , payment ) <EOL> self . assertEqual ( order . orderstatus_set . latest ( ) . status , '<STR_LIT>' ) <EOL> self . assertEqual ( order . balance , Decimal ( '<STR_LIT:0>' ) ) <EOL> def test_authorize_listener ( self ) : <EOL> """<STR_LIT>""" <EOL> order = make_test_order ( self . US , '<STR_LIT>' ) <EOL> self . assertEqual ( order . balance , order . total ) <EOL> self . assertEqual ( order . total , Decimal ( '<STR_LIT>' ) ) <EOL> processor = utils . get_processor_by_key ( '<STR_LIT>' ) <EOL> processor . create_pending_payment ( order = order , amount = order . total ) <EOL> processor . prepare_data ( order ) <EOL> result = processor . authorize_payment ( ) <EOL> self . assertEqual ( result . success , True ) <EOL> self . assertEqual ( order . authorized_remaining , Decimal ( '<STR_LIT>' ) ) <EOL> order . add_status ( '<STR_LIT>' ) <EOL> self . assertEqual ( order . authorized_remaining , Decimal ( '<STR_LIT:0>' ) ) <EOL> self . assertEqual ( order . balance , Decimal ( '<STR_LIT:0>' ) ) <EOL> def test_authorize_multiple ( self ) : <EOL> """<STR_LIT>""" <EOL> order = make_test_order ( self . US , '<STR_LIT>' ) <EOL> self . assertEqual ( order . balance , order . total ) <EOL> self . assertEqual ( order . total , Decimal ( '<STR_LIT>' ) ) <EOL> processor = utils . get_processor_by_key ( '<STR_LIT>' ) <EOL> processor . create_pending_payment ( order = order , amount = Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( order . pendingpayments . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( order . payments . count ( ) , <NUM_LIT:1> ) <EOL> pending = order . pendingpayments . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( pending . amount , Decimal ( '<STR_LIT>' ) ) <EOL> processor . prepare_data ( order ) <EOL> result = processor . authorize_payment ( ) <EOL> self . assertEqual ( result . success , True ) <EOL> processor . create_pending_payment ( order = order , amount = Decimal ( '<STR_LIT>' ) ) <EOL> result = processor . authorize_payment ( ) <EOL> results = processor . capture_authorized_payments ( ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:2> ) <EOL> r1 = results [ <NUM_LIT:0> ] <EOL> r2 = results [ <NUM_LIT:1> ] <EOL> self . assertEqual ( r1 . success , True ) <EOL> self . assertEqual ( r2 . success , True ) <EOL> self . assertEqual ( order . orderstatus_set . latest ( ) . status , '<STR_LIT>' ) <EOL> self . assertEqual ( order . balance , Decimal ( '<STR_LIT:0>' ) ) <EOL> def test_capture ( self ) : <EOL> """<STR_LIT>""" <EOL> order = make_test_order ( self . US , '<STR_LIT>' ) <EOL> self . assertEqual ( order . balance , order . total ) <EOL> self . assertEqual ( order . total , Decimal ( '<STR_LIT>' ) ) <EOL> processor = utils . get_processor_by_key ( '<STR_LIT>' ) <EOL> processor . create_pending_payment ( order = order , amount = order . total ) <EOL> processor . prepare_data ( order ) <EOL> result = processor . capture_payment ( ) <EOL> self . assertEqual ( result . success , True ) <EOL> pmt1 = result . payment <EOL> self . assertEqual ( type ( pmt1 ) , OrderPayment ) <EOL> self . assertEqual ( order . authorized_remaining , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( result . success , True ) <EOL> payment = result . payment <EOL> self . assertEqual ( pmt1 , payment ) <EOL> self . assertEqual ( order . orderstatus_set . latest ( ) . status , '<STR_LIT>' ) <EOL> self . assertEqual ( order . balance , Decimal ( '<STR_LIT:0>' ) ) <EOL> def test_multiple_pending ( self ) : <EOL> """<STR_LIT>""" <EOL> order = make_test_order ( self . US , '<STR_LIT>' ) <EOL> self . assertEqual ( order . balance , order . total ) <EOL> self . assertEqual ( order . total , Decimal ( '<STR_LIT>' ) ) <EOL> processor = utils . get_processor_by_key ( '<STR_LIT>' ) <EOL> pend1 = processor . create_pending_payment ( order = order , amount = order . total ) <EOL> pend2 = processor . create_pending_payment ( order = order , amount = order . total ) <EOL> self . assertEqual ( order . pendingpayments . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( order . payments . count ( ) , <NUM_LIT:1> ) </s>
