<s> from django . conf import settings <EOL> from django . test import TestCase <EOL> from django . utils . unittest import skipIf <EOL> from billing import get_gateway , CreditCard <EOL> from billing . signals import * <EOL> from billing . models import EwayResponse <EOL> from billing . gateway import CardNotSupported <EOL> from billing . utils . credit_card import Visa <EOL> fake_options = { <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:state>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:url>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:100> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> } <EOL> @ skipIf ( not settings . MERCHANT_SETTINGS . get ( "<STR_LIT>" , None ) , "<STR_LIT>" ) <EOL> class EWayGatewayTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . merchant = get_gateway ( "<STR_LIT>" ) <EOL> self . merchant . test_mode = True <EOL> self . credit_card = CreditCard ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" , <EOL> month = <NUM_LIT:10> , year = <NUM_LIT> , <EOL> number = "<STR_LIT>" , <EOL> verification_value = "<STR_LIT:100>" ) <EOL> def testCardSupported ( self ) : <EOL> self . credit_card . number = "<STR_LIT>" <EOL> self . assertRaises ( CardNotSupported , <EOL> lambda : self . merchant . purchase ( <NUM_LIT:1000> , self . credit_card ) ) <EOL> def testCardValidated ( self ) : <EOL> self . merchant . test_mode = False <EOL> self . credit_card . number = "<STR_LIT>" <EOL> self . assertFalse ( self . merchant . validate_card ( self . credit_card ) ) <EOL> def testCardType ( self ) : <EOL> self . merchant . validate_card ( self . credit_card ) <EOL> self . assertEquals ( self . credit_card . card_type , Visa ) <EOL> def testPurchase ( self ) : <EOL> resp = self . merchant . purchase ( <NUM_LIT:100> , self . credit_card , <EOL> options = fake_options ) <EOL> self . assertEquals ( resp [ "<STR_LIT:status>" ] , "<STR_LIT>" ) <EOL> self . assertNotEquals ( resp [ "<STR_LIT>" ] . ewayTrxnStatus , True ) <EOL> self . assertEquals ( resp [ "<STR_LIT>" ] . ewayTrxnError , <EOL> "<STR_LIT>" ) <EOL> self . assertNotEquals ( resp [ "<STR_LIT>" ] . ewayTrxnNumber , "<STR_LIT:0>" ) <EOL> self . assertTrue ( resp [ "<STR_LIT>" ] . ewayReturnAmount , "<STR_LIT:100>" ) <EOL> def testFailure ( self ) : <EOL> resp = self . merchant . purchase ( <NUM_LIT> , self . credit_card , <EOL> options = fake_options ) <EOL> self . assertEquals ( resp [ "<STR_LIT:status>" ] , "<STR_LIT>" ) <EOL> self . assertEquals ( resp [ "<STR_LIT>" ] . ewayTrxnError , <EOL> "<STR_LIT>" ) <EOL> self . assertNotEquals ( resp [ "<STR_LIT>" ] . ewayTrxnNumber , "<STR_LIT:0>" ) <EOL> self . assertTrue ( resp [ "<STR_LIT>" ] . ewayReturnAmount , "<STR_LIT:100>" ) <EOL> def testDirectPayment ( self ) : <EOL> credit_card_details = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> resp = self . merchant . direct_payment ( credit_card_details , <EOL> options = fake_options ) <EOL> self . assertEquals ( resp [ "<STR_LIT:status>" ] , "<STR_LIT>" ) <EOL> eway_response = resp [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> self . assertEquals ( eway_response [ '<STR_LIT>' ] , '<STR_LIT:True>' ) <EOL> self . assertEquals ( eway_response [ "<STR_LIT>" ] , "<STR_LIT:100>" ) <EOL> def testPaymentSuccessfulSignal ( self ) : <EOL> received_signals = [ ] <EOL> def receive ( sender , ** kwargs ) : <EOL> received_signals . append ( kwargs . get ( "<STR_LIT>" ) ) <EOL> transaction_was_unsuccessful . connect ( receive ) <EOL> resp = self . merchant . purchase ( <NUM_LIT:1> , self . credit_card , <EOL> options = fake_options ) <EOL> self . assertEquals ( received_signals , [ transaction_was_unsuccessful ] ) <EOL> def testPaymentUnSuccessfulSignal ( self ) : <EOL> received_signals = [ ] <EOL> def receive ( sender , ** kwargs ) : <EOL> received_signals . append ( kwargs . get ( "<STR_LIT>" ) ) <EOL> transaction_was_unsuccessful . connect ( receive ) <EOL> resp = self . merchant . purchase ( <NUM_LIT:6> , self . credit_card , <EOL> options = fake_options ) <EOL> self . assertEquals ( received_signals , [ transaction_was_unsuccessful ] ) <EOL> def testCreditCardExpired ( self ) : <EOL> resp = self . merchant . purchase ( <NUM_LIT:8> , self . credit_card , <EOL> options = fake_options ) <EOL> self . assertNotEquals ( resp [ "<STR_LIT:status>" ] , "<STR_LIT>" ) </s>
