Example #1
0
	def test_freeze_access(self):
		"""
		Test freeze is only available to super user.
		"""
		u = User(username="******", is_staff=True)
		u.save()
		self.k.user = u
		freeze = Freeze(kingdom=self.k)

		# AssertNoRaises
		freeze.save()
Example #2
0
def api(request):
	"""
	JSON contribution to /api/kingdom from this app.
	"""

	resp = {
		'freezes': {
			'can_create': Freeze.can_freeze(request.user.kingdom),
			'can_restore': Freeze.can_freeze(request.user.kingdom) and request.user.kingdom.freeze_set.exists(),
			'links': {
				'create': reverse('internal.views.freeze_create'),
				'restore': reverse('internal.views.freeze_restore')
			}
		}
	}

	return resp
Example #3
0
	def test_freeze_nolock(self):
		"""
		Test freeze restoration is not bound to petty matter, such as "not leaving a mission before it ends".
		"""

		from mission.models import Mission, PendingMission, MissionGrid, PendingMissionAffectation
		m = Mission(
			name="Stub mission",
			slug="stub",
			title=None,
		)
		m.save()

		mg = MissionGrid(
			mission=m,
			slug='stub_grid'
		)
		mg.save()

		pm = PendingMission(
			mission=m,
			kingdom=self.k
		)
		pm.save()

		pma = PendingMissionAffectation(
			pending_mission=pm,
			mission_grid=mg,
			folk=self.f
		)
		pma.save()

		# Create the freeze
		freeze = Freeze(kingdom=self.k)
		freeze.save()

		pm.start()
		# Sanity check
		self.assertRaises(ValidationError, lambda: pm.delete())

		# Unfreeze.
		# No errors should be raised, even though the PendingMission is still deleted
		freeze.restore()

		self.assertFalse(PendingMission.objects.get(pk=pm.pk).is_started)
Example #4
0
	def test_freeze_destroyed(self):
		"""
		Test freeze mechanism : objects deleted post-freeze are recreated
		"""

		freezed_folk_pk = self.f.pk

		freeze = Freeze(kingdom=self.k)
		freeze.save()

		# Delete folk
		self.f.delete()

		# Unfreeze
		freeze.restore()

		# Check folk is restored
		self.assertEqual(Folk.objects.get(pk=freezed_folk_pk).first_name, self.f.first_name)
Example #5
0
	def test_freeze_m2m(self):
		"""
		Test freeze mechanism : m2m objects are restored
		"""
		freeze = Freeze(kingdom=self.k)
		freeze.save()

		# Launch trigger self.t
		self.k.population = 15
		self.k.prestige = 15
		self.k.money = 15
		self.k.save()
		# Sanity check
		self.assertEqual(1, self.k.trigger_set.count())

		# Unfreeze
		freeze.restore()

		self.assertEqual(0, self.k.trigger_set.count())
Example #6
0
	def test_freeze_created(self):
		"""
		Test freeze mechanism : objects created post-freeze are deleted
		"""
		freezed_folk_pk = self.f.pk

		self.f.delete()

		freeze = Freeze(kingdom=self.k)
		freeze.save()

		# Create new folk
		self.f.save()

		# Unfreeze
		freeze.restore()

		# Check folk has been removed
		self.assertRaises(Folk.DoesNotExist, lambda: Folk.objects.get(pk=freezed_folk_pk))
Example #7
0
	def test_freeze_advanced(self):
		"""
		Test advanced freeze mechanism : pending_event_variable are restored (this is "second level restoration" since this Variable has nothing to do with the kingdom)
		"""

		from event.models import Event, PendingEvent
		e = Event(
			name="Event 1",
			slug="event_1",
			category=None,
			text="Event 1",
			on_fire=""
		)
		e.save()
		pe = PendingEvent(
			event=e,
			kingdom=self.k
		)
		pe.save()
		pe.set_value('foo', 'bar')
		pe.set_value('folk', self.f)


		freezed_pe_pk = pe.pk

		freeze = Freeze(kingdom=self.k)
		freeze.save()

		# Terminate PendingEvent
		pe.delete()

		# Unfreeze
		freeze.restore()

		# Check variable has been restored
		pe = PendingEvent.objects.get(pk=freezed_pe_pk)
		self.assertEqual(pe.get_value('foo'), 'bar')
		self.assertEqual(pe.get_value('folk'), self.f)
Example #8
0
	def test_freeze_on_values(self):
		"""
		Test freeze mechanism : value restored.
		"""

		freezed_prestige = self.k.prestige
		freezed_folk_first_name = self.f.first_name

		freeze = Freeze(kingdom=self.k)
		freeze.save()

		# Change values
		self.k.prestige += 50
		self.k.save()

		self.f.first_name = "Raymondie"
		self.f.save()

		# Unfreeze
		freeze.restore()

		# Check values are restored
		self.assertEqual(Kingdom.objects.get(pk=self.k.pk).prestige, freezed_prestige)
		self.assertEqual(Folk.objects.get(pk=self.f.pk).first_name, freezed_folk_first_name)