Exemple #1
0
 def create_game(self):
     uuid = uuid4()
     game = Games.objects.create(uuid=uuid,
                                 created_by=self.scope['user'],
                                 white_pieces_player=self.scope['user'])
     game_object = Game()
     cache.set(uuid, game_object)
     pass
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_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 #4
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 #5
0
    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
 def setUp(self):
     self.g = Game()
     self.g.save()