コード例 #1
0
ファイル: test_signals.py プロジェクト: Neamar/corporate
	def test_one_vote(self):
		"""
		Can't vote more than once
		"""
		v = DIncVoteOrder(
			player=self.p,
		)
		v.clean()
		v.save()

		v2 = DIncVoteOrder(
			player=self.p,
		)
		self.assertRaises(OrderNotAvailable, v2.clean)
コード例 #2
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)
コード例 #3
0
ファイル: test_models.py プロジェクト: Neamar/corporate
class ModelsTest(EngineTestCase):
	def setUp(self):
		super(ModelsTest, self).setUp()

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

	def test_player_get_last_dinc_vote(self):
		"""
		get_last_dinc_vote should return vote order
		"""

		self.assertIsNone(self.p.get_last_dinc_vote())
		self.g.resolve_current_turn()
		self.assertEqual(self.v, self.p.get_last_dinc_vote())

	def test_player_get_last_dinc_coalition(self):
		"""
		get_last_dinc_coalition should return coalition
		"""
		self.assertIsNone(self.p.get_last_dinc_coalition())
		self.g.resolve_current_turn()
		self.assertEqual(self.v.coalition, self.p.get_last_dinc_coalition())

	def test_game_get_dinc_coalition(self):
		"""
		get_dinc_coalition should return coalition from specified turn
		"""
		self.g.resolve_current_turn()
		self.g.resolve_current_turn()
		self.assertIsNone(self.g.get_dinc_coalition())
		self.assertEqual(self.g.get_dinc_coalition(turn=self.g.current_turn - 1), self.v.coalition)
コード例 #4
0
ファイル: test_dinc_lines.py プロジェクト: Neamar/corporate
    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()
コード例 #5
0
ファイル: test_orders.py プロジェクト: Neamar/corporate
class OrdersTest(EngineTestCase):
	def setUp(self):
		super(OrdersTest, self).setUp()

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

	def test_not_top_holder(self):
		"""
		Test that your vote counts for 1 when you're not top holder
		"""
		self.assertEqual(self.v.get_weight(), 1)
		self.assertEqual(self.v.get_friendly_corporations(), [])

	def test_one_top_holder(self):
		"""
		Test that a top holder's vote is correctly weighed
		"""
		s = Share(
			corporation=self.c,
			player=self.p,
			turn=self.g.current_turn
		)
		s.save()

		self.assertEqual(self.v.get_weight(), 2)
		self.assertEqual(self.v.get_friendly_corporations(), [self.c])

	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)

	def test_top_holder_two_corporations(self):
		"""
		Test when a player is the top holder in two corporations
		"""
		s = Share(
			corporation=self.c,
			player=self.p,
		)
		s.save()

		s2 = Share(
			corporation=self.c2,
			player=self.p,
		)
		s2.save()

		self.assertEqual(self.v.get_weight(), 3)
		self.assertItemsEqual(self.v.get_friendly_corporations(), [self.c, self.c2])

	def test_dinc_coalition(self):
		"""
		Check party line is returned correctly
		"""
		self.assertIsNone(self.g.get_dinc_coalition())

		self.g.resolve_current_turn()

		self.assertEqual(self.g.get_dinc_coalition(), self.v.coalition)

	def test_get_last_mdv_vote(self):
		"""
		Check player last vote is returned correctly
		"""
		self.assertIsNone(self.p.get_last_dinc_coalition())

		self.g.resolve_current_turn()

		self.assertEqual(self.p.get_last_dinc_coalition(), self.v.coalition)

	def test_get_form_forbids_none_value(self):
		self.v.delete()

		instance = DIncVoteOrder(player=self.p)

		form = instance.get_form({'coalition': DIncVoteOrder.CPUB, 'player': self.p})
		self.assertTrue(form.is_valid())

		form = instance.get_form({'coalition': None, 'player': self.p})
		self.assertFalse(form.is_valid())