コード例 #1
0
ファイル: session.py プロジェクト: noQ/TriviaOnline
 def can_join(self, user=None):
     """
         Join in session with different status: ready to play, not ready etc.
          
     """
     if not self.has_free_slots():
         return False
     if user is not None:
         self.set_user(user)
     ''' decrement slots '''
     self.session.available_slots -= 1
     """ check again if session has free slots. 
         if no slots available then change session status to "ready to play" (game),
         and set the player
     """ 
     if not self.has_free_slots():
         self.session.status = SessionStatus.ready_to_play.value
     
     player_status = PlayerStatus.not_ready.value
     if self.session.status == SessionStatus.ready_to_play.value:
         player_status = PlayerStatus.ready_to_play.value
     ''' create player object '''
     player = Player(uid = self.user.uid,
                     status = player_status
                     )
     ''' set player additional info '''
     player.get_player_info(self.user)
     ''' add player to current session '''
     self.add_player(player)
     ''' save session '''
     self.session.save()
     return True
コード例 #2
0
    def setUp(self):
        super(WiretransterOrderTest, self).setUp()

        self.p2 = Player(game=self.g, money=self.initial_money)
        self.p2.save()

        self.wo = WiretransferOrder(player=self.p, recipient=self.p2, amount=1)
コード例 #3
0
	def setUp(self):
		"""
		p is top shareholder in c,
		p2 is top shareholder in c2,
		p3 is top shareholder in c3,
		"""
		super(MDCPartyLineTest, self).setUp()

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

		self.p3 = Player(game=self.g, )
		self.p3.save()

		self.s = Share(
			corporation=self.c,
			player=self.p,
			turn=self.g.current_turn
		)
		self.s.save()

		self.s2 = Share(
			corporation=self.c2,
			player=self.p2,
			turn=self.g.current_turn
		)
		self.s2.save()

		self.s3 = Share(
			corporation=self.c3,
			player=self.p3,
			turn=self.g.current_turn
		)
		self.s3.save()
コード例 #4
0
    def setUp(self):
        """
		p is top shareholder in c,
		p2 is top shareholder in c2,
		p3 is top shareholder in c3,
		"""
        super(MDCPartyLineTest, self).setUp()

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

        self.p3 = Player(game=self.g, )
        self.p3.save()

        self.s = Share(corporation=self.c,
                       player=self.p,
                       turn=self.g.current_turn)
        self.s.save()

        self.s2 = Share(corporation=self.c2,
                        player=self.p2,
                        turn=self.g.current_turn)
        self.s2.save()

        self.s3 = Share(corporation=self.c3,
                        player=self.p3,
                        turn=self.g.current_turn)
        self.s3.save()
コード例 #5
0
ファイル: test_orders.py プロジェクト: silky/corporate
    def setUp(self):
        super(InformationRunOrderTest, self).setUp()

        self.p2 = Player(game=self.g, secrets="Some nasty sfuff")
        self.p2.save()
        self.p2.citizenship.corporation = self.c
        self.p2.citizenship.save()

        from engine_modules.influence.models import BuyInfluenceOrder

        # Initial setup, create a resolution sheet we'll use later.
        o = BuyInfluenceOrder(player=self.p2)
        o.save()

        self.g.resolve_current_turn()

        self.io = InformationOrder(
            target=self.p2,
            player=self.p,
            additional_percents=0,
        )
        self.io.clean()
        self.io.save()

        self.set_to_zero(self.io.target.citizenship.corporation)
コード例 #6
0
ファイル: session.py プロジェクト: noQ/TriviaOnline
 def create(self):
     """
         Create new session. default status is 'incomplete'
     """
     if self.user is None:
         raise TypeError("USER object must be provided!")
     
     ''' generate random name if not provided '''
     while not self.find_session(self.generate_session_name()):
         """ create new session with one player and status 'free' """
         player = Player(uid = self.user.uid,
                         status = PlayerStatus.ready_to_play.value
                         )
         ''' get player info based on current user '''
         player.get_player_info(self.user)
         ''' set available slots '''
         self.slots -= 1
         ''' create session object '''
         self.session = Session(name = self.session_name,
                                owner_uid = self.user.uid,
                                status = SessionStatus.incomplete.value,
                                is_active = True,
                                expired_at = self.expire_in(),
                                players = [player],
                                slots = self.slots,
                                game_name = self.game_name,
                                available_slots = self.slots
                           )
         self.session.save()
         return self.session
     return None
コード例 #7
0
ファイル: test_orders.py プロジェクト: Neamar/corporate
class WiretransterOrderTest(EngineTestCase):
	def setUp(self):
		super(WiretransterOrderTest, self).setUp()

		self.p2 = Player(game=self.g, money=self.initial_money)
		self.p2.save()

		self.wo = WiretransferOrder(
			player=self.p,
			recipient=self.p2,
			amount=1
		)

	def test_wiretransfer_immediate(self):
		"""
		Wiretransfer sends money immediately
		"""
		self.wo.save()

		# Effect should be immediate
		self.assertEqual(self.reload(self.p).money, self.initial_money - self.wo.amount)
		self.assertEqual(self.reload(self.p2).money, self.initial_money + self.wo.amount)

		# Wiretransfer should not be saved in DB
		self.assertIsNone(self.wo.pk)
コード例 #8
0
    def setUp(self):
        super(TaskTest, self).setUp()

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

        self.v = MDCVoteOrder(player=self.p, coalition=MDCVoteOrder.DERE)
        self.v.save()
コード例 #9
0
    def test_wiretransfer_run_cant_send_more_than_available(self):
        """
		Check you can't send more money than you have right now
		"""
        p2 = Player(game=self.g)
        p2.save()

        o = WiretransferOrder(player=self.p,
                              recipient=p2,
                              amount=self.p.money + 1)
        self.assertRaises(OrderNotAvailable, o.clean)
コード例 #10
0
ファイル: test_models.py プロジェクト: silky/corporate
	def test_game_add_newsfeed(self):
		"""
		Check add_newsfeed on Game
		"""
		u = User(username="******", email="*****@*****.**")
		u.save()

		p2 = Player(user=u, game=self.g, name="hahaha")
		p2.save()

		self.assertEqual(Newsfeed.objects.count(), 0)
		self.g.add_newsfeed(category=Newsfeed.MDC_REPORT, content="something")
		self.assertEqual(Newsfeed.objects.count(), 1)
コード例 #11
0
ファイル: test_signals.py プロジェクト: Neamar/corporate
	def test_wiretransfer_run_cant_send_more_than_available(self):
		"""
		Check you can't send more money than you have right now
		"""
		p2 = Player(game=self.g)
		p2.save()

		o = WiretransferOrder(
			player=self.p,
			recipient=p2,
			amount=self.p.money + 1
		)
		self.assertRaises(OrderNotAvailable, o.clean)
コード例 #12
0
ファイル: test_models.py プロジェクト: silky/corporate
    def test_game_add_newsfeed(self):
        """
		Check add_newsfeed on Game
		"""
        u = User(username="******", email="*****@*****.**")
        u.save()

        p2 = Player(user=u, game=self.g, name="hahaha")
        p2.save()

        self.assertEqual(Newsfeed.objects.count(), 0)
        self.g.add_newsfeed(category=Newsfeed.MDC_REPORT, content="something")
        self.assertEqual(Newsfeed.objects.count(), 1)
コード例 #13
0
ファイル: test_signals.py プロジェクト: Neamar/corporate
class SignalTest(EngineTestCase):
	def test_log_creation(self):
		"""
		Check a game_event creates a Logs in DB and a Many-To-Many with players
		"""
		self.p2 = Player(game=self.g, money=self.initial_money)
		self.p2.save()

		logs_before = Log.objects.count()
		m2m_before = ConcernedPlayer.objects.count()

		self.g.add_event(event_type=Game.WIRETRANSFER, data=None, players=[self.p, self.p2])

		self.assertEqual(1, Log.objects.count() - logs_before)
		self.assertEqual(2, ConcernedPlayer.objects.count() - m2m_before)
コード例 #14
0
ファイル: testcases.py プロジェクト: Neamar/corporate
	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
コード例 #15
0
ファイル: test_orders.py プロジェクト: silky/corporate
	def setUp(self):
		super(InformationRunOrderTest, self).setUp()

		self.p2 = Player(game=self.g, secrets="Some nasty sfuff")
		self.p2.save()
		self.p2.citizenship.corporation = self.c
		self.p2.citizenship.save()

		from engine_modules.influence.models import BuyInfluenceOrder

		# Initial setup, create a resolution sheet we'll use later.
		o = BuyInfluenceOrder(
			player=self.p2
		)
		o.save()

		self.g.resolve_current_turn()

		self.io = InformationOrder(
			target=self.p2,
			player=self.p,
			additional_percents=0,
		)
		self.io.clean()
		self.io.save()

		self.set_to_zero(self.io.target.citizenship.corporation)
コード例 #16
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
コード例 #17
0
ファイル: test_orders.py プロジェクト: Neamar/corporate
	def setUp(self):
		super(WiretransterOrderTest, self).setUp()

		self.p2 = Player(game=self.g, money=self.initial_money)
		self.p2.save()

		self.wo = WiretransferOrder(
			player=self.p,
			recipient=self.p2,
			amount=1
		)
コード例 #18
0
ファイル: test_tasks.py プロジェクト: silky/corporate
	def setUp(self):
		super(TaskTest, self).setUp()

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

		self.v = MDCVoteOrder(
			player=self.p,
			coalition=MDCVoteOrder.DERE
		)
		self.v.save()
コード例 #19
0
ファイル: test_orders.py プロジェクト: silky/corporate
    def test_equality_case(self):
        """
		Test when two players have the same amount of shares
		"""
        s = Share(
            corporation=self.c,
            player=self.p,
        )
        s.save()

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

        s2 = Share(
            corporation=self.c,
            player=p2,
        )
        s2.save()

        self.assertEqual(self.v.get_weight(), 1)
コード例 #20
0
ファイル: test_tasks.py プロジェクト: Neamar/corporate
	def setUp(self):
		super(TaskTest, self).setUp()

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

		self.v = DIncVoteOrder(
			player=self.p,
			coalition=DIncVoteOrder.CPUB
		)
		self.v.save()
コード例 #21
0
ファイル: test_orders.py プロジェクト: Neamar/corporate
	def test_equality_case(self):
		"""
		Test when two players have the same amount of shares
		"""
		s = Share(
			corporation=self.c,
			player=self.p,
		)
		s.save()

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

		s2 = Share(
			corporation=self.c,
			player=p2,
		)
		s2.save()

		self.assertEqual(self.v.get_weight(), 1)
コード例 #22
0
ファイル: test_models.py プロジェクト: silky/corporate
    def test_game_no_two_players_from_same_user_in_game(self):
        """
		Check if a user can't have 2 players in the same game
		"""

        u = User(username="******", email="*****@*****.**")
        u.save()

        self.p.user = u
        self.p.save()

        p2 = Player(user=u, game=self.g)
        self.assertRaises(IntegrityError, p2.save)
コード例 #23
0
ファイル: test_orders.py プロジェクト: silky/corporate
class WiretransterOrderTest(EngineTestCase):
	def setUp(self):
		super(WiretransterOrderTest, self).setUp()

		self.p2 = Player(game=self.g, money=self.initial_money)
		self.p2.save()

		self.wo = WiretransferOrder(
			player=self.p,
			recipient=self.p2,
			amount=1
		)

	def test_wiretransfer_immediate(self):
		"""
		Wiretransfer sends money immediately
		"""
		self.wo.save()

		# Effect should be immediate
		self.assertEqual(self.reload(self.p).money, self.initial_money - self.wo.amount)
		self.assertEqual(self.reload(self.p2).money, self.initial_money + self.wo.amount)

		# Wiretransfer should not be saved in DB
		self.assertIsNone(self.wo.pk)

	def test_wiretransfer_message(self):
		"""
		Wiretransfer sends a message to both players
		"""
		self.wo.save()

		m = Message.objects.get()
		self.assertEqual(m.title, "Transfert d'argent")
		self.assertEqual(m.flag, Message.CASH_TRANSFER)
		self.assertIn(self.wo.player.name, m.content)
		self.assertIn(self.wo.recipient.name, m.content)
		self.assertIn(str(self.wo.amount), m.content)
コード例 #24
0
ファイル: test_tasks.py プロジェクト: Neamar/corporate
class TaskTest(EngineTestCase):
	def setUp(self):
		super(TaskTest, self).setUp()

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

		self.v = DIncVoteOrder(
			player=self.p,
			coalition=DIncVoteOrder.CPUB
		)
		self.v.save()

	def test_coalition_set(self):
		"""
		Test the line is defined
		"""
		self.g.resolve_current_turn()

		dinc_vote_session = self.g.dincvotesession_set.get(turn=self.g.current_turn)
		self.assertEqual(dinc_vote_session.coalition, self.v.coalition)

	def test_equality_no_coalition(self):
		"""
		When an equality occurs, no line is set
		"""
		self.v2 = DIncVoteOrder(
			player=self.p2,
			coalition=DIncVoteOrder.RSEC
		)
		self.v2.save()

		self.g.resolve_current_turn()

		dinc_vote_session = (self.g.dincvotesession_set.get(turn=self.g.current_turn))
		self.assertEqual(dinc_vote_session.coalition, None)
コード例 #25
0
class WiretransterOrderTest(EngineTestCase):
    def setUp(self):
        super(WiretransterOrderTest, self).setUp()

        self.p2 = Player(game=self.g, money=self.initial_money)
        self.p2.save()

        self.wo = WiretransferOrder(player=self.p, recipient=self.p2, amount=1)

    def test_wiretransfer_immediate(self):
        """
		Wiretransfer sends money immediately
		"""
        self.wo.save()

        # Effect should be immediate
        self.assertEqual(
            self.reload(self.p).money, self.initial_money - self.wo.amount)
        self.assertEqual(
            self.reload(self.p2).money, self.initial_money + self.wo.amount)

        # Wiretransfer should not be saved in DB
        self.assertIsNone(self.wo.pk)

    def test_wiretransfer_message(self):
        """
		Wiretransfer sends a message to both players
		"""
        self.wo.save()

        m = Message.objects.get()
        self.assertEqual(m.title, "Transfert d'argent")
        self.assertEqual(m.flag, Message.CASH_TRANSFER)
        self.assertIn(self.wo.player.name, m.content)
        self.assertIn(self.wo.recipient.name, m.content)
        self.assertIn(str(self.wo.amount), m.content)
コード例 #26
0
ファイル: test_orders.py プロジェクト: Neamar/corporate
	def setUp(self):
		super(InformationRunOrderTest, self).setUp()

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

		from engine_modules.corporation_run.models import SabotageOrder

		# Initial setup, create logs we'll use later.
		o = SabotageOrder(
			player=self.p2,
			target_corporation_market=self.c.get_random_corporation_market_among_bests()
		)
		o.save()

		self.io = InformationOrder(
			player=self.p,
		)
		self.io.clean()
		self.io.save()
コード例 #27
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))
コード例 #28
0
ファイル: test_models.py プロジェクト: silky/corporate
	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))
コード例 #29
0
ファイル: test_tasks.py プロジェクト: silky/corporate
class TaskTest(EngineTestCase):
	def setUp(self):
		super(TaskTest, self).setUp()

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

		self.v = MDCVoteOrder(
			player=self.p,
			coalition=MDCVoteOrder.DERE
		)
		self.v.save()

	def test_coalition_set(self):
		"""
		Test the line is defined
		"""
		self.g.resolve_current_turn()

		mdc_vote_session = self.g.mdcvotesession_set.get(turn=self.g.current_turn)
		self.assertEqual(mdc_vote_session.coalition, self.v.coalition)

	def test_equality_no_coalition(self):
		"""
		When an equality occurs, no line is set
		"""
		self.v2 = MDCVoteOrder(
			player=self.p2,
			coalition=MDCVoteOrder.DEVE
		)
		self.v2.save()

		self.g.resolve_current_turn()

		mdc_vote_session = (self.g.mdcvotesession_set.get(turn=self.g.current_turn))
		self.assertEqual(mdc_vote_session.coalition, None)

	def test_coalition_resolution_message(self):
		"""
		Beneficiary and victims get a note in resolution message
		"""
		v2 = MDCVoteOrder(
			player=self.p2,
			coalition=MDCVoteOrder.BANK
		)
		v2.save()

		# Give priority to player 1
		Share(corporation=self.c, player=self.p, turn=self.g.current_turn).save()

		self.g.resolve_current_turn()

		self.assertIn("MDC a suivi", self.p.message_set.get().content)
		self.assertIn(u"MDC a rejoint la coalition opposée", self.p2.message_set.get().content)

	def test_coalition_newsfeed(self):
		"""
		Newsfeeds describes everything.
		"""
		self.p.name = "p1"
		self.p.save()
		self.p2.name = "p2"
		self.p2.save()

		v2 = MDCVoteOrder(
			player=self.p2,
			coalition=MDCVoteOrder.BANK
		)
		v2.save()

		# Give priority to player 1
		s = Share(corporation=self.c, player=self.p, turn=self.g.current_turn)
		s.save()
		s2 = Share(corporation=self.c2, player=self.p, turn=self.g.current_turn)
		s2.save()

		self.g.resolve_current_turn()

		ns = Newsfeed.objects.last().content
		self.assertIn(self.p.name, ns)
		self.assertIn(self.p2.name, ns)
		self.assertIn(s.corporation.base_corporation.name, ns)
		self.assertIn(s2.corporation.base_corporation.name, ns)
		self.assertIn(self.v.get_coalition_display(), ns)
		self.assertIn(v2.get_coalition_display(), ns)
		self.assertIn("3 voix", ns)
		self.assertIn("1 voix", ns)
コード例 #30
0
class MDCPartyLineTest(EngineTestCase):
	def setUp(self):
		"""
		p is top shareholder in c,
		p2 is top shareholder in c2,
		p3 is top shareholder in c3,
		"""
		super(MDCPartyLineTest, self).setUp()

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

		self.p3 = Player(game=self.g, )
		self.p3.save()

		self.s = Share(
			corporation=self.c,
			player=self.p,
			turn=self.g.current_turn
		)
		self.s.save()

		self.s2 = Share(
			corporation=self.c2,
			player=self.p2,
			turn=self.g.current_turn
		)
		self.s2.save()

		self.s3 = Share(
			corporation=self.c3,
			player=self.p3,
			turn=self.g.current_turn
		)
		self.s3.save()

	def set_turn_line(self, L1, L2, L3):
		"""
		A little helper to set the Line each player has voted for this turn
		"""

		v = MDCVoteOrder(
			player=self.p,
			coalition=L1
		)
		v.save()

		v2 = MDCVoteOrder(
			player=self.p2,
			coalition=L2
		)
		v2.save()

		v3 = MDCVoteOrder(
			player=self.p3,
			coalition=L3
		)
		v3.save()

	def test_mdc_CPUB_line_effects(self):
		"""
		Test what happens when the CPUB party line is chosen
		"""

		initial_assets = self.c.assets
		initial_assets2 = self.c2.assets
		initial_assets3 = self.c3.assets

		self.set_turn_line(MDCVoteOrder.CPUB, MDCVoteOrder.CPUB, MDCVoteOrder.DEVE)

		self.g.resolve_current_turn()

		self.assertEqual(self.reload(self.c).assets, initial_assets + 1)
		self.assertEqual(self.reload(self.c2).assets, initial_assets2 + 1)
		self.assertEqual(self.reload(self.c3).assets, initial_assets3 - 1)

	def test_mdc_DEVE_line_effects(self):
		"""
		Test what happens when the CPUB party line is chosen
		"""

		initial_assets = self.c.assets
		initial_assets2 = self.c2.assets
		initial_assets3 = self.c3.assets

		self.set_turn_line(MDCVoteOrder.CPUB, MDCVoteOrder.DEVE, MDCVoteOrder.DEVE)

		self.g.resolve_current_turn()

		self.assertEqual(self.reload(self.c).assets, initial_assets - 1)
		self.assertEqual(self.reload(self.c2).assets, initial_assets2 + 1)
		self.assertEqual(self.reload(self.c3).assets, initial_assets3 + 1)

	def test_mdc_CCIB_line_positive_effects(self):
		"""
		Test what happens to voters of the CCIB party line when it is chosen
		"""

		self.set_turn_line(MDCVoteOrder.CCIB, MDCVoteOrder.CCIB, MDCVoteOrder.TRAN)
		self.g.resolve_current_turn()

		dso = DataStealOrder(
			stealer_corporation=self.c2,
			player=self.p,
			target_corporation=self.c,
			additional_percents=5,
		)
		dso.save()

		# 20% malus
		self.assertEqual(dso.get_raw_probability(), dso.additional_percents * 10 + dso.BASE_SUCCESS_PROBABILITY - 20)

		# Other have no bonus
		dso2 = DataStealOrder(
			stealer_corporation=self.c,
			player=self.p,
			target_corporation=self.c3,
			additional_percents=5,
		)
		dso2.save()

		self.assertEqual(dso2.get_raw_probability(), dso2.additional_percents * 10 + dso2.BASE_SUCCESS_PROBABILITY)

	def test_mdc_CCIB_line_negative_effects(self):
		"""
		Test what happens when the CCIB party line is chosen to players who voted for transparency
		"""

		self.set_turn_line(MDCVoteOrder.CCIB, MDCVoteOrder.CCIB, MDCVoteOrder.TRAN)
		self.g.resolve_current_turn()

		# Player 3 has voted transparency, so he shouldn't be able to have a protection run
		po = ProtectionOrder(
			player=self.p3,
			protected_corporation=self.c,
			defense=ProtectionOrder.SABOTAGE,
		)
		self.assertRaises(OrderNotAvailable, po.clean)

		# Player 1 still can
		po2 = ProtectionOrder(
			player=self.p,
			protected_corporation=self.c,
			defense=ProtectionOrder.SABOTAGE,
		)
		po2.clean()

	def test_mdc_TRAN_line_effects(self):
		"""
		Test what happens when the TRAN party line is chosen
		"""

		self.set_turn_line(MDCVoteOrder.CCIB, MDCVoteOrder.TRAN, MDCVoteOrder.TRAN)
		self.g.resolve_current_turn()

		dso = DataStealOrder(
			stealer_corporation=self.c2,
			player=self.p,
			target_corporation=self.c,
			additional_percents=5,
		)
		dso.save()

		# 20% bonus
		self.assertEqual(dso.get_raw_probability(), dso.additional_percents * 10 + dso.BASE_SUCCESS_PROBABILITY - 20)

		dso2 = DataStealOrder(
			stealer_corporation=self.c2,
			player=self.p2,
			target_corporation=self.c,
			additional_percents=5,
		)
		dso2.save()

		# 20% malus
		self.assertEqual(dso2.get_raw_probability(), dso2.additional_percents * 10 + dso2.BASE_SUCCESS_PROBABILITY + 20)

	def test_mdc_BANK_line_positive_effect(self):
		"""
		Test what happens when BANK party line is chosen to people who voted it
		"""

		self.set_turn_line(MDCVoteOrder.BANK, MDCVoteOrder.BANK, MDCVoteOrder.DERE)
		self.c.update_assets(10)
		self.g.resolve_current_turn()

		# should fail, because c is first rank
		o = CorporationSpeculationOrder(
			player=self.p,
			corporation=self.c2,
			rank=1,
			investment=5
		)
		o.save()
		o.resolve()

		self.assertEqual(o.on_win_ratio, 2)  # Default
		self.assertEqual(o.on_loss_ratio, 0)  # 1 - 1
		self.assertEqual(self.reload(self.p).money, self.initial_money)

	def test_mdc_BANK_line_negative_effect(self):
		"""
		Test what happens when BANK party line is chosen to people who voted deregulation
		"""

		self.set_turn_line(MDCVoteOrder.BANK, MDCVoteOrder.BANK, MDCVoteOrder.DERE)
		self.g.resolve_current_turn()

		# Player 3 has voted DERE, so he shouldn't be able to speculate
		o = CorporationSpeculationOrder(
			player=self.p3,
			corporation=self.c3,
			rank=1,
			investment=1
		)
		self.assertRaises(OrderNotAvailable, o.clean)

		# Check that player 1 still can
		o2 = CorporationSpeculationOrder(
			player=self.p,
			corporation=self.c3,
			rank=1,
			investment=1
		)
		o2.clean()

	def test_mdc_DERE_line_positive_effect(self):
		"""
		Test what happens when the DERE party line is chosen for players who voted for it
		"""

		self.set_turn_line(MDCVoteOrder.BANK, MDCVoteOrder.DERE, MDCVoteOrder.DERE)
		self.g.resolve_current_turn()

		o = CorporationSpeculationOrder(
			player=self.p2,
			corporation=self.c,
			rank=1,
			investment=5
		)
		o.save()

		o.resolve()
		self.assertEqual(o.on_win_ratio, 3)  # 2 + 1
		self.assertEqual(o.on_loss_ratio, 1)  # Default
		self.assertEqual(self.reload(self.p2).money, self.initial_money + o.investment * 3)

	def test_mdc_DERE_line_negative_effect(self):
		"""
		Test what happens when the DERE party line is chosen for detractors
		"""

		self.set_turn_line(MDCVoteOrder.BANK, MDCVoteOrder.DERE, MDCVoteOrder.DERE)
		self.g.resolve_current_turn()

		# Player 1 has voted BANK, so he shouldn't be able to speculate
		o = CorporationSpeculationOrder(
			player=self.p,
			corporation=self.c3,
			rank=1,
			investment=5
		)
		self.assertRaises(OrderNotAvailable, o.clean)

		# Check that player 3 still can
		o2 = CorporationSpeculationOrder(
			player=self.p3,
			corporation=self.c3,
			rank=1,
			investment=5
		)
		o2.clean()
コード例 #31
0
class TaskTest(EngineTestCase):
    def setUp(self):
        super(TaskTest, self).setUp()

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

        self.v = MDCVoteOrder(player=self.p, coalition=MDCVoteOrder.DERE)
        self.v.save()

    def test_coalition_set(self):
        """
		Test the line is defined
		"""
        self.g.resolve_current_turn()

        mdc_vote_session = self.g.mdcvotesession_set.get(
            turn=self.g.current_turn)
        self.assertEqual(mdc_vote_session.coalition, self.v.coalition)

    def test_equality_no_coalition(self):
        """
		When an equality occurs, no line is set
		"""
        self.v2 = MDCVoteOrder(player=self.p2, coalition=MDCVoteOrder.DEVE)
        self.v2.save()

        self.g.resolve_current_turn()

        mdc_vote_session = (self.g.mdcvotesession_set.get(
            turn=self.g.current_turn))
        self.assertEqual(mdc_vote_session.coalition, None)

    def test_coalition_resolution_message(self):
        """
		Beneficiary and victims get a note in resolution message
		"""
        v2 = MDCVoteOrder(player=self.p2, coalition=MDCVoteOrder.BANK)
        v2.save()

        # Give priority to player 1
        Share(corporation=self.c, player=self.p,
              turn=self.g.current_turn).save()

        self.g.resolve_current_turn()

        self.assertIn("MDC a suivi", self.p.message_set.get().content)
        self.assertIn(u"MDC a rejoint la coalition opposée",
                      self.p2.message_set.get().content)

    def test_coalition_newsfeed(self):
        """
		Newsfeeds describes everything.
		"""
        self.p.name = "p1"
        self.p.save()
        self.p2.name = "p2"
        self.p2.save()

        v2 = MDCVoteOrder(player=self.p2, coalition=MDCVoteOrder.BANK)
        v2.save()

        # Give priority to player 1
        s = Share(corporation=self.c, player=self.p, turn=self.g.current_turn)
        s.save()
        s2 = Share(corporation=self.c2,
                   player=self.p,
                   turn=self.g.current_turn)
        s2.save()

        self.g.resolve_current_turn()

        ns = Newsfeed.objects.last().content
        self.assertIn(self.p.name, ns)
        self.assertIn(self.p2.name, ns)
        self.assertIn(s.corporation.base_corporation.name, ns)
        self.assertIn(s2.corporation.base_corporation.name, ns)
        self.assertIn(self.v.get_coalition_display(), ns)
        self.assertIn(v2.get_coalition_display(), ns)
        self.assertIn("3 voix", ns)
        self.assertIn("1 voix", ns)
コード例 #32
0
ファイル: test_orders.py プロジェクト: silky/corporate
class InformationRunOrderTest(RunOrdersTest):
    def setUp(self):
        super(InformationRunOrderTest, self).setUp()

        self.p2 = Player(game=self.g, secrets="Some nasty sfuff")
        self.p2.save()
        self.p2.citizenship.corporation = self.c
        self.p2.citizenship.save()

        from engine_modules.influence.models import BuyInfluenceOrder

        # Initial setup, create a resolution sheet we'll use later.
        o = BuyInfluenceOrder(player=self.p2)
        o.save()

        self.g.resolve_current_turn()

        self.io = InformationOrder(
            target=self.p2,
            player=self.p,
            additional_percents=0,
        )
        self.io.clean()
        self.io.save()

        self.set_to_zero(self.io.target.citizenship.corporation)

    def tearDown(self):
        self.set_to_original(self.io.target.citizenship.corporation)

    def test_information_success(self):
        """
		Information yields players data
		"""
        self.io.additional_percents = 10
        self.io.save()
        # Save message
        p2_resolution_message = self.p2.message_set.get(
            flag=Message.RESOLUTION, turn=1).content
        p2_resolution_message_formatted = p2_resolution_message.replace(
            '# ', '## ')

        self.g.resolve_current_turn()

        p_results = self.p.message_set.get(
            flag=Message.PRIVATE_MESSAGE).content

        self.assertIn("Tour 1", p_results)
        self.assertIn(self.p2.secrets, p_results)
        self.assertNotIn("Tour 2", p_results)  # Current turn not included

        self.assertIn(p2_resolution_message_formatted, p_results)

    def test_information_failure(self):
        """
		Failed information should not give information
		"""
        self.io.hidden_percents -= 10
        self.io.save()
        self.g.resolve_current_turn()

        self.assertRaises(
            Message.DoesNotExist,
            lambda: self.p.message_set.get(flag=Message.PRIVATE_MESSAGE))
コード例 #33
0
ファイル: test_dinc_lines.py プロジェクト: Neamar/corporate
class DIncPartyLineTest(EngineTestCase):
    def setUp(self):
        """
		p is top shareholder in c,
		p2 is top shareholder in c2,
		p3 is top shareholder in c3,
		"""
        super(DIncPartyLineTest, self).setUp()

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

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

        self.s = Share(corporation=self.c, player=self.p, turn=self.g.current_turn)
        self.s.save()

        self.s2 = Share(corporation=self.c2, player=self.p2, turn=self.g.current_turn)
        self.s2.save()

        self.s3 = Share(corporation=self.c3, player=self.p3, turn=self.g.current_turn)
        self.s3.save()

    def set_turn_line(self, L1, L2, L3):
        """
		A little helper to set the Line each player has voted for this turn
		"""

        v = DIncVoteOrder(player=self.p, coalition=L1)
        v.save()

        v2 = DIncVoteOrder(player=self.p2, coalition=L2)
        v2.save()

        v3 = DIncVoteOrder(player=self.p3, coalition=L3)
        v3.save()

    def test_dinc_CPUB_line_effects(self):
        """
		Test what happens when the CPUB party line is chosen
		"""

        initial_assets = self.c.assets
        initial_assets2 = self.c2.assets
        initial_assets3 = self.c3.assets

        self.set_turn_line(DIncVoteOrder.CPUB, DIncVoteOrder.CPUB, DIncVoteOrder.RSEC)

        self.g.resolve_current_turn()

        self.assertEqual(self.reload(self.c).assets, initial_assets + 1)
        self.assertEqual(self.reload(self.c2).assets, initial_assets2 + 1)
        self.assertEqual(self.reload(self.c3).assets, initial_assets3 - 1)

    def test_dinc_RSEC_good_effects(self):
        """
		Test what happens when the RSEC party line is chosen
		"""

        self.set_turn_line(DIncVoteOrder.CONS, DIncVoteOrder.RSEC, DIncVoteOrder.RSEC)
        self.g.resolve_current_turn()

        dso = DataStealOrder(
            stealer_corporation=self.c2,
            player=self.p2,
            target_corporation_market=self.c.corporation_markets.first(),
            additional_percents=5,
        )
        dso.save()

        # Reduction on first run
        self.assertEqual(
            dso.get_cost(), max(0, dso.LAUNCH_COST + dso.BASE_COST * dso.additional_percents - dso.INFLUENCE_BONUS)
        )

        dso2 = DataStealOrder(
            stealer_corporation=self.c2,
            player=self.p2,
            target_corporation_market=self.c.corporation_markets.first(),
            additional_percents=5,
        )
        dso2.save()

        # No reduction on second run
        self.assertEqual(dso2.get_cost(), max(0, dso2.LAUNCH_COST + dso2.BASE_COST * dso2.additional_percents))

    def test_dinc_RSEC_last_turn(self):
        """
		Should not reduce price of a run
		"""
        while self.g.current_turn < self.g.total_turn - 1:
            self.g.resolve_current_turn()
        self.set_turn_line(DIncVoteOrder.CONS, DIncVoteOrder.RSEC, DIncVoteOrder.RSEC)
        self.g.resolve_current_turn()

        dso3 = DataStealOrder(
            stealer_corporation=self.c2,
            player=self.p2,
            target_corporation_market=self.c.corporation_markets.first(),
            additional_percents=5,
        )
        dso3.save()

        # Reduction on first run
        self.assertEqual(dso3.get_cost(), dso3.LAUNCH_COST + dso3.BASE_COST * dso3.additional_percents)

    def test_dinc_RSEC_bad_effects_apply_on_CONS(self):
        """
		Test what happens when the RSEC party line is chosen
		"""

        self.set_turn_line(DIncVoteOrder.CONS, DIncVoteOrder.RSEC, DIncVoteOrder.RSEC)
        self.g.resolve_current_turn()

        common_corporation_market = self.c.get_common_corporation_market(self.c2)

        dso = DataStealOrder(
            stealer_corporation=self.c2,
            player=self.p,
            target_corporation_market=common_corporation_market,
            additional_percents=5,
        )
        dso.save()
        begin_assets_stealer = dso.stealer_corporation.assets

        self.g.resolve_current_turn()
        # Test that the run fail
        self.assertEqual(self.reload(dso.stealer_corporation).assets, begin_assets_stealer)

    def test_dinc_RSEC_bad_effects_do_not_apply_on_CPUB(self):
        """
		Test what happens when the RSEC party line is chosen
		"""

        self.set_turn_line(DIncVoteOrder.CPUB, DIncVoteOrder.RSEC, DIncVoteOrder.RSEC)
        self.g.resolve_current_turn()

        common_corporation_market = self.c.get_common_corporation_market(self.c2)

        dso = DataStealOrder(
            stealer_corporation=self.c2,
            player=self.p,
            target_corporation_market=common_corporation_market,
            additional_percents=5,
        )
        dso.save()
        begin_assets_stealer = dso.stealer_corporation.assets

        self.g.resolve_current_turn()
        # Test that the run fail
        self.assertNotEqual(self.reload(dso.stealer_corporation).assets, begin_assets_stealer)

    def test_dinc_RSEC_bad_effects_do_not_apply_on_RSEC(self):
        """
		Test what happens when the RSEC party line is chosen
		"""

        self.set_turn_line(DIncVoteOrder.CPUB, DIncVoteOrder.RSEC, DIncVoteOrder.RSEC)
        self.g.resolve_current_turn()

        common_corporation_market = self.c.get_common_corporation_market(self.c2)

        dso = DataStealOrder(
            stealer_corporation=self.c2,
            player=self.p2,
            target_corporation_market=common_corporation_market,
            additional_percents=5,
        )
        dso.save()
        begin_assets_stealer = dso.stealer_corporation.assets

        self.g.resolve_current_turn()
        # Test that the run fail
        self.assertNotEqual(self.reload(dso.stealer_corporation).assets, begin_assets_stealer)
コード例 #34
0
ファイル: test_orders.py プロジェクト: Neamar/corporate
class InformationRunOrderTest(EngineTestCase):
	def setUp(self):
		super(InformationRunOrderTest, self).setUp()

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

		from engine_modules.corporation_run.models import SabotageOrder

		# Initial setup, create logs we'll use later.
		o = SabotageOrder(
			player=self.p2,
			target_corporation_market=self.c.get_random_corporation_market_among_bests()
		)
		o.save()

		self.io = InformationOrder(
			player=self.p,
		)
		self.io.clean()
		self.io.save()

	def test_no_information_gives_no_logs(self):
		"""
		No information run == no logs for target player.
		Just a sanity check
		"""
		self.io.delete()

		self.g.resolve_current_turn()

		# Sanity check: no information run, no knownloedge on player 2 action
		self.assertEqual(len(Log.objects.for_player(self.p2, self.p, self.g.current_turn)), 0)

	def test_information_on_player_gives_logs(self):
		"""
		Information run gives information about the sabotage
		"""
		self.io.player_targets.add(self.p2)
		self.g.resolve_current_turn()

		self.assertEqual(len(Log.objects.for_player(self.p2, self.p, self.g.current_turn).filter(Q(event_type=self.g.OPE_SABOTAGE) | Q(event_type=self.g.OPE_SABOTAGE_FAIL))), 1)

	def test_double_information_gives_logs(self):
		"""
		Sending the same information run twice should not crash (not add concernedplayer twice)
		"""
		self.io.player_targets.add(self.p2)
		self.io2 = InformationOrder(
			player=self.p,
			additional_percents=10,
		)
		self.io2.clean()
		self.io2.save()
		self.io2.player_targets.add(self.p2)

		self.g.resolve_current_turn()

		self.assertEqual(len(Log.objects.for_player(self.p2, self.p, self.g.current_turn).filter(Q(event_type=self.g.OPE_SABOTAGE) | Q(event_type=self.g.OPE_SABOTAGE_FAIL))), 1)

	def test_informations_on_corporations_gives_logs(self):
		self.io.corporation_targets.add(self.c)

		self.g.resolve_current_turn()

	def test_information_on_corporation_give_logs(self):
		"""
		We get information about the corporation
		"""
		self.io.corporation_targets.add(self.c)
		self.g.resolve_current_turn()

		self.assertEqual(len(Log.objects.for_player(self.p2, self.p, self.g.current_turn)), 1)

	def test_more_information_than_money(self):
		"""
		We have enough to buy 1 player and 2 corporation and we ask for 1 player and 3 corporations. The order should be reduced to 1 player and 2 corporations
		"""

		self.p.money = 2 * InformationOrder.CORPORATION_COST + InformationOrder.PLAYER_COST
		self.p.save()

		self.io.player_targets.add(self.p2)
		self.io.corporation_targets.add(self.c, self.c2, self.c3)

		self.assertEqual(self.io.player_targets.count(), 1)
		self.assertEqual(self.io.corporation_targets.count(), 2)
コード例 #35
0
class MDCPartyLineTest(EngineTestCase):
    def setUp(self):
        """
		p is top shareholder in c,
		p2 is top shareholder in c2,
		p3 is top shareholder in c3,
		"""
        super(MDCPartyLineTest, self).setUp()

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

        self.p3 = Player(game=self.g, )
        self.p3.save()

        self.s = Share(corporation=self.c,
                       player=self.p,
                       turn=self.g.current_turn)
        self.s.save()

        self.s2 = Share(corporation=self.c2,
                        player=self.p2,
                        turn=self.g.current_turn)
        self.s2.save()

        self.s3 = Share(corporation=self.c3,
                        player=self.p3,
                        turn=self.g.current_turn)
        self.s3.save()

    def set_turn_line(self, L1, L2, L3):
        """
		A little helper to set the Line each player has voted for this turn
		"""

        v = MDCVoteOrder(player=self.p, coalition=L1)
        v.save()

        v2 = MDCVoteOrder(player=self.p2, coalition=L2)
        v2.save()

        v3 = MDCVoteOrder(player=self.p3, coalition=L3)
        v3.save()

    def test_mdc_CPUB_line_effects(self):
        """
		Test what happens when the CPUB party line is chosen
		"""

        initial_assets = self.c.assets
        initial_assets2 = self.c2.assets
        initial_assets3 = self.c3.assets

        self.set_turn_line(MDCVoteOrder.CPUB, MDCVoteOrder.CPUB,
                           MDCVoteOrder.DEVE)

        self.g.resolve_current_turn()

        self.assertEqual(self.reload(self.c).assets, initial_assets + 1)
        self.assertEqual(self.reload(self.c2).assets, initial_assets2 + 1)
        self.assertEqual(self.reload(self.c3).assets, initial_assets3 - 1)

    def test_mdc_DEVE_line_effects(self):
        """
		Test what happens when the CPUB party line is chosen
		"""

        initial_assets = self.c.assets
        initial_assets2 = self.c2.assets
        initial_assets3 = self.c3.assets

        self.set_turn_line(MDCVoteOrder.CPUB, MDCVoteOrder.DEVE,
                           MDCVoteOrder.DEVE)

        self.g.resolve_current_turn()

        self.assertEqual(self.reload(self.c).assets, initial_assets - 1)
        self.assertEqual(self.reload(self.c2).assets, initial_assets2 + 1)
        self.assertEqual(self.reload(self.c3).assets, initial_assets3 + 1)

    def test_mdc_CCIB_line_positive_effects(self):
        """
		Test what happens to voters of the CCIB party line when it is chosen
		"""

        self.set_turn_line(MDCVoteOrder.CCIB, MDCVoteOrder.CCIB,
                           MDCVoteOrder.TRAN)
        self.g.resolve_current_turn()

        dso = DataStealOrder(
            stealer_corporation=self.c2,
            player=self.p,
            target_corporation=self.c,
            additional_percents=5,
        )
        dso.save()

        # 20% malus
        self.assertEqual(
            dso.get_raw_probability(),
            dso.additional_percents * 10 + dso.BASE_SUCCESS_PROBABILITY - 20)

        # Other have no bonus
        dso2 = DataStealOrder(
            stealer_corporation=self.c,
            player=self.p,
            target_corporation=self.c3,
            additional_percents=5,
        )
        dso2.save()

        self.assertEqual(
            dso2.get_raw_probability(),
            dso2.additional_percents * 10 + dso2.BASE_SUCCESS_PROBABILITY)

    def test_mdc_CCIB_line_negative_effects(self):
        """
		Test what happens when the CCIB party line is chosen to players who voted for transparency
		"""

        self.set_turn_line(MDCVoteOrder.CCIB, MDCVoteOrder.CCIB,
                           MDCVoteOrder.TRAN)
        self.g.resolve_current_turn()

        # Player 3 has voted transparency, so he shouldn't be able to have a protection run
        po = ProtectionOrder(
            player=self.p3,
            protected_corporation=self.c,
            defense=ProtectionOrder.SABOTAGE,
        )
        self.assertRaises(OrderNotAvailable, po.clean)

        # Player 1 still can
        po2 = ProtectionOrder(
            player=self.p,
            protected_corporation=self.c,
            defense=ProtectionOrder.SABOTAGE,
        )
        po2.clean()

    def test_mdc_TRAN_line_effects(self):
        """
		Test what happens when the TRAN party line is chosen
		"""

        self.set_turn_line(MDCVoteOrder.CCIB, MDCVoteOrder.TRAN,
                           MDCVoteOrder.TRAN)
        self.g.resolve_current_turn()

        dso = DataStealOrder(
            stealer_corporation=self.c2,
            player=self.p,
            target_corporation=self.c,
            additional_percents=5,
        )
        dso.save()

        # 20% bonus
        self.assertEqual(
            dso.get_raw_probability(),
            dso.additional_percents * 10 + dso.BASE_SUCCESS_PROBABILITY - 20)

        dso2 = DataStealOrder(
            stealer_corporation=self.c2,
            player=self.p2,
            target_corporation=self.c,
            additional_percents=5,
        )
        dso2.save()

        # 20% malus
        self.assertEqual(
            dso2.get_raw_probability(),
            dso2.additional_percents * 10 + dso2.BASE_SUCCESS_PROBABILITY + 20)

    def test_mdc_BANK_line_positive_effect(self):
        """
		Test what happens when BANK party line is chosen to people who voted it
		"""

        self.set_turn_line(MDCVoteOrder.BANK, MDCVoteOrder.BANK,
                           MDCVoteOrder.DERE)
        self.c.update_assets(10)
        self.g.resolve_current_turn()

        # should fail, because c is first rank
        o = CorporationSpeculationOrder(player=self.p,
                                        corporation=self.c2,
                                        rank=1,
                                        investment=5)
        o.save()
        o.resolve()

        self.assertEqual(o.on_win_ratio, 2)  # Default
        self.assertEqual(o.on_loss_ratio, 0)  # 1 - 1
        self.assertEqual(self.reload(self.p).money, self.initial_money)

    def test_mdc_BANK_line_negative_effect(self):
        """
		Test what happens when BANK party line is chosen to people who voted deregulation
		"""

        self.set_turn_line(MDCVoteOrder.BANK, MDCVoteOrder.BANK,
                           MDCVoteOrder.DERE)
        self.g.resolve_current_turn()

        # Player 3 has voted DERE, so he shouldn't be able to speculate
        o = CorporationSpeculationOrder(player=self.p3,
                                        corporation=self.c3,
                                        rank=1,
                                        investment=1)
        self.assertRaises(OrderNotAvailable, o.clean)

        # Check that player 1 still can
        o2 = CorporationSpeculationOrder(player=self.p,
                                         corporation=self.c3,
                                         rank=1,
                                         investment=1)
        o2.clean()

    def test_mdc_DERE_line_positive_effect(self):
        """
		Test what happens when the DERE party line is chosen for players who voted for it
		"""

        self.set_turn_line(MDCVoteOrder.BANK, MDCVoteOrder.DERE,
                           MDCVoteOrder.DERE)
        self.g.resolve_current_turn()

        o = CorporationSpeculationOrder(player=self.p2,
                                        corporation=self.c,
                                        rank=1,
                                        investment=5)
        o.save()

        o.resolve()
        self.assertEqual(o.on_win_ratio, 3)  # 2 + 1
        self.assertEqual(o.on_loss_ratio, 1)  # Default
        self.assertEqual(
            self.reload(self.p2).money, self.initial_money + o.investment * 3)

    def test_mdc_DERE_line_negative_effect(self):
        """
		Test what happens when the DERE party line is chosen for detractors
		"""

        self.set_turn_line(MDCVoteOrder.BANK, MDCVoteOrder.DERE,
                           MDCVoteOrder.DERE)
        self.g.resolve_current_turn()

        # Player 1 has voted BANK, so he shouldn't be able to speculate
        o = CorporationSpeculationOrder(player=self.p,
                                        corporation=self.c3,
                                        rank=1,
                                        investment=5)
        self.assertRaises(OrderNotAvailable, o.clean)

        # Check that player 3 still can
        o2 = CorporationSpeculationOrder(player=self.p3,
                                         corporation=self.c3,
                                         rank=1,
                                         investment=5)
        o2.clean()
コード例 #36
0
ファイル: test_orders.py プロジェクト: silky/corporate
class InformationRunOrderTest(RunOrdersTest):
	def setUp(self):
		super(InformationRunOrderTest, self).setUp()

		self.p2 = Player(game=self.g, secrets="Some nasty sfuff")
		self.p2.save()
		self.p2.citizenship.corporation = self.c
		self.p2.citizenship.save()

		from engine_modules.influence.models import BuyInfluenceOrder

		# Initial setup, create a resolution sheet we'll use later.
		o = BuyInfluenceOrder(
			player=self.p2
		)
		o.save()

		self.g.resolve_current_turn()

		self.io = InformationOrder(
			target=self.p2,
			player=self.p,
			additional_percents=0,
		)
		self.io.clean()
		self.io.save()

		self.set_to_zero(self.io.target.citizenship.corporation)

	def tearDown(self):
		self.set_to_original(self.io.target.citizenship.corporation)

	def test_information_success(self):
		"""
		Information yields players data
		"""
		self.io.additional_percents = 10
		self.io.save()
		# Save message
		p2_resolution_message = self.p2.message_set.get(flag=Message.RESOLUTION, turn=1).content
		p2_resolution_message_formatted = p2_resolution_message.replace('# ', '## ')

		self.g.resolve_current_turn()

		p_results = self.p.message_set.get(flag=Message.PRIVATE_MESSAGE).content

		self.assertIn("Tour 1", p_results)
		self.assertIn(self.p2.secrets, p_results)
		self.assertNotIn("Tour 2", p_results)  # Current turn not included

		self.assertIn(p2_resolution_message_formatted, p_results)

	def test_information_failure(self):
		"""
		Failed information should not give information
		"""
		self.io.hidden_percents -= 10
		self.io.save()
		self.g.resolve_current_turn()

		self.assertRaises(Message.DoesNotExist, lambda: self.p.message_set.get(flag=Message.PRIVATE_MESSAGE))