Example #1
0
    def test_cavalry_step2_fail(self):
        area1 = Area(id="A1", iso='UK', unit='cav')
        area2 = Area(id="A3", iso='UK')

        with self.assertRaises(MoveException) as context:
            movement.move_to(area1, area2)
        self.assertEqual(context.exception.reason, 'cant_move_there')
        self.assertEqual(area1.unit, 'cav')
        self.assertEqual(area2.unit, None)
Example #2
0
    def test_occupied_fail(self):
        area1 = Area(id="A1", iso='UK', unit='cav')
        area2 = Area(id="A2", iso='UK', unit='inf')

        with self.assertRaises(MoveException) as context:
            movement.move_to(area1, area2)
        self.assertEqual(context.exception.reason, 'not_enemy')
        self.assertEqual(area1.unit, 'cav')
        self.assertEqual(area2.unit, 'inf')
Example #3
0
    def test_nounit_fail(self):
        area1 = Area(id="A1", iso='UK')
        area2 = Area(id="A2", iso='FR')

        with self.assertRaises(MoveException) as context:
            movement.move_to(area1, area2)
        self.assertEqual(context.exception.reason, 'invalid_params')
        self.assertIsNone(area1.unit)
        self.assertIsNone(area2.unit)
Example #4
0
    def test_mount_exhaust_pass(self):
        area1 = Area(id="A1", iso='UK', unit='inf')
        area2 = Area(id="A2", iso='UK', tile='mount')

        try:
            movement.move_to(area1, area2)
        except MoveException as e:
            self.fail("test_mount_exhaust_pass raised MoveException({}) unexpectedly!".format(e.reason))

        self.assertEqual(area2.exhaust, 3)
Example #5
0
    def test_inf_attack2_fail(self):
        area1 = Area(id="A1", iso='UK', unit='inf')
        area2 = Area(id="A3", iso='FR', unit='cav')

        with self.assertRaises(MoveException) as context:
            movement.move_to(area1, area2)
        self.assertEqual(context.exception.reason, 'cant_attack_there')
        self.assertEqual(area1.unit, 'inf')
        self.assertEqual(area2.unit, 'cav')
        self.assertEqual(area2.iso, 'FR')
Example #6
0
    def test_move_pass(self):
        area1 = Area(id="A1", iso='UK', unit='inf')
        area2 = Area(id="A2", iso='FR')

        try:
            movement.move_to(area1, area2)
        except MoveException as e:
            self.fail("test_move_pass raised MoveException({}) unexpectedly!".format(e.reason))

        self.assertEqual(area1.unit, None)
        self.assertEqual(area1.iso, 'UK')

        self.assertEqual(area2.unit, 'inf')
        self.assertEqual(area2.iso, 'UK')
Example #7
0
    def move(self, area_id, to_id, user: User):
        error, world, country, area1 = self._accessControl(user, area_id)
        if error: return error

        area2: Area = areas.get(to_id, user.wid)
        is_kill = bool(area2.unit)

        try:
            is_conquer = movement.move_to(area1, area2, world.map)
        except movement.MoveException as e:
            return {"err": e.reason}

        if not world.has_moved:
            world.has_moved = True
            worlds.save(world)

        areas.save(area1)
        areas.save(area2)

        self.server.send_to_world(
            user.wid, {
                "route": self.name + ":move",
                "iso": user.iso,
                "area_id": area_id,
                "to_id": to_id,
                "events": {
                    "conquer": is_conquer,
                    "kill": is_kill
                }
            })
Example #8
0
    def test_cavalry_forest_fail(self):
        area1 = Area(id="A1", iso='UK', unit='cav')
        area2 = Area(id="A2", iso='FR', unit='inf', tile='forest')

        with self.assertRaises(MoveException) as context:
            movement.move_to(area1, area2)
        self.assertEqual(context.exception.reason, 'cant_attack_cavalry')
        self.assertEqual(area1.unit, 'cav')
        self.assertEqual(area2.unit, 'inf')
        self.assertEqual(area2.iso, 'FR')

        # infantry can, however
        area3 = Area(id="A3", iso='UK', unit='inf')
        try:
            movement.move_to(area3, area2)
        except MoveException as e:
            self.fail("test_cavalry_forest_fail raised MoveException({}) unexpectedly!".format(e.reason))
        self.assertEqual(area3.unit, None)
        self.assertEqual(area2.unit, 'inf')
        self.assertEqual(area2.iso, 'UK')