Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
class DefensiveRunOrderTest(EngineTestCase):
	def setUp(self):
		super(DefensiveRunOrderTest, self).setUp()

		corporationmarket = self.c.get_random_corporation_market()
		self.dso = ProtectionOrder(
			player=self.p,
			protected_corporation_market=corporationmarket,
		)
		self.dso.clean()
		self.dso.save()

		self.so = SabotageOrder(
			player=self.p,
			target_corporation_market=corporationmarket,
			additional_percents=10,
		)
		self.so.clean()
		self.so.save()

	def test_protection_stops_runs(self):
		# this test's only purpose is to test that the run is stopped when it has 100% chance of success and protection drops it to 0%
		# these parameters are defined in engine/testcases.py
		begin_assets = self.c2.assets
		self.g.resolve_current_turn()
		self.assertEqual(self.reload(self.c2).assets, begin_assets)
Exemplo n.º 3
0
    def test_get_protection_values(self):
        """
		Protection values should include Protection runs.
		"""
        dso = DataStealOrder(
            stealer_corporation=self.c2,
            player=self.p,
            target_corporation=self.c,
            additional_percents=7,
        )
        dso.save()

        self.assertEqual(dso.get_protection_values(),
                         [dso.target_corporation.base_corporation.datasteal])

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

        self.assertEqual(dso.get_protection_values(), [
            po.get_success_probability(),
            dso.target_corporation.base_corporation.datasteal
        ])
Exemplo n.º 4
0
	def test_protected_corporation_property(self):
		"""
		protected_corporation must return the right corporation
		"""

		po = ProtectionOrder(
			player=self.p,
			protected_corporation_market=self.c.get_random_corporation_market(),
		)
		po.save()

		self.assertEqual(po.protected_corporation, self.c)
Exemplo n.º 5
0
	def test_protection_run_task(self):
		"""
		Check the task solves the run
		"""
		po = ProtectionOrder(
			player=self.p,
			protected_corporation=self.c,
			defense=ProtectionOrder.SABOTAGE,
		)
		po.clean()
		po.save()
		po.additional_percents = 10
		po.save()

		self.g.resolve_current_turn()
		self.assertEqual(self.reload(self.p).money, self.INITIAL_MONEY - po.get_cost())
Exemplo n.º 6
0
    def test_has_base_value(self):
        """
		Protection has defaut protection values
		"""

        po = ProtectionOrder(
            player=self.p,
            protected_corporation=self.c,
            defense=ProtectionOrder.DATASTEAL,
            additional_percents=1,
        )
        po.save()

        self.assertEqual(
            po.get_success_probability(), po.additional_percents * 10 +
            po.BASE_SUCCESS_PROBABILITY[po.defense])
Exemplo n.º 7
0
    def test_protection_run_task(self):
        """
		Check the task solves the run
		"""
        po = ProtectionOrder(
            player=self.p,
            protected_corporation=self.c,
            defense=ProtectionOrder.SABOTAGE,
        )
        po.clean()
        po.save()
        po.additional_percents = 10
        po.save()

        self.g.resolve_current_turn()
        self.assertEqual(
            self.reload(self.p).money, self.INITIAL_MONEY - po.get_cost())
Exemplo n.º 8
0
	def test_sabotage_interception(self):
		"""
		Intercepted sabotage does not change corporation assets
		"""
		begin_assets = self.so.target_corporation.assets

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

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

		self.so.resolve()
		self.assertEqual(self.reload(self.so.target_corporation).assets, begin_assets)
Exemplo n.º 9
0
	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)
Exemplo n.º 10
0
    def test_sabotage_interception(self):
        """
		Intercepted sabotage does not change corporation assets
		"""
        begin_assets = self.so.target_corporation.assets

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

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

        self.so.resolve()
        self.assertEqual(
            self.reload(self.so.target_corporation).assets, begin_assets)
Exemplo n.º 11
0
	def test_datasteal_interception(self):
		"""
		Intercepted datasteal should not change corporation assets.
		"""
		begin_assets_stealer = self.dso.stealer_corporation.assets

		po = ProtectionOrder(
			player=self.p,
			protected_corporation_market=self.dso.target_corporation_market,
		)
		po.clean()
		po.save()

		po.additional_percents = 10
		po.save()

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

		self.dso.resolve()
		self.assertEqual(self.reload(self.dso.stealer_corporation).assets, begin_assets_stealer)
Exemplo n.º 12
0
    def test_datasteal_interception(self):
        """
		Intercepted datasteal should not change corporation assets.
		"""
        begin_assets_stealer = self.dso.stealer_corporation.assets

        po = ProtectionOrder(player=self.p,
                             protected_corporation=self.c,
                             defense=ProtectionOrder.DATASTEAL)
        po.clean()
        po.save()

        po.additional_percents = 10
        po.save()

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

        self.dso.resolve()
        self.assertEqual(
            self.reload(self.dso.stealer_corporation).assets,
            begin_assets_stealer)
Exemplo n.º 13
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)