Exemplo n.º 1
0
	def test_recurring_code(self):
		"""
		Test recurring condition code.
		"""

		r = Recurring(
			on_fire="""
status = "foo"
kingdom.money = 15
kingdom.save()
"""
		)
		r.save()

		status = r.fire(self.k)
		self.assertEqual(status, "foo")
		self.assertEqual(Kingdom.objects.get(pk=self.k.pk).money, 15)
Exemplo n.º 2
0
	def test_recurring_kingdoms(self):
		"""
		Test recurring returns a list of kingdoms on which to run
		"""

		r = Recurring(
			kingdom_list="""
param = Kingdom.objects.filter(prestige__lte=50)
"""
		)
		r.save()

		kingdoms = r.kingdoms()
		self.assertEqual(len(kingdoms), 1)

		self.k.prestige = 500
		self.k.save()
		kingdoms = r.kingdoms()
		self.assertEqual(len(kingdoms), 0)
Exemplo n.º 3
0
	def test_recurring_cron(self):
		"""
		Test recurring runs within the cron signal
		"""

		r = Recurring(
			delay=10,
			on_fire="""
kingdom.money = 500
kingdom.save()
"""
		)
		r.save()

		# Sanity check
		self.assertEqual(Kingdom.objects.get(pk=self.k.pk).money, 0)

		cron_ten_minutes.send(self, counter=5)
		self.assertEqual(Kingdom.objects.get(pk=self.k.pk).money, 0)

		cron_ten_minutes.send(self, counter=10)
		self.assertEqual(Kingdom.objects.get(pk=self.k.pk).money, 500)