Exemple #1
0
    def test_share_integrity(self):
        """
		Share corporation must be part of the same game as the player
		"""
        g2 = Game()
        g2.save()

        s = Share(corporation=g2.corporation_set.get(
            base_corporation_slug="renraku"),
                  player=self.p)

        self.assertRaises(IntegrityError, s.save)
Exemple #2
0
	def test_share_integrity(self):
		"""
		Share corporation must be part of the same game as the player
		"""
		g2 = Game()
		g2.save()

		s = Share(
			corporation=g2.corporation_set.get(base_corporation_slug="renraku"),
			player=self.p
		)

		self.assertRaises(IntegrityError, s.save)
Exemple #3
0
	def test_share_integrity(self):
		"""
		Share corporation must be part of the same game as the player
		"""
		g2 = Game()
		g2.save()

		s = Share(
			corporation=g2.corporations['c'],
			player=self.p
		)

		self.assertRaises(IntegrityError, s.save)
Exemple #4
0
class ManhattanEffectsTest(TestCase):
	"""
	Retrieve all Manhattan corporations, and check their first and last effects
	"""

	@classmethod
	def setUpClass(self):
		# Override to use Manhattan
		MANHATTAN_BASE_DIR = "%s/data/cities/manhattan" % settings.BASE_DIR
		BaseCorporation.BASE_CORPORATION_DIR = BaseCorporation.BASE_CORPORATION_TEMPLATE % MANHATTAN_BASE_DIR

		BaseCorporation.build_dict()
		self.g = Game()
		self.g.save()

	@classmethod
	def tearDownClass(self):
		BaseCorporation.BASE_CORPORATION_DIR = BaseCorporation.BASE_CORPORATION_TEMPLATE % settings.CITY_BASE_DIR
		BaseCorporation.build_dict()
		self.g.delete()

	def test_all_corporations_first_effect(self):
		"""
		Checking for all corporation first_effects
		"""
		ladder = self.g.get_ladder()
		for corporation in self.g.corporation_set.all():
			sid = transaction.savepoint()
			try:
				corporation.on_first_effect(ladder)
			except:
				e = sys.exc_value
				message = "[%s.on_first_effect] %s" % (corporation.base_corporation_slug, str(e))
				raise e.__class__(message)
			transaction.savepoint_rollback(sid)

	def test_all_corporations_last_effect(self):
		"""
		Checking for all corporation last_effects
		"""
		ladder = self.g.get_ladder()
		for corporation in self.g.corporation_set.all():
			sid = transaction.savepoint()
			try:
				corporation.on_last_effect(ladder)
			except:
				e = sys.exc_value
				message = "[%s.on_last_effect] %s" % (corporation.base_corporation_slug, str(e))
				raise e.__class__(message)
			transaction.savepoint_rollback(sid)
Exemple #5
0
class EngineTestCase(TestCase):
    """
	Base class for unittesting engine.
	Add a game in self.g and a player in self.p
	"""
    def setUp(self):
        """
		Setup initial configuration.
		For faster tests, remove all BaseCorporation to avoid creating useless fixtures.
		"""

        # Create a Game, without creating all default base corporations
        from engine_modules.corporation.models import Corporation, BaseCorporation
        original_base_corporations = BaseCorporation.base_corporations
        BaseCorporation.base_corporations = {}
        try:
            self.g = Game()
            # Disable all side effects for the game (first and last effects, invisible hand)
            self.g.disable_side_effects = True
            self.g.save()
        except:
            raise
        finally:
            BaseCorporation.base_corporations = original_base_corporations

        # Create base corporations
        self.c = Corporation(base_corporation_slug='shiawase', assets=10)
        self.c2 = Corporation(base_corporation_slug='renraku', assets=10)
        self.c3 = Corporation(base_corporation_slug='ares', assets=10)
        self.g.corporation_set.add(self.c, self.c2, self.c3)

        self.initial_money = Player._meta.get_field_by_name('money')[0].default
        self.p = Player(game=self.g, money=self.initial_money)
        self.p.save()

        # TODO: move to another place, in engine_modules/runs
        # TODO : add test for 90% restriction
        from engine_modules.run.models import RunOrder
        RunOrder.MAX_PERCENTS = 100

        from engine_modules.corporation_run.models import ProtectionOrder
        ProtectionOrder.MAX_PERCENTS = 100
Exemple #6
0
class ModelsTest(TestCase):
	"""
	Inherit from TestCase and not from EngineTestCase, since EngineTestCase overrides base corporation behavior for faster tests.
	"""

	def setUp(self):

		self.g = Game()
		self.g.save()

	def test_corporation_auto_created(self):
		"""
		Corporation should have been created alongside the game
		"""

		corporations = Corporation.objects.all().order_by('base_corporation_slug')
		self.assertEqual(len(corporations), len(BaseCorporation.retrieve_all()))

		self.assertEqual(corporations[0].base_corporation.slug, 'ares')
		self.assertEqual(corporations[0].base_corporation.datasteal, 10)
Exemple #7
0
	def test_post_create_signal(self):
		"""
		Check is current_turn can't be greater than total_turn
		"""
		def first_creation(sender, instance, **kwargs):
			first_creation.was_called = True
		first_creation.was_called = False

		post_create.connect(first_creation)
		g2 = Game()
		g2.save()
		self.assertTrue(first_creation.was_called)

		first_creation.was_called = False
		post_create.connect
		g2.current_turn += 1
		g2.save()
		# Should not be called again
		self.assertFalse(first_creation.was_called)

		post_create.disconnect(first_creation)
Exemple #8
0
class ModelsTest(TestCase):
    """
	Inherit from TestCase and not from EngineTestCase, since EngineTestCase overrides base corporation behavior for faster tests.
	"""
    def setUp(self):

        self.g = Game()
        self.g.save()

    def test_corporation_auto_created(self):
        """
		Corporation should have been created alongside the game
		"""

        corporations = Corporation.objects.all().order_by(
            'base_corporation_slug')
        self.assertEqual(len(corporations),
                         len(BaseCorporation.retrieve_all()))

        self.assertEqual(corporations[0].base_corporation.slug, 'ares')
        self.assertEqual(corporations[0].base_corporation.datasteal, 10)
Exemple #9
0
class ModelsTest(TestCase):
	"""
	Inherit from test case, to retrieve all corporations
	"""
	def setUp(self):
		self.g = Game()
		self.g.save()

	def test_all_corporations_first_effect(self):
		"""
		Checking for all corporation first_effects
		"""
		ladder = self.g.get_ladder()
		for corporation in self.g.corporation_set.all():
			sid = transaction.savepoint()
			try:
				corporation.on_first_effect(ladder)
			except:
				e = sys.exc_value
				message = "[%s.on_first_effect] %s" % (corporation.base_corporation_slug, str(e))
				raise e.__class__(message)
			transaction.savepoint_rollback(sid)
Exemple #10
0
    def test_post_create_signal(self):
        """
		Check is current_turn can't be greater than total_turn
		"""
        def first_creation(sender, instance, **kwargs):
            first_creation.was_called = True

        first_creation.was_called = False

        post_create.connect(first_creation)
        g2 = Game()
        g2.save()
        self.assertTrue(first_creation.was_called)

        first_creation.was_called = False
        post_create.connect
        g2.current_turn += 1
        g2.save()
        # Should not be called again
        self.assertFalse(first_creation.was_called)

        post_create.disconnect(first_creation)
Exemple #11
0
    def test_message_author_game_equals_player_game(self):
        """
		Check if author's game = player's game
		"""

        p2 = Player(game=self.g)
        p2.save()

        g2 = Game()
        g2.save()

        p3 = Player(game=g2)
        p3.save()

        m = Message(title="titre", author=self.p, turn=self.g.current_turn)
        m.save()
        m.recipient_set.add(p2)
        m.save()

        m2 = Message(title="titre1", author=self.p, turn=self.g.current_turn)
        m2.save()

        self.assertRaises(IntegrityError, lambda: m2.recipient_set.add(p3))
Exemple #12
0
	def test_message_author_game_equals_player_game(self):
		"""
		Check if author's game = player's game
		"""

		p2 = Player(game=self.g)
		p2.save()

		g2 = Game()
		g2.save()

		p3 = Player(game=g2)
		p3.save()

		m = Message(title="titre", author=self.p, turn=self.g.current_turn)
		m.save()
		m.recipient_set.add(p2)
		m.save()

		m2 = Message(title="titre1", author=self.p, turn=self.g.current_turn)
		m2.save()

		self.assertRaises(IntegrityError, lambda: m2.recipient_set.add(p3))
Exemple #13
0
class ModelsTest(TestCase):
    """
	Inherit from test case, to retrieve all corporations
	"""
    def setUp(self):
        self.g = Game()
        self.g.save()

    def test_all_corporations_first_effect(self):
        """
		Checking for all corporation first_effects
		"""
        ladder = self.g.get_ladder()
        for corporation in self.g.corporation_set.all():
            sid = transaction.savepoint()
            try:
                corporation.on_first_effect(ladder)
            except:
                e = sys.exc_value
                message = "[%s.on_first_effect] %s" % (
                    corporation.base_corporation_slug, str(e))
                raise e.__class__(message)
            transaction.savepoint_rollback(sid)
Exemple #14
0
class EngineTestCase(TestCase):
	"""
	Base class for unittesting engine.
	Add a game in self.g, a player in self.p
	And three corporations in self.c, self.c2 and self.c3.
	"""

	def setUp(self):
		"""
		Setup initial configuration.
		This is run on the test city, with few corporations, for faster tests.
		"""

		self.g = Game()
		# Disable all side effects for the game (first and last effects, invisible hand)
		self.g.disable_side_effects = True
		self.g.save()

		self.p = Player(game=self.g)
		self.p.save()

		# Add a value storing default money, can be used read_only for comparisons
		self.initial_money = self.p.money

		self.c = self.g.corporations['c']
		self.c2 = self.g.corporations['c2']
		self.c3 = self.g.corporations['c3']

		# TODO: move to another place, in engine_modules/runs/testcases?
		# TODO : add test for 90% restriction
		# Remove default 90% limitation, making test reliable
		from engine_modules.run.models import RunOrder
		RunOrder.MAX_PERCENTS = 100

		from engine_modules.corporation_run.models import ProtectionOrder
		ProtectionOrder.MAX_PERCENTS = 0