def test_validate_user_funds(self): get_or_create_balance(self.user) self.user.balance.deposit(100) self.user.balance.save() self.assertTrue(validate_user_funds(self.user, 99), 'Should evaluate to True when user.balance >= funds.') self.assertTrue(validate_user_funds(self.user, 100), 'Should evaluate to True when user.balance >= funds.') self.assertFalse(validate_user_funds(self.user, 101), 'User does not have enough funds')
def join_orderline(request, group, orderline_id): orderline = get_object_or_404(OrderLine, pk=orderline_id) group = get_object_or_404(Group, name=group) # @TODO if not buddy system enabled, disable join if in_other_orderline(get_order(group), request.user): messages.error(request, 'You cannot be in multiple orderlines') logger.warn('%s tried to join multiple orderlines (new: %i) for "%s"!' % (request.user, orderline.id, get_order(group))) elif orderline.order.use_validation and \ not validate_user_funds( request.user, (orderline.price / (orderline.users.count() + 1))): # Adds us to the test as well messages.error(request, 'You need cashes') logger.info('%s tried to join an orderline for "%s", by %s, with insufficient funds.' % (request.user, orderline.order, orderline.creator)) else: orderline.users.add(request.user) orderline.save() messages.success(request, 'Joined orderline') return redirect('feedme:feedme_index_new', group)
def join_orderline(request, group, orderline_id): orderline = get_object_or_404(OrderLine, pk=orderline_id) group = get_object_or_404(Group, name=group) # @TODO if not buddy system enabled, disable join if in_other_orderline(get_order(group), request.user): messages.error(request, 'You cannot be in multiple orderlines') logger.warn( '%s tried to join multiple orderlines (new: %i) for "%s"!' % (request.user, orderline.id, get_order(group))) elif orderline.order.use_validation and \ not validate_user_funds( request.user, (orderline.price / (orderline.users.count() + 1))): # Adds us to the test as well messages.error(request, 'You need cashes') logger.info( '%s tried to join an orderline for "%s", by %s, with insufficient funds.' % (request.user, orderline.order, orderline.creator)) else: orderline.users.add(request.user) orderline.save() messages.success(request, 'Joined orderline') return redirect('feedme:feedme_index_new', group)
def validate_funds(user, amount): enough = validate_user_funds(user, amount) if not enough: raise ValidationError("Insufficient funds") return True
def validate_funds(user, amount): enough = validate_user_funds(user, amount) if not enough: raise ValidationError('Insufficient funds') return True