예제 #1
0
    def setUp(self):
        super(ExtractionRunOrderTest, self).setUp()

        self.eo = ExtractionOrder(player=self.p,
                                  target_corporation=self.c,
                                  kidnapper_corporation=self.c2)
        self.eo.clean()
        self.eo.save()

        self.set_to_zero(self.eo.target_corporation)
예제 #2
0
    def setUp(self):
        super(SignalsTest, self).setUp()

        # We disable the test that stop you from start more than one run on the same target
        self.g.allow_several_runs_on_one_target = True

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

        self.dso = DataStealOrder(
            player=self.p, target_corporation_market=common_corporation_market, stealer_corporation=self.c2
        )
        self.dso.save()

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

        self.eo = ExtractionOrder(
            player=self.p, target_corporation_market=common_corporation_market, stealer_corporation=self.c2
        )
        self.eo.save()

        self.so = SabotageOrder(
            player=self.p, target_corporation_market=common_corporation_market, additional_percents=0
        )
        self.so.clean()
        self.so.save()

        self.po = ProtectionOrder(
            player=self.p, protected_corporation_market=self.eo.target_corporation_market, hidden_percents=10
        )
        self.po.clean()
        self.po.save()
예제 #3
0
	def test_offensive_resolve_order(self):
		"""
		Check that offensive runs are resolved in order of raw_probability
		And that only the first one has been resolved on the same market
		"""

		# We don't want the setUp order to interfere :
		self.so.delete()

		# We find a common corporationmarket on c with a market shared by c,c2 and c3
		c2_markets = self.c2.markets
		c3_markets = self.c3.markets
		common_corporation_markets = [cm for cm in self.c.corporation_markets if cm.market in c2_markets and cm.market in c3_markets]
		common_corporation_market = common_corporation_markets[0]

		assets_c_before = self.c.assets
		assets_c3_before = self.c3.assets
		assets_c2_before = self.c2.assets

		# We order an extraction run for c2 and c3 on this market
		so2 = ExtractionOrder(
			player=self.p,
			target_corporation_market=common_corporation_market,
			stealer_corporation=self.c2,
			additional_percents=4,
		)

		so2.clean()
		so2.save()
		
		so3 = ExtractionOrder(
			player=self.p,
			target_corporation_market=common_corporation_market,
			stealer_corporation=self.c3,
			additional_percents=8,
		)

		so3.clean()
		so3.save()
		
		self.g.resolve_current_turn()

		self.assertEqual(self.reload(self.c).assets, assets_c_before - 1)  # SabotageOrder of the setUp succeeded + 1 ExtractionOrder succeeded
		self.assertEqual(self.reload(self.c2).assets, assets_c3_before)  # ExtractionOrder failed
		self.assertEqual(self.reload(self.c3).assets, assets_c2_before + 1)  # ExtractionOrder succeeded
예제 #4
0
    def test_extraction_target_stealer_different(self):
        """
		Target and stealer must be different for Extraction.
		"""

        self.dso = ExtractionOrder(player=self.p,
                                   target_corporation=self.c,
                                   kidnapper_corporation=self.c)

        self.assertRaises(ValidationError, self.dso.clean)
예제 #5
0
	def setUp(self):
		super(ExtractionRunOrderTest, self).setUp()

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

		self.eo = ExtractionOrder(
			player=self.p,
			target_corporation_market=common_corporation_market,
			stealer_corporation=self.c2
		)
		self.eo.clean()
		self.eo.save()
예제 #6
0
class SignalsTest(EngineTestCase):
    def setUp(self):
        super(SignalsTest, self).setUp()

        # We disable the test that stop you from start more than one run on the same target
        self.g.allow_several_runs_on_one_target = True

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

        self.dso = DataStealOrder(
            player=self.p, target_corporation_market=common_corporation_market, stealer_corporation=self.c2
        )
        self.dso.save()

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

        self.eo = ExtractionOrder(
            player=self.p, target_corporation_market=common_corporation_market, stealer_corporation=self.c2
        )
        self.eo.save()

        self.so = SabotageOrder(
            player=self.p, target_corporation_market=common_corporation_market, additional_percents=0
        )
        self.so.clean()
        self.so.save()

        self.po = ProtectionOrder(
            player=self.p, protected_corporation_market=self.eo.target_corporation_market, hidden_percents=10
        )
        self.po.clean()
        self.po.save()

    def get_unique_market_for_corporation(self, corporation):
        return corporation.corporationmarket_set.get(
            market__name=corporation.base_corporation.markets.keys()[-1], turn=self.g.current_turn
        )

    def test_datasteal_target_stealer_different(self):
        """
		Target and stealer must be different for Datasteal.
		"""
        self.dso.stealer_corporation = self.c
        self.assertRaises(OrderNotAvailable, self.dso.clean)

    def test_extraction_target_stealer_different(self):
        """
		Target and stealer must be different for Extraction.
		"""
        self.eo.stealer_corporation = self.c
        self.assertRaises(OrderNotAvailable, self.eo.clean)

    def test_datasteal_unavailable_market_for_stealer(self):
        """
		Datasteal should not be able to target a corporation that doesn't
		have assets in the target market
		"""
        self.dso.target_corporation_market = self.get_unique_market_for_corporation(self.c)

        self.assertRaises(ValidationError, self.dso.clean)

    def test_datasteal_unavailable_market_for_target(self):
        """
		Datasteal should not be able to target a corporation that doesn't
		have assets in the target market
		"""
        self.dso.target_corporation_market = self.get_unique_market_for_corporation(self.c2)

        self.assertRaises(ValidationError, self.dso.clean)

    def test_extraction_unavailable_market(self):
        """
		Extraction should not be able to target a corporation that doesn't
		have assets in the target market
		"""
        self.eo.target_corporation_market = self.get_unique_market_for_corporation(self.c)

        self.assertRaises(ValidationError, self.eo.clean)

    def test_datasteal_stealer_above_target(self):
        """
		A datasteal cannot be launched against a corporation that is
		(strictly) below the stealer on the target market
		"""

        self.dso.target_corporation_market.value = 0
        self.dso.target_corporation_market.save()

        self.assertRaises(ValidationError, self.dso.clean)

    def test_extraction_stealer_above_target(self):
        """
		An extraction cannot be launched against a corporation that is
		(strictly) below the stealer on the target market
		"""

        self.eo.target_corporation_market.value = 0
        self.eo.target_corporation_market.save()

        self.assertRaises(ValidationError, self.eo.clean)

    def test_datasteal_negative_market(self):
        """
		Target market must have positive assets
		"""
        target_corporation_market = self.dso.target_corporation_market
        target_corporation_market.value = -1
        target_corporation_market.save()
        # Stealer must have market assets lower than target
        stealer_corporation_market = self.dso.stealer_corporation.corporationmarket_set.get(
            market=target_corporation_market.market, turn=self.g.current_turn
        )
        stealer_corporation_market.value = -2
        stealer_corporation_market.save()
        self.assertRaises(OrderNotAvailable, self.dso.clean)

    def test_extraction_negative_market(self):
        """
		Target market must have positive assets
		"""
        target_corporation_market = self.eo.target_corporation_market
        target_corporation_market.value = -1
        target_corporation_market.save()
        # Stealer must have market assets lower than target
        stealer_corporation_market = self.eo.stealer_corporation.corporationmarket_set.get(
            market=target_corporation_market.market, turn=self.g.current_turn
        )
        stealer_corporation_market.value = -2
        stealer_corporation_market.save()
        self.assertRaises(OrderNotAvailable, self.eo.clean)

    def test_sabotage_negative_market(self):
        """
		Target market must have positive assets
		"""
        target_corporation_market = self.so.target_corporation_market
        target_corporation_market.value = -1
        target_corporation_market.save()
        self.assertRaises(OrderNotAvailable, self.so.clean)

    def test_protection_negative_market(self):
        """
		Target market must have positive assets
		"""
        target_corporation_market = self.po.protected_corporation_market
        target_corporation_market.value = -1
        target_corporation_market.save()
        self.assertRaises(OrderNotAvailable, self.po.clean)

    def test_several_run_on_same_target_fail(self):
        """
		Only one run is allowed by target. allow_several_runs_on_one_target is set on True on the test_models.py of corporation_run
		We used this variable because there are a lot of randoms corporations in the targets for testing
		"""
        self.p.game.allow_several_runs_on_one_target = False

        common_corporation_market = self.c.get_common_corporation_market(self.c2)
        self.so2 = SabotageOrder(
            player=self.p, target_corporation_market=common_corporation_market, additional_percents=0
        )
        self.so2.save()
        self.assertRaises(OrderNotAvailable, self.po.clean)
예제 #7
0
class ExtractionRunOrderTest(RunOrdersTest):
    def setUp(self):
        super(ExtractionRunOrderTest, self).setUp()

        self.eo = ExtractionOrder(player=self.p,
                                  target_corporation=self.c,
                                  kidnapper_corporation=self.c2)
        self.eo.clean()
        self.eo.save()

        self.set_to_zero(self.eo.target_corporation)

    def tearDown(self):
        self.set_to_original(self.eo.target_corporation)

    def test_extraction_success(self):
        """
		Extraction doesn't benefit anyone, but costs the sabotaged 2 assets
		"""
        begin_assets_target = self.eo.target_corporation.assets
        begin_assets_kidnapper = self.eo.kidnapper_corporation.assets

        self.eo.additional_percents = 10
        self.eo.save()

        self.eo.resolve()
        self.assertEqual(
            self.reload(self.eo.target_corporation).assets,
            begin_assets_target - 1)
        self.assertEqual(
            self.reload(self.eo.kidnapper_corporation).assets,
            begin_assets_kidnapper + 1)

    def test_extraction_failure(self):
        """
		Failed extraction does not change corporation assets
		"""
        begin_assets_target = self.eo.target_corporation.assets
        begin_assets_kidnapper = self.eo.kidnapper_corporation.assets

        self.eo.additional_percents = 0
        self.eo.hidden_percents = -10
        self.eo.save()

        self.eo.resolve()
        self.assertEqual(
            self.reload(self.eo.target_corporation).assets,
            begin_assets_target)
        self.assertEqual(
            self.reload(self.eo.kidnapper_corporation).assets,
            begin_assets_kidnapper)

    def test_extraction_interception(self):
        """
		Intercepted extraction does not change corporation assets
		"""
        begin_assets_target = self.eo.target_corporation.assets
        begin_assets_kidnapper = self.eo.kidnapper_corporation.assets

        po = ProtectionOrder(
            player=self.p,
            protected_corporation=self.c,
            defense=ProtectionOrder.EXTRACTION,
            hidden_percents=10,
        )
        po.save()

        self.eo.additional_percents = 10
        self.eo.save()

        self.eo.resolve()
        self.assertEqual(
            self.reload(self.eo.target_corporation).assets,
            begin_assets_target)
        self.assertEqual(
            self.reload(self.eo.kidnapper_corporation).assets,
            begin_assets_kidnapper)
예제 #8
0
class ExtractionRunOrderTest(EngineTestCase):
	def setUp(self):
		super(ExtractionRunOrderTest, self).setUp()

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

		self.eo = ExtractionOrder(
			player=self.p,
			target_corporation_market=common_corporation_market,
			stealer_corporation=self.c2
		)
		self.eo.clean()
		self.eo.save()

	def test_extraction_success(self):
		"""
		Extraction benefits the stealer 1 asset and costs the stolen 1
		"""
		begin_assets_target = self.eo.target_corporation.assets
		begin_assets_kidnapper = self.eo.stealer_corporation.assets

		self.eo.additional_percents = 10
		self.eo.save()

		self.eo.resolve()

		self.assertEqual(self.reload(self.eo.target_corporation).assets, begin_assets_target - 1)
		self.assertEqual(self.reload(self.eo.stealer_corporation).assets, begin_assets_kidnapper + 1)

	def test_extraction_failure(self):
		"""
		Failed extraction does not change corporation assets
		"""
		begin_assets_target = self.eo.target_corporation.assets
		begin_assets_kidnapper = self.eo.stealer_corporation.assets

		self.eo.additional_percents = 0
		self.eo.hidden_percents = -10
		self.eo.save()

		self.eo.resolve()
		self.assertEqual(self.reload(self.eo.target_corporation).assets, begin_assets_target)
		self.assertEqual(self.reload(self.eo.stealer_corporation).assets, begin_assets_kidnapper)

	@override_max_protection
	def test_extraction_interception(self):
		"""
		Intercepted extraction does not change corporation assets
		"""
		begin_assets_target = self.eo.target_corporation.assets
		begin_assets_kidnapper = self.eo.stealer_corporation.assets

		po = ProtectionOrder(
			player=self.p,
			protected_corporation_market=self.eo.target_corporation_market,
			hidden_percents=10,
		)
		po.save()

		self.eo.additional_percents = 10
		self.eo.save()

		self.eo.resolve()
		self.assertEqual(self.reload(self.eo.target_corporation).assets, begin_assets_target)
		self.assertEqual(self.reload(self.eo.stealer_corporation).assets, begin_assets_kidnapper)