#NEWLINE# def test_purchase( self ) : #NEWLINE# #INDENT# account_obj = AccountFactory . create ( ) #NEWLINE# wallet_obj = WalletFactory . create ( owner_id = account_obj . id ) #NEWLINE# WalletTrxFactory . create ( wallet = balance , amount = Money ( 1000 , 'SEK' ) , trx_status = TrxStatus . FINALIZED ) #NEWLINE# product_obj1 = ProductFactory . create ( code = '1337733113370' , name = 'Billys Original' , price = Money ( 13 , 'SEK' ) ) #NEWLINE# product_obj2 = ProductFactory . create ( code = '7331733113370' , name = 'Kebaba' , price = Money ( 30 , 'SEK' ) ) #NEWLINE# products = [ ( product_obj1 . id , 3 ) , ( product_obj2 . id , 1 ) ] #NEWLINE# purchase_obj = api . purchase ( account_obj . id , products ) #NEWLINE# self . assertEqual ( purchase_obj . amount , Money ( 69 , 'SEK' ) ) #NEWLINE# product_obj1 . refresh_from_db ( ) #NEWLINE# product_obj2 . refresh_from_db ( ) #NEWLINE# self . assertEqual ( product_obj1 . qty , ( - 3 ) ) #NEWLINE# self . assertEqual ( product_obj2 . qty , ( - 1 ) ) #NEWLINE# ( _ , balance ) = wallet_api . get_balance ( account_obj . id ) #NEWLINE# self . assertEqual ( balance , Money ( 931 , 'SEK' ) ) #NEWLINE# ( _ , balance ) = wallet_api . get_balance ( settings . FOOBAR_MAIN_WALLET ) #NEWLINE# self . assertEqual ( balance , Money ( 69 , 'SEK' ) )