Пример #1
0
    def test_situation_changes_neutral_ok(self):
        """Can end up somewhere neutral if we allow it"""
        self.conf["game"]["traversable_neutrals"] = True
        started = self.alice.region
        londo = self.get_region("Orange Londo")
        # For testing purposes, londo is now alice's
        londo.owner = self.alice.team

        order = self.alice.move(100, londo, 60 * 60 * 24, conf=self.conf)[0]
        n = self.sess.query(db.MarchingOrder).count()
        self.assertEqual(n, 1)

        # What makes a man turn neutral?
        londo.owner = None

        # Push back arrival time
        order.arrival = now()
        self.sess.commit()

        # Invoke the update routine to set everyone's location
        arrived = MarchingOrder.update_all(self.sess, conf=self.conf)
        self.assert_(arrived)

        # Now we're there!
        self.assertEqual(londo, self.alice.region)

        # Shouldn't be any marching orders left
        orders = self.sess.query(MarchingOrder).count()
        self.assertEqual(orders, 0)
Пример #2
0
    def test_situation_changes_neutral(self):
        """Can't move somewhere that becomes neutral while you're moving"""
        started = self.alice.region
        londo = self.get_region("Orange Londo")
        # For testing purposes, londo is now alice's
        londo.owner = self.alice.team

        order = self.alice.move(100, londo, 60 * 60 * 24)[0]
        n = self.sess.query(db.MarchingOrder).count()
        self.assertEqual(n, 1)

        # What makes a man turn neutral?
        londo.owner = None

        # Push back arrival time
        order.arrival = now()
        self.sess.commit()

        # Invoke the update routine to set everyone's location
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Alice should be back where she started, as she can't be in londo
        self.assertEqual(started, self.alice.region)

        n = self.sess.query(db.MarchingOrder).count()
        self.assertEqual(n, 0)
Пример #3
0
    def test_situation_changes_neutral_ok(self):
        """Can end up somewhere neutral if we allow it"""
        self.conf["game"]["traversable_neutrals"] = True
        started = self.alice.region
        londo = self.get_region("Orange Londo")
        # For testing purposes, londo is now alice's
        londo.owner = self.alice.team

        order = self.alice.move(100, londo, 60 * 60 * 24, conf=self.conf)[0]
        n = self.sess.query(db.MarchingOrder).count()
        self.assertEqual(n, 1)

        # What makes a man turn neutral?
        londo.owner = None

        # Push back arrival time
        order.arrival = now()
        self.sess.commit()

        # Invoke the update routine to set everyone's location
        arrived = MarchingOrder.update_all(self.sess, conf=self.conf)
        self.assert_(arrived)

        # Now we're there!
        self.assertEqual(londo, self.alice.region)

        # Shouldn't be any marching orders left
        orders = self.sess.query(MarchingOrder).count()
        self.assertEqual(orders, 0)
Пример #4
0
    def test_got_moved(self):
        """Make sure you can't finish moving if you're warped"""
        started = self.alice.region
        londo = self.get_region("Orange Londo")
        # For testing purposes, londo is now alice's
        londo.owner = self.alice.team

        # But she's at the fight
        self.alice.region = self.get_region('sapphire')

        order = self.alice.move(100, londo, 60 * 60 * 24)[0]
        n = self.sess.query(db.MarchingOrder).count()
        self.assertEqual(n, 1)

        # The sapphire battle ends poorly for alice's team, and she gets
        # booted out
        self.alice.region = self.get_region('oraistedarg')

        # Invoke the update routine to set everyone's location
        order.arrival = now()
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Alice should be back where she started, as the move isn't valid
        self.assertEqual(started, self.alice.region)

        n = self.sess.query(db.MarchingOrder).count()
        self.assertEqual(n, 0)
Пример #5
0
    def test_situation_changes_neutral(self):
        """Can't move somewhere that becomes neutral while you're moving"""
        started = self.alice.region
        londo = self.get_region("Orange Londo")
        # For testing purposes, londo is now alice's
        londo.owner = self.alice.team

        order = self.alice.move(100, londo, 60 * 60 * 24)[0]
        n = self.sess.query(db.MarchingOrder).count()
        self.assertEqual(n, 1)

        # What makes a man turn neutral?
        londo.owner = None

        # Push back arrival time
        order.arrival = now()
        self.sess.commit()

        # Invoke the update routine to set everyone's location
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Alice should be back where she started, as she can't be in londo
        self.assertEqual(started, self.alice.region)

        n = self.sess.query(db.MarchingOrder).count()
        self.assertEqual(n, 0)
Пример #6
0
    def test_delayed_sector_movement(self):
        self.conf["game"]["num_sectors"] = 7
        londo = self.get_region("Orange Londo")

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        DAY = 60 * 60 * 24
        then = now()  # We'll need this to check timing

        self.alice.move(100, londo, DAY, sector=2, conf=self.conf)

        movements = self.sess.query(MarchingOrder).all()
        self.assertEqual(len(movements), 1)
        first = movements[0]
        self.assertEqual(first.source, self.get_region('Oraistedarg'))
        self.assertEqual(first.dest, self.get_region('Orange Londo'))
        self.assertEqual(first.dest_sector, 2)
        # Note, if self.alice.move takes longer than 10 minutes to run, this
        # will fail.
        self.assertAlmostEqual(first.arrival, then + DAY, delta=600)

        # Tired of waiting!
        first.arrival = now()
        self.sess.commit()
        self.assert_(first.has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should be in londo
        self.assertEqual(londo, self.alice.region)

        # And in sector 2
        self.assertEqual(self.alice.sector, 2)
Пример #7
0
    def test_got_moved(self):
        """Make sure you can't finish moving if you're warped"""
        started = self.alice.region
        londo = self.get_region("Orange Londo")
        # For testing purposes, londo is now alice's
        londo.owner = self.alice.team

        # But she's at the fight
        self.alice.region = self.get_region('sapphire')

        order = self.alice.move(100, londo, 60 * 60 * 24)[0]
        n = self.sess.query(db.MarchingOrder).count()
        self.assertEqual(n, 1)

        # The sapphire battle ends poorly for alice's team, and she gets
        # booted out
        self.alice.region = self.get_region('oraistedarg')

        # Invoke the update routine to set everyone's location
        order.arrival = now()
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Alice should be back where she started, as the move isn't valid
        self.assertEqual(started, self.alice.region)

        n = self.sess.query(db.MarchingOrder).count()
        self.assertEqual(n, 0)
Пример #8
0
    def test_delayed_sector_movement(self):
        self.conf["game"]["num_sectors"] = 7
        londo = self.get_region("Orange Londo")

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        DAY = 60 * 60 * 24
        then = now()  # We'll need this to check timing

        self.alice.move(100, londo, DAY, sector=2, conf=self.conf)

        movements = self.sess.query(MarchingOrder).all()
        self.assertEqual(len(movements), 1)
        first = movements[0]
        self.assertEqual(first.source, self.get_region('Oraistedarg'))
        self.assertEqual(first.dest, self.get_region('Orange Londo'))
        self.assertEqual(first.dest_sector, 2)
        # Note, if self.alice.move takes longer than 10 minutes to run, this
        # will fail.
        self.assertAlmostEqual(first.arrival, then + DAY, delta=600)

        # Tired of waiting!
        first.arrival = now()
        self.sess.commit()
        self.assert_(first.has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should be in londo
        self.assertEqual(londo, self.alice.region)

        # And in sector 2
        self.assertEqual(self.alice.sector, 2)
Пример #9
0
    def test_movement_multiplier(self):
        """Some lands are harder to enter/leave"""
        home = self.alice.region
        londo = self.get_region("Orange Londo")
        londo.travel_multiplier = 2
        self.sess.commit()

        DAY = 60 * 60 * 24

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        then = now()
        order = self.alice.move(100, londo, DAY)[0]
        self.assert_(order)

        # But because the travel multiplier's 2, that should take twice
        # as long
        self.assertAlmostEqual(order.arrival, then + DAY + DAY, delta=600)

        # Tired of waiting
        order.arrival = now()
        self.sess.commit()
        self.assert_(order.has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should be in londo
        self.assertEqual(order.dest, londo)
        self.assertEqual(order.dest, self.alice.region)

        # We're bored and want to go home
        then = now()
        order = self.alice.move(100, home, DAY)[0]

        self.assert_(order)

        # But because the travel multiplier's 2, that should ALSO take twice
        # as long
        self.assertAlmostEqual(order.arrival, then + DAY + DAY, delta=600)
Пример #10
0
    def test_movement_multiplier(self):
        """Some lands are harder to enter/leave"""
        home = self.alice.region
        londo = self.get_region("Orange Londo")
        londo.travel_multiplier = 2
        self.sess.commit()

        DAY = 60 * 60 * 24

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        then = now()
        order = self.alice.move(100, londo, DAY)[0]
        self.assert_(order)

        # But because the travel multiplier's 2, that should take twice
        # as long
        self.assertAlmostEqual(order.arrival, then + DAY + DAY, delta=600)

        # Tired of waiting
        order.arrival = now()
        self.sess.commit()
        self.assert_(order.has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should be in londo
        self.assertEqual(order.dest, londo)
        self.assertEqual(order.dest, self.alice.region)

        # We're bored and want to go home
        then = now()
        order = self.alice.move(100, home, DAY)[0]

        self.assert_(order)

        # But because the travel multiplier's 2, that should ALSO take twice
        # as long
        self.assertAlmostEqual(order.arrival, then + DAY + DAY, delta=600)
Пример #11
0
    def test_movement_multiplier_does_not_affect_intrasector(self):
        DAY = 60 * 60 * 24
        self.conf["game"]["num_sectors"] = 7
        self.conf["game"]["intrasector_travel"] = DAY / 2
        home = self.alice.region
        self.assertEqual(home, self.get_region('Oraistedarg'))
        home.travel_multiplier = 2
        self.sess.commit()

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        then = now()  # We'll need this to check timing

        self.alice.move(100, home, DAY, sector=7, conf=self.conf)

        movements = self.sess.query(MarchingOrder).all()
        self.assertEqual(len(movements), 1)
        first = movements[0]
        self.assertEqual(first.source, home)
        self.assertEqual(first.dest, home)
        self.assertEqual(first.dest_sector, 7)

        # Unaffected by travel multiplier
        self.assertAlmostEqual(first.arrival, then + DAY / 2, delta=600)

        # Tired of waiting!
        first.arrival = now()
        self.sess.commit()
        self.assert_(first.has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should still be home
        self.assertEqual(home, self.alice.region)

        # But in sector 7
        self.assertEqual(self.alice.sector, 7)
Пример #12
0
    def test_movement_multiplier_does_not_affect_intrasector(self):
        DAY = 60 * 60 * 24
        self.conf["game"]["num_sectors"] = 7
        self.conf["game"]["intrasector_travel"] = DAY / 2
        home = self.alice.region
        self.assertEqual(home, self.get_region('Oraistedarg'))
        home.travel_multiplier = 2
        self.sess.commit()

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        then = now()  # We'll need this to check timing

        self.alice.move(100, home, DAY, sector=7, conf=self.conf)

        movements = self.sess.query(MarchingOrder).all()
        self.assertEqual(len(movements), 1)
        first = movements[0]
        self.assertEqual(first.source, home)
        self.assertEqual(first.dest, home)
        self.assertEqual(first.dest_sector, 7)

        # Unaffected by travel multiplier
        self.assertAlmostEqual(first.arrival, then + DAY / 2, delta=600)

        # Tired of waiting!
        first.arrival = now()
        self.sess.commit()
        self.assert_(first.has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should still be home
        self.assertEqual(home, self.alice.region)

        # But in sector 7
        self.assertEqual(self.alice.sector, 7)
Пример #13
0
    def test_delayed_movement(self):
        """Most movement should take a while"""
        home = self.alice.region
        londo = self.get_region("Orange Londo")

        # Everything's fine
        self.assertFalse(self.alice.is_moving())

        # Ideally, this test will not take a day to complete
        order = self.alice.move(100, londo, 60 * 60 * 24)[0]
        self.assert_(order)

        # Alice should be moving
        self.assert_(self.alice.is_moving())

        # For record-keeping purposes, she's in her source city
        self.assertEqual(home, self.alice.region)

        # Well, we don't want to wait an entire day, so let's cheat and push
        # back the arrival time
        order.arrival = time.mktime(time.localtime())
        self.sess.commit()
        self.assert_(order.has_arrived())

        # But we're not actually there yet
        self.assertEqual(home, self.alice.region)

        # Invoke the update routine to set everyone's location
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Now we're there!
        self.assertEqual(londo, self.alice.region)

        # Shouldn't be any marching orders left
        orders = self.sess.query(MarchingOrder).count()
        self.assertEqual(orders, 0)
Пример #14
0
    def test_delayed_movement(self):
        """Most movement should take a while"""
        home = self.alice.region
        londo = self.get_region("Orange Londo")

        # Everything's fine
        self.assertFalse(self.alice.is_moving())

        # Ideally, this test will not take a day to complete
        order = self.alice.move(100, londo, 60 * 60 * 24)[0]
        self.assert_(order)

        # Alice should be moving
        self.assert_(self.alice.is_moving())

        # For record-keeping purposes, she's in her source city
        self.assertEqual(home, self.alice.region)

        # Well, we don't want to wait an entire day, so let's cheat and push
        # back the arrival time
        order.arrival = time.mktime(time.localtime())
        self.sess.commit()
        self.assert_(order.has_arrived())

        # But we're not actually there yet
        self.assertEqual(home, self.alice.region)

        # Invoke the update routine to set everyone's location
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Now we're there!
        self.assertEqual(londo, self.alice.region)

        # Shouldn't be any marching orders left
        orders = self.sess.query(MarchingOrder).count()
        self.assertEqual(orders, 0)
Пример #15
0
    def test_delayed_intrasector_movement(self):
        DAY = 60 * 60 * 24
        self.conf["game"]["num_sectors"] = 7
        self.conf["game"]["intrasector_travel"] = DAY / 2
        home = self.alice.region

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        DAY = 60 * 60 * 24
        then = now()  # We'll need this to check timing

        self.alice.move(100, home, DAY, sector=7, conf=self.conf)

        movements = self.sess.query(MarchingOrder).all()
        self.assertEqual(len(movements), 1)
        first = movements[0]
        self.assertEqual(first.source, self.get_region('Oraistedarg'))
        self.assertEqual(first.dest, self.get_region('Oraistedarg'))
        self.assertEqual(first.dest_sector, 7)
        # Note, if self.alice.move takes longer than 10 minutes to run, this
        # will fail.
        self.assertAlmostEqual(first.arrival, then + DAY / 2, delta=600)

        # Tired of waiting!
        first.arrival = now()
        self.sess.commit()
        self.assert_(first.has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should still be home
        self.assertEqual(home, self.alice.region)

        # But in sector 7
        self.assertEqual(self.alice.sector, 7)
Пример #16
0
    def test_delayed_intrasector_movement(self):
        DAY = 60 * 60 * 24
        self.conf["game"]["num_sectors"] = 7
        self.conf["game"]["intrasector_travel"] = DAY / 2
        home = self.alice.region

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        DAY = 60 * 60 * 24
        then = now()  # We'll need this to check timing

        self.alice.move(100, home, DAY, sector=7, conf=self.conf)

        movements = self.sess.query(MarchingOrder).all()
        self.assertEqual(len(movements), 1)
        first = movements[0]
        self.assertEqual(first.source, self.get_region('Oraistedarg'))
        self.assertEqual(first.dest, self.get_region('Oraistedarg'))
        self.assertEqual(first.dest_sector, 7)
        # Note, if self.alice.move takes longer than 10 minutes to run, this
        # will fail.
        self.assertAlmostEqual(first.arrival, then + DAY / 2, delta=600)

        # Tired of waiting!
        first.arrival = now()
        self.sess.commit()
        self.assert_(first.has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should still be home
        self.assertEqual(home, self.alice.region)

        # But in sector 7
        self.assertEqual(self.alice.sector, 7)
Пример #17
0
    def test_multimove_situation_changes(self):
        """Can't multimove somewhere that's changed hands"""
        sapp = self.get_region("Sapphire")
        sapp.owner = self.alice.team
        self.sess.commit()

        DAY = 60 * 60 * 24

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        path = [self.get_region(name) for name in ('Orange Londo', 'Sapphire')]
        then = now()  # We'll need this to check timing
        self.alice.move(100, path, DAY)

        movements = self.sess.query(MarchingOrder).all()
        self.assertEqual(len(movements), 2)
        # The first should be to londo
        londomove = movements[0]
        self.assertEqual(londomove.source, self.get_region('Oraistedarg'))
        self.assertEqual(londomove.dest, self.get_region('Orange Londo'))
        # Note, if self.alice.move takes longer than 10 minutes to run, this
        # will fail.
        self.assertAlmostEqual(londomove.arrival, then + DAY, delta=600)

        # Next, sapphire
        sappmove = movements[1]
        self.assertEqual(sappmove.source, self.get_region('Orange Londo'))
        self.assertEqual(sappmove.dest, self.get_region('Sapphire'))
        # Should arrive 2 days from now, +/- 5 minutes
        self.assertAlmostEqual(sappmove.arrival, then + DAY + DAY, delta=600)

        n = (self.sess.query(db.MarchingOrder).
            filter_by(leader=self.alice)).count()
        self.assertEqual(n, 2)

        # Sapphire falls to the enemy!
        sappmove.dest.owner = self.bob.team
        self.sess.commit()

        # Tired of waiting
        movements[0].arrival = now()
        self.sess.commit()
        self.assert_(movements[0].has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should be in londo
        self.assertEqual(londomove.dest, self.alice.region)

        # One order left
        n = (self.sess.query(db.MarchingOrder).
            filter_by(leader=self.alice)).count()
        self.assertEqual(n, 1)

        movements[1].arrival = now()
        self.sess.commit()
        self.assert_(movements[1].has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # But we fail to arrive because this movement's no longer valid.
        self.assertEqual(londomove.dest, self.alice.region)

        # Done moving
        n = (self.sess.query(db.MarchingOrder).
            filter_by(leader=self.alice)).count()
        self.assertEqual(n, 0)
Пример #18
0
    def test_multimove(self):
        """Should be able to more more than one hop.
        (with corresponding increase in times)"""
        sapp = self.get_region("Sapphire")
        sapp.owner = self.alice.team
        self.sess.commit()

        DAY = 60 * 60 * 24

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        path = [self.get_region(name) for name in ('Orange Londo', 'Sapphire')]
        then = now()  # We'll need this to check timing
        self.alice.move(100, path, DAY)

        movements = self.sess.query(MarchingOrder).all()
        self.assertEqual(len(movements), 2)
        # The first should be to londo
        londomove = movements[0]
        self.assertEqual(londomove.source, self.get_region('Oraistedarg'))
        self.assertEqual(londomove.dest, self.get_region('Orange Londo'))
        # Note, if self.alice.move takes longer than 10 minutes to run, this
        # will fail.
        self.assertAlmostEqual(londomove.arrival, then + DAY, delta=600)

        # Next, sapphire
        sappmove = movements[1]
        self.assertEqual(sappmove.source, self.get_region('Orange Londo'))
        self.assertEqual(sappmove.dest, self.get_region('Sapphire'))
        # Should arrive 2 days from now, +/- 5 minutes
        self.assertAlmostEqual(sappmove.arrival, then + DAY + DAY, delta=600)

        n = (self.sess.query(db.MarchingOrder).
            filter_by(leader=self.alice)).count()
        self.assertEqual(n, 2)

        # Tired of waiting
        movements[0].arrival = now()
        self.sess.commit()
        self.assert_(movements[0].has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should be in londo
        self.assertEqual(londomove.dest, self.alice.region)

        # One order left
        n = (self.sess.query(db.MarchingOrder).
            filter_by(leader=self.alice)).count()
        self.assertEqual(n, 1)

        movements[1].arrival = now()
        self.sess.commit()
        self.assert_(movements[1].has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # And now in sapphire
        self.assertEqual(sappmove.dest, self.alice.region)

        # Done moving
        n = (self.sess.query(db.MarchingOrder).
            filter_by(leader=self.alice)).count()
        self.assertEqual(n, 0)
Пример #19
0
    def test_multimove(self):
        """Should be able to more more than one hop.
        (with corresponding increase in times)"""
        sapp = self.get_region("Sapphire")
        sapp.owner = self.alice.team
        self.sess.commit()

        DAY = 60 * 60 * 24

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        path = [self.get_region(name) for name in ('Orange Londo', 'Sapphire')]
        then = now()  # We'll need this to check timing
        self.alice.move(100, path, DAY)

        movements = self.sess.query(MarchingOrder).all()
        self.assertEqual(len(movements), 2)
        # The first should be to londo
        londomove = movements[0]
        self.assertEqual(londomove.source, self.get_region('Oraistedarg'))
        self.assertEqual(londomove.dest, self.get_region('Orange Londo'))
        # Note, if self.alice.move takes longer than 10 minutes to run, this
        # will fail.
        self.assertAlmostEqual(londomove.arrival, then + DAY, delta=600)

        # Next, sapphire
        sappmove = movements[1]
        self.assertEqual(sappmove.source, self.get_region('Orange Londo'))
        self.assertEqual(sappmove.dest, self.get_region('Sapphire'))
        # Should arrive 2 days from now, +/- 5 minutes
        self.assertAlmostEqual(sappmove.arrival, then + DAY + DAY, delta=600)

        n = (self.sess.query(
            db.MarchingOrder).filter_by(leader=self.alice)).count()
        self.assertEqual(n, 2)

        # Tired of waiting
        movements[0].arrival = now()
        self.sess.commit()
        self.assert_(movements[0].has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should be in londo
        self.assertEqual(londomove.dest, self.alice.region)

        # One order left
        n = (self.sess.query(
            db.MarchingOrder).filter_by(leader=self.alice)).count()
        self.assertEqual(n, 1)

        movements[1].arrival = now()
        self.sess.commit()
        self.assert_(movements[1].has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # And now in sapphire
        self.assertEqual(sappmove.dest, self.alice.region)

        # Done moving
        n = (self.sess.query(
            db.MarchingOrder).filter_by(leader=self.alice)).count()
        self.assertEqual(n, 0)
Пример #20
0
    def test_multimove_situation_changes(self):
        """Can't multimove somewhere that's changed hands"""
        sapp = self.get_region("Sapphire")
        sapp.owner = self.alice.team
        self.sess.commit()

        DAY = 60 * 60 * 24

        movements = self.sess.query(MarchingOrder).count()
        self.assertEqual(movements, 0)

        path = [self.get_region(name) for name in ('Orange Londo', 'Sapphire')]
        then = now()  # We'll need this to check timing
        self.alice.move(100, path, DAY)

        movements = self.sess.query(MarchingOrder).all()
        self.assertEqual(len(movements), 2)
        # The first should be to londo
        londomove = movements[0]
        self.assertEqual(londomove.source, self.get_region('Oraistedarg'))
        self.assertEqual(londomove.dest, self.get_region('Orange Londo'))
        # Note, if self.alice.move takes longer than 10 minutes to run, this
        # will fail.
        self.assertAlmostEqual(londomove.arrival, then + DAY, delta=600)

        # Next, sapphire
        sappmove = movements[1]
        self.assertEqual(sappmove.source, self.get_region('Orange Londo'))
        self.assertEqual(sappmove.dest, self.get_region('Sapphire'))
        # Should arrive 2 days from now, +/- 5 minutes
        self.assertAlmostEqual(sappmove.arrival, then + DAY + DAY, delta=600)

        n = (self.sess.query(
            db.MarchingOrder).filter_by(leader=self.alice)).count()
        self.assertEqual(n, 2)

        # Sapphire falls to the enemy!
        sappmove.dest.owner = self.bob.team
        self.sess.commit()

        # Tired of waiting
        movements[0].arrival = now()
        self.sess.commit()
        self.assert_(movements[0].has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # Should be in londo
        self.assertEqual(londomove.dest, self.alice.region)

        # One order left
        n = (self.sess.query(
            db.MarchingOrder).filter_by(leader=self.alice)).count()
        self.assertEqual(n, 1)

        movements[1].arrival = now()
        self.sess.commit()
        self.assert_(movements[1].has_arrived())
        arrived = MarchingOrder.update_all(self.sess)
        self.assert_(arrived)

        # But we fail to arrive because this movement's no longer valid.
        self.assertEqual(londomove.dest, self.alice.region)

        # Done moving
        n = (self.sess.query(
            db.MarchingOrder).filter_by(leader=self.alice)).count()
        self.assertEqual(n, 0)