本文整理匯總了Python中accounts.factories.UserFactory.total_cash方法的典型用法代碼示例。如果您正苦於以下問題:Python UserFactory.total_cash方法的具體用法?Python UserFactory.total_cash怎麽用?Python UserFactory.total_cash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類accounts.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.total_cash方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_buy_a_bet
# 需要導入模塊: from accounts.factories import UserFactory [as 別名]
# 或者: from accounts.factories.UserFactory import total_cash [as 別名]
def test_buy_a_bet(self):
"""
Buy a bet
"""
event = EventFactory()
user = UserFactory(total_cash=event.current_buy_for_price)
old_price = event.current_buy_for_price
bet_user, bet_event, bet = Bet.objects.buy_a_bet(user, event.id, Bet.YES,
event.current_buy_for_price)
self.assertEqual(user, bet_user)
self.assertEqual(event, bet_event)
self.assertEqual(event.current_buy_for_price, bet.bought_avg_price)
self.assertEqual(1, bet.has)
self.assertEqual(1, bet.bought)
self.assertEqual(0, bet_user.total_cash)
self.assertEqual(old_price, bet_user.portfolio_value)
self.assertNotEqual(old_price, bet_event.current_buy_for_price)
self.assertEqual(1, bet_event.turnover)
with self.assertRaises(PriceMismatch):
Bet.objects.buy_a_bet(user, event.id, Bet.YES, old_price)
with self.assertRaises(InsufficientCash):
Bet.objects.buy_a_bet(user, event.id, Bet.YES, bet_event.current_buy_for_price)
user.total_cash = bet_event.current_buy_against_price
user.save()
# TODO should throw exception
Bet.objects.buy_a_bet(user, event.id, Bet.NO, bet_event.current_buy_against_price)