Beispiel #1
0
	def test_against_cascade_deletion_of_purchaseditem(self):
		"""Test that purchased items are not removed when related merchandise
		is

		"""
		account = Account(name="tset")
		account.deposit(500) # Depost issues the save routine
		operator = None

		m1 = Merchandise(name="m1", internal_price=3, ordinary_price=4)
		m1.save()
		m2 = Merchandise(name="m2", internal_price=2, ordinary_price=4)
		m2.save()

		# Test a basic purchase:
		trans = buy_merchandise(account, [m1], operator)

		# Test that transactions are not deleted when related merchandise is,
		# and that backup information is stored to merchandise_tags and
		# merchandise_name:
		pm1_id = PurchasedItem.objects.get(transaction=trans).id
		merchandise_name = m1.name[:30]
		merchandise_tags = "|".join((unicode(t) for t in m1.tags.all()))[:30]
		m1.delete()
		pm1 = PurchasedItem.objects.get(id=pm1_id)
		self.failUnlessEqual(pm1.merchandise_name, merchandise_name)
		self.failUnlessEqual(pm1.merchandise_tags, merchandise_tags)
Beispiel #2
0
	def test_merchandise_tags(self):
		"""Test that tags are not deleted together with merchandise.

		"""
		tag1 = MerchandiseTag(name="tag1")
		tag1.save()
		tag1_id = tag1.id
		m1 = Merchandise(name="m1", internal_price=3, ordinary_price=4)
		m1.save()
		m1.tags = [tag1]
		m1.save()

		# Test that the tag has been added:
		m1 = Merchandise.objects.get(id=m1.id)
		self.failUnlessEqual(m1.tags.all()[0], tag1)

		# Test that the tag is not deleted together with it's merchandise:
		m1.delete()
		tag_count = MerchandiseTag.objects.filter(id=tag1_id).count()
		self.failUnlessEqual(tag_count, 1)