Esempio n. 1
0
	def test_get_citizenship_first_time_does_not_create_remove_citizenship_event(self):
		"""
		When you get citizenship for the first time, you should only fire the event of add_citizenship
		"""

		# create the function that will catch the signal
		@receiver(game_event)
		def catch_game_event(sender, instance, event_type, **kwargs):
			if event_type == 'ADD_CITIZENSHIP':
				self.g.add_citizenship_was_called = True
			elif event_type == 'REMOVE_CITIZENSHIP':
				raise Exception("Should not happen")

		# Change citizenship
		self.o = CitizenshipOrder(
			player=self.p,
			corporation=self.c
		)
		self.o.clean()
		self.o.save()

		self.g.resolve_current_turn()

		self.assertTrue(self.g.add_citizenship_was_called)

		# disconnect receiver
		game_event.disconnect(catch_game_event)
Esempio n. 2
0
	def test_get_citizenship_second_time_create_remove_citizenship_event(self):
		"""
		When you already have a citizenship and you change it, two events must be triggered
		"""
		# New turn because you can't change your citizenship twice in same turn
		self.g.resolve_current_turn()

		# create the function that will catch the signal
		@receiver(game_event)
		def catch_game_event(sender, instance, event_type, **kwargs):
			if event_type == 'ADD_CITIZENSHIP':
				self.g.add_citizenship_was_called = True
			elif event_type == 'REMOVE_CITIZENSHIP':
				self.g.remove_citizenship_was_called = True

		# Buy a share to have the new nationality
		self.s = Share(
			player=self.p,
			corporation=self.c2
		)
		self.s.save()

		# Change citizenship
		self.o = CitizenshipOrder(
			player=self.p,
			corporation=self.c2
		)
		self.o.clean()
		self.o.save()

		self.g.resolve_current_turn()

		self.assertTrue(self.g.add_citizenship_was_called)
		self.assertTrue(self.g.remove_citizenship_was_called)

		# disconnect receiver
		game_event.disconnect(catch_game_event)