<s> from httmock import HTTMock , with_httmock <EOL> from xml . dom . minidom import parseString <EOL> from django . test import TestCase <EOL> from authorizenet . models import CustomerProfile <EOL> from . utils import create_user , xml_to_dict <EOL> from . mocks import cim_url_match , customer_profile_success , delete_success <EOL> from . test_data import create_empty_profile_success , delete_profile_success <EOL> class RequestError ( Exception ) : <EOL> pass <EOL> def error_on_request ( url , request ) : <EOL> raise RequestError ( "<STR_LIT>" ) <EOL> class CustomerProfileModelTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . user = create_user ( id = <NUM_LIT> , username = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> def create_profile ( self ) : <EOL> return CustomerProfile . objects . create ( <EOL> customer = self . user , profile_id = '<STR_LIT>' , sync = False ) <EOL> def test_create_sync_no_data ( self ) : <EOL> @ cim_url_match <EOL> def request_handler ( url , request ) : <EOL> request_xml = parseString ( request . body ) <EOL> self . assertEqual ( xml_to_dict ( request_xml ) , <EOL> create_empty_profile_success ) <EOL> return customer_profile_success . format ( <EOL> '<STR_LIT>' ) <EOL> profile = CustomerProfile ( customer = self . user ) <EOL> with HTTMock ( error_on_request ) : <EOL> self . assertRaises ( RequestError , profile . save ) <EOL> self . assertEqual ( profile . profile_id , '<STR_LIT>' ) <EOL> with HTTMock ( request_handler ) : <EOL> profile . save ( sync = True ) <EOL> self . assertEqual ( profile . profile_id , '<STR_LIT>' ) <EOL> @ with_httmock ( error_on_request ) <EOL> def test_create_no_sync ( self ) : <EOL> profile = CustomerProfile ( customer = self . user ) <EOL> profile . save ( sync = False ) <EOL> self . assertEqual ( profile . profile_id , '<STR_LIT>' ) <EOL> @ with_httmock ( error_on_request ) <EOL> def test_edit ( self ) : <EOL> profile = self . create_profile ( ) <EOL> self . assertEqual ( profile . profile_id , '<STR_LIT>' ) <EOL> profile . profile_id = '<STR_LIT>' <EOL> profile . save ( ) <EOL> self . assertEqual ( profile . profile_id , '<STR_LIT>' ) <EOL> profile . profile_id = '<STR_LIT>' <EOL> profile . save ( sync = True ) <EOL> self . assertEqual ( profile . profile_id , '<STR_LIT>' ) <EOL> profile . profile_id = '<STR_LIT>' <EOL> profile . save ( sync = False ) <EOL> self . assertEqual ( profile . profile_id , '<STR_LIT>' ) <EOL> def test_delete ( self ) : <EOL> @ cim_url_match <EOL> def request_handler ( url , request ) : <EOL> request_xml = parseString ( request . body ) <EOL> self . assertEqual ( xml_to_dict ( request_xml ) , <EOL> delete_profile_success ) <EOL> return delete_success . format ( <EOL> '<STR_LIT>' ) <EOL> profile = self . create_profile ( ) <EOL> with HTTMock ( request_handler ) : <EOL> profile . delete ( ) <EOL> self . assertEqual ( profile . __class__ . objects . count ( ) , <NUM_LIT:0> ) </s>
