Esempio n. 1
0
	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
Esempio n. 2
0
	def create_accounts(self, request, queryset):
		quryset = queryset.filter(account__isnull=True)
		n = queryset.count()

		# GUARD: Nothing to do?
		if n == 0:
			return

		# Create accounts:
		for obj in queryset:
			name = obj.get_full_name()
			if name in (" ", ""):
				name = obj.username
			a = Account(name=name, email=obj.email, user=obj)
			a.save()
			self.log_addition(request, a)

		# message for user:
		if n == 1: msg_bit = "1 account"
		else: msg_bit = "%s accounts" % n
		self.message_user(request, "Successfully created %s." % msg_bit)
Esempio n. 3
0
	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)
Esempio n. 4
0
	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)
Esempio n. 5
0
	def handle_noargs(self, *args, **options):
		#if len(args) != 0:
		#	 raise CommandError("Command doesn't accept any arguments")
		from django_kikrit.accounts.models import Account, LimitGroup, RFIDCard
		from django_kikrit.merchandise.models import Merchandise,MerchandiseTag

		# Create test Accounts and LimitGroups:
		lim1 = LimitGroup(name=u"Omega Verksted", black_limit=-200)
		lim2 = LimitGroup(name=u"Omega Verksted - VIP", black_limit=-1000,
				internal_price=True)
		lim1.save()
		lim2.save()
		print "2 LimitGroups created"

		a1 = Account(name=u"Workshop Dude", limit_group=lim1, balance=20)
		a2 = Account(name=u"Workshop Meister", limit_group=lim2, balance=8)
		a3 = Account(name=u"Humble Washing Lady", balance=15)
		a1.save()
		a2.save()
		a3.save()
		print "3 Accounts created"

		# Two cards are registered for the Workshop Dude, one for the Meister
		# and none for the Humble Washing Lady...
		c1 = RFIDCard(rfid_string=u"1101010001001", account=a1)
		c2 = RFIDCard(rfid_string=u"1101010001010", account=a1)
		c3 = RFIDCard(rfid_string=u"1101010001011", account=a2)
		c1.save()
		c2.save()
		c3.save()
		print "3 RFIDCards created"


		# Create test Merchandise and MerchandiseTags:
		t1 = MerchandiseTag(name="Beer")
		t2 = MerchandiseTag(name="Drink")
		t1.save()
		t2.save()
		print "2 MerchandiseTags created"

		m1 = Merchandise(name=u"Hansa Premium 0,5L", ordinary_price=30,
				internal_price=28, ean="001")
		m2 = Merchandise(name=u"Hansa Fatøl 0,5L", ordinary_price=30,
				internal_price=28,ean="002")
		m3 = Merchandise(name=u"Hansa Pilsner 0,33L", ordinary_price=20,
				internal_price=18,ean="003")
		m4 = Merchandise(name=u"Farvel til slekt og venner", ordinary_price=20,
				internal_price=18,ean="004")
		m5 = Merchandise(name=u"Dø og brenn i helvete", ordinary_price=20,
				internal_price=18, ean="005")
		m6 = Merchandise(name=u"m6", ordinary_price=10, internal_price=5)
		m7 = Merchandise(name=u"m7", ordinary_price=10, internal_price=5)
		m8 = Merchandise(name=u"m8", ordinary_price=10, internal_price=5)
		m9 = Merchandise(name=u"m9", ordinary_price=10, internal_price=5)
		m10 = Merchandise(name=u"m10", ordinary_price=10, internal_price=5)
		m11 = Merchandise(name=u"m11", ordinary_price=10, internal_price=5)
		m12 = Merchandise(name=u"m12", ordinary_price=10, internal_price=5)
		m13 = Merchandise(name=u"m13", ordinary_price=10, internal_price=5)
		m14 = Merchandise(name=u"m14", ordinary_price=10, internal_price=5)
		m15 = Merchandise(name=u"m15", ordinary_price=10, internal_price=5)
		m16 = Merchandise(name=u"m16", ordinary_price=10, internal_price=5)
		m17 = Merchandise(name=u"m17", ordinary_price=10, internal_price=5)
		m18 = Merchandise(name=u"m18", ordinary_price=10, internal_price=5)
		m19 = Merchandise(name=u"m19", ordinary_price=10, internal_price=5)
		m20 = Merchandise(name=u"m20", ordinary_price=10, internal_price=5)
		m21 = Merchandise(name=u"m21", ordinary_price=10, internal_price=5)
		m22 = Merchandise(name=u"m22", ordinary_price=10, internal_price=5)
		m23 = Merchandise(name=u"m23", ordinary_price=10, internal_price=5)
		m24 = Merchandise(name=u"m24", ordinary_price=10, internal_price=5)
		m25 = Merchandise(name=u"m25", ordinary_price=10, internal_price=5)
		m26 = Merchandise(name=u"m26", ordinary_price=10, internal_price=5)
		m27 = Merchandise(name=u"m27", ordinary_price=10, internal_price=5)
		m28 = Merchandise(name=u"m28", ordinary_price=10, internal_price=5)
		m29 = Merchandise(name=u"m29", ordinary_price=10, internal_price=5)
		m30 = Merchandise(name=u"m30", ordinary_price=10, internal_price=5)
		m1.save()
		m2.save()
		m3.save()
		m4.save()
		m5.save()
		m6.save()
		m7.save()
		m8.save()
		m9.save()
		m10.save()
		m11.save()
		m12.save()
		m13.save()
		m14.save()
		m15.save()
		m16.save()
		m17.save()
		m18.save()
		m19.save()
		m20.save()
		m21.save()
		m22.save()
		m23.save()
		m24.save()
		m25.save()
		m26.save()
		m27.save()
		m28.save()
		m29.save()
		m30.save()
		print "30 Merchandise created"

		# ManyToManyField data must be assigned after save:
		m1.tags = (t1,)
		m2.tags = (t1,)
		m3.tags = (t1,)
		m4.tags = (t2,)
		m5.tags = (t2,)
		print "5 Merchandise tag associations has been made"
		print "Move along now.."