예제 #1
0
파일: tests.py 프로젝트: smyrman/kikrit
	def test_basic_transactions(self):
		"""Test basic deposit and withdraw for normal accounts"""
		# Create an operator:
		operator = User(username="******", password="******")
		operator.save()

		# Create a bank account:
		account = Account(id=1, name="Test Account")
		account.save()

		# Test to deposit 200:
		trans_deposit = deposit_to_account(account, 200, operator)
		account = Account.objects.get(pk=1)
		self.failUnlessEqual(account.balance, 200)

		# Test to withdraw 200:
		trans_withdraw = withdraw_from_account(account, 200, operator)
		account = Account.objects.get(pk=1)
		self.failUnlessEqual(account.balance, 0)

		# Test that withdrawing 200 from an empty account fails:
		trans_withdraw2 = withdraw_from_account(account, 200, operator)
		self.failUnlessEqual(trans_withdraw2, None)

		# Return objects for reuse in other tests:
		return account, operator, trans_deposit, trans_withdraw
예제 #2
0
파일: tests.py 프로젝트: smyrman/kikrit
	def test_limitgroup_transactions(self):
		"""Test credit withdraw for accounts with limitgroup memberships"""

		# Create an operator:
		operator = User(username="******", password="******")
		operator.save()

		# Create a bank account with black_limit == -200:
		limit_group = LimitGroup(id=1, name="Tester1", black_limit=-200,
				max_grey_hours=1)
		limit_group.save()
		account = Account(id=1, name="Test Account", limit_group=limit_group)
		account.save()

		# Test to withdraw 199:
		trans_withdraw = withdraw_from_account(account, 199, operator)
		account = Account.objects.get(pk=1)
		self.failUnlessEqual(account.balance, -199)

		# Test to withdraw the last 1:
		trans_withdraw2 = withdraw_from_account(account, 1, operator)
		account = Account.objects.get(pk=1)
		self.failUnlessEqual(account.balance, -200)

		# Test that withdrawing another 1 fails:
		trans_withdraw3 = withdraw_from_account(account, 1, operator)
		self.failUnlessEqual(trans_withdraw3, None)

		# Test that the account go black after max_grey_hours == 1:
		trans_deposit = deposit_to_account(account, 50, operator)
		account.timestamp_grey = datetime.now() - timedelta(hours=1, seconds=1)
		account.save()
		trans_withdraw4 = withdraw_from_account(account, 1, operator)
		self.failUnlessEqual(trans_withdraw4, None)
예제 #3
0
파일: admin.py 프로젝트: smyrman/kikrit
	def save_form(self, request, form, change):
		if change:
			raise PermissionDenied

		obj = form.save(commit=False)
		trans = None

		if obj.type == Transaction.TYPE_DEPOSIT:
			trans = deposit_to_account(obj.account, obj.amount, request.user)
		elif obj.type == Transaction.TYPE_WITHDRAWAL:
			trans = withdraw_from_account(obj.account, obj.amount, request.user)
		elif obj.type == Transaction.TYPE_PURCHASE:
			trans = purchase_from_account(obj.account, obj.amount, request.user)

		if trans == None:
			raise PermissionDenied

		return trans
예제 #4
0
파일: tests.py 프로젝트: smyrman/kikrit
	def test_inactive_accounts(self):
		"""Test that withdraw and deposit are not possible for inactive
		accounts

		"""
		# Create account and operator:
		operator = User(username="******", password="******")
		operator.save()
		account = Account(id=1, name="Test Account", is_active=False)
		account.save()

		account_balance = account.balance

		# Test that withdraw fails:
		trans_withdraw = withdraw_from_account(account, 200, operator)
		self.failUnlessEqual(trans_withdraw, None)
		account = Account.objects.get(pk=1)
		self.failUnlessEqual(account.balance, account_balance)

		# Test that deposits are still allowed:
		trans_deposit = deposit_to_account(account, 200, operator)
		account = Account.objects.get(pk=1)
		self.failUnlessEqual(account.balance, account_balance+200)