<s> from __future__ import unicode_literals <EOL> from unittest import TestCase <EOL> from mock import patch , MagicMock , Mock <EOL> from . import AuthorizeNetProvider <EOL> from . . import RedirectNeeded <EOL> LOGIN_ID = '<STR_LIT>' <EOL> TRANSACTION_KEY = '<STR_LIT>' <EOL> PROCESS_DATA = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:5>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> STATUS_CONFIRMED = '<STR_LIT:1>' <EOL> class Payment ( Mock ) : <EOL> id = <NUM_LIT:1> <EOL> variant = '<STR_LIT>' <EOL> currency = '<STR_LIT>' <EOL> total = <NUM_LIT:100> <EOL> status = '<STR_LIT>' <EOL> transaction_id = None <EOL> captured_amount = <NUM_LIT:0> <EOL> def get_process_url ( self ) : <EOL> return '<STR_LIT>' <EOL> def get_failure_url ( self ) : <EOL> return '<STR_LIT>' <EOL> def get_success_url ( self ) : <EOL> return '<STR_LIT>' <EOL> def change_status ( self , status ) : <EOL> self . status = status <EOL> class TestAuthorizeNetProvider ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . payment = Payment ( ) <EOL> def test_provider_redirects_to_success_on_payment_success ( self ) : <EOL> provider = AuthorizeNetProvider ( <EOL> login_id = LOGIN_ID , transaction_key = TRANSACTION_KEY ) <EOL> response_data = [ <EOL> STATUS_CONFIRMED , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> with patch ( '<STR_LIT>' ) as mocked_post : <EOL> post = MagicMock ( ) <EOL> post . text = '<STR_LIT:|>' . join ( response_data ) <EOL> mocked_post . return_value = post <EOL> with self . assertRaises ( RedirectNeeded ) as exc : <EOL> provider . get_form ( self . payment , data = PROCESS_DATA ) <EOL> self . assertEqual ( exc . args [ <NUM_LIT:0> ] , self . payment . get_success_url ( ) ) <EOL> self . assertEqual ( self . payment . status , '<STR_LIT>' ) <EOL> self . assertEqual ( self . payment . captured_amount , self . payment . total ) <EOL> def test_provider_shows_validation_error_message ( self ) : <EOL> provider = AuthorizeNetProvider ( <EOL> login_id = LOGIN_ID , transaction_key = TRANSACTION_KEY ) <EOL> error_msg = '<STR_LIT>' <EOL> response_data = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> error_msg , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> with patch ( '<STR_LIT>' ) as mocked_post : <EOL> post = MagicMock ( ) <EOL> post . ok = False <EOL> post . text = '<STR_LIT:|>' . join ( response_data ) <EOL> mocked_post . return_value = post <EOL> form = provider . get_form ( self . payment , data = PROCESS_DATA ) <EOL> self . assertEqual ( form . errors [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , error_msg ) <EOL> self . assertEqual ( self . payment . status , '<STR_LIT:error>' ) <EOL> self . assertEqual ( self . payment . captured_amount , <NUM_LIT:0> ) </s>
