本文整理汇总了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)