示例#1
0
    def test_region_autocapital(self):
        """A region that's a capital is automatically owned by the same team"""
        cap = Region.capital_for(0, self.sess)
        self.assertEqual(cap.capital, cap.owner)

        cap = Region.capital_for(1, self.sess)
        self.assertEqual(cap.capital, cap.owner)
示例#2
0
    def test_region_autocapital(self):
        """A region that's a capital is automatically owned by the same team"""
        cap = Region.capital_for(0, self.sess)
        self.assertEqual(cap.capital, cap.owner)

        cap = Region.capital_for(1, self.sess)
        self.assertEqual(cap.capital, cap.owner)
示例#3
0
    def setUp(self):
        logging.basicConfig(level=logging.DEBUG)
        self.conf = MockConf(dbstring="sqlite://")
        self.db = DB(self.conf)
        self.db.create_all()
        self.sess = self.db.session()
        Region.create_from_json(self.sess, TEST_LANDS)

        # Create some users
        self.alice = self.create_user("alice", 0)
        self.bob = self.create_user("bob", 1)
示例#4
0
    def setUp(self):
        logging.basicConfig(level=logging.DEBUG)
        self.conf = MockConf(dbstring="sqlite://")
        self.db = DB(self.conf)
        self.db.create_all()
        self.sess = self.db.session()
        Region.create_from_json(self.sess, TEST_LANDS)

        # Create some users
        self.alice = self.create_user("alice", 0)
        self.bob = self.create_user("bob", 1)
示例#5
0
    def test_stop_cancels_movement(self):
        """Stopping movement should actually, you know, stop movement"""

        sess = self.sess
        cap = Region.capital_for(0, sess)
        # Move Alice somewhere else
        londo = self.get_region("Orange Londo")
        self.alice.move(100, londo, 0)

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

        # Bloodless coup of Sapphire
        sapp = self.get_region("Sapphire")
        sapp.owner = self.alice.team
        sess.commit()

        # Start wandering that way
        order = self.alice.move(100, sapp, 60 * 60 * 24)
        self.assert_(order)

        orders = self.sess.query(MarchingOrder).count()
        self.assertEqual(orders, 1)

        self.alice.cancel_movement()
        self.assertEqual(self.alice.region, londo)

        orders = self.sess.query(MarchingOrder).count()
        self.assertEqual(orders, 0)
示例#6
0
    def test_extract_cancels_movement(self):
        """Emergency movement shouldn't rubberband"""
        sess = self.sess
        cap = Region.capital_for(0, sess)
        # Move Alice somewhere else
        londo = self.get_region("Orange Londo")
        self.alice.move(100, londo, 0)

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

        # Bloodless coup of Sapphire
        sapp = self.get_region("Sapphire")
        sapp.owner = self.alice.team
        sess.commit()

        # Start wandering that way
        order = self.alice.move(100, sapp, 60 * 60 * 24)
        self.assert_(order)

        orders = self.sess.query(MarchingOrder).count()
        self.assertEqual(orders, 1)

        self.alice.extract()
        self.assertEqual(self.alice.region, cap)

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

        # Make sure she ended up in a sector
        self.assertTrue(self.alice.sector)
示例#7
0
    def test_extract_cancels_movement(self):
        """Emergency movement shouldn't rubberband"""
        sess = self.sess
        cap = Region.capital_for(0, sess)
        # Move Alice somewhere else
        londo = self.get_region("Orange Londo")
        self.alice.move(100, londo, 0)

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

        # Bloodless coup of Sapphire
        sapp = self.get_region("Sapphire")
        sapp.owner = self.alice.team
        sess.commit()

        # Start wandering that way
        order = self.alice.move(100, sapp, 60 * 60 * 24)
        self.assert_(order)

        orders = self.sess.query(MarchingOrder).count()
        self.assertEqual(orders, 1)

        self.alice.extract()
        self.assertEqual(self.alice.region, cap)

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

        # Make sure she ended up in a sector
        self.assertTrue(self.alice.sector)
示例#8
0
 def create_user(self, name, team):
     newbie = User(name=name, team=team, loyalists=100, leader=True)
     self.sess.add(newbie)
     cap = Region.capital_for(team, self.sess)
     newbie.region = cap
     self.sess.commit()
     return newbie
示例#9
0
    def test_stop_cancels_movement(self):
        """Stopping movement should actually, you know, stop movement"""

        sess = self.sess
        cap = Region.capital_for(0, sess)
        # Move Alice somewhere else
        londo = self.get_region("Orange Londo")
        self.alice.move(100, londo, 0)

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

        # Bloodless coup of Sapphire
        sapp = self.get_region("Sapphire")
        sapp.owner = self.alice.team
        sess.commit()

        # Start wandering that way
        order = self.alice.move(100, sapp, 60 * 60 * 24)
        self.assert_(order)

        orders = self.sess.query(MarchingOrder).count()
        self.assertEqual(orders, 1)

        self.alice.cancel_movement()
        self.assertEqual(self.alice.region, londo)

        orders = self.sess.query(MarchingOrder).count()
        self.assertEqual(orders, 0)
示例#10
0
 def create_user(self, name, team):
     newbie = User(name=name, team=team, loyalists=100, leader=True)
     self.sess.add(newbie)
     cap = Region.capital_for(team, self.sess)
     newbie.region = cap
     self.sess.commit()
     return newbie
示例#11
0
    def test_sector_movement(self):
        self.conf["game"]["num_sectors"] = 7
        sess = self.sess
        cap = Region.capital_for(0, sess)
        self.assertEqual(self.alice.region.id, cap.id)
        londo = self.get_region("Orange Londo")
        self.assertIsNotNone(londo)

        self.alice.move(100, londo, 0, sector=3, conf=self.conf)
示例#12
0
    def test_sector_movement(self):
        self.conf["game"]["num_sectors"] = 7
        sess = self.sess
        cap = Region.capital_for(0, sess)
        self.assertEqual(self.alice.region.id, cap.id)
        londo = self.get_region("Orange Londo")
        self.assertIsNotNone(londo)

        self.alice.move(100, londo, 0, sector=3, conf=self.conf)
示例#13
0
def main():
    c = Config()
    reddit = c.praw()

    dbconn = DB(c)
    
    sess = dbconn.session()
    
    source = sys.argv[1]
    regions = Region.patch_from_json(sess, json_file=source, verbose=True)
示例#14
0
def main():
    c = Config()
    reddit = c.praw()

    dbconn = DB(c)

    sess = dbconn.session()

    source = sys.argv[1]
    regions = Region.patch_from_json(sess, json_file=source, verbose=True)
示例#15
0
    def test_patch_alias(self):
        """Should be able to patch in a new alias"""
        NEW_LANDS = """
[
    {
        "name": "Periopolis",
        "aliases": ["periperi"],
        "connections": []
    }
]
"""
        peri = self.sess.query(Region).filter_by(name="periopolis").first()
        self.assertIsNotNone(peri)
        periperi = self.get_region("periperi")
        self.assertIsNone(periperi)

        Region.patch_from_json(self.sess, NEW_LANDS)
        periperi = self.get_region("periperi")
        self.assertIsNotNone(periperi)

        self.assertEqual(peri, periperi)
示例#16
0
    def test_patch_alias(self):
        """Should be able to patch in a new alias"""
        NEW_LANDS = """
[
    {
        "name": "Periopolis",
        "aliases": ["periperi"],
        "connections": []
    }
]
"""
        peri = self.sess.query(Region).filter_by(name="periopolis").first()
        self.assertIsNotNone(peri)
        periperi = self.get_region("periperi")
        self.assertIsNone(periperi)

        Region.patch_from_json(self.sess, NEW_LANDS)
        periperi = self.get_region("periperi")
        self.assertIsNotNone(periperi)

        self.assertEqual(peri, periperi)
示例#17
0
    def test_movement(self):
        """Move Alice from the Orangered capital to an adjacent region"""
        sess = self.sess
        cap = Region.capital_for(0, sess)
        # First of all, make sure alice is actually there
        self.assertEqual(self.alice.region.id, cap.id)

        londo = self.get_region("Orange Londo")
        self.assertIsNotNone(londo)

        self.alice.move(100, londo, 0)

        # Now she should be there
        self.assertEqual(self.alice.region.id, londo.id)
示例#18
0
    def test_movement(self):
        """Move Alice from the Orangered capital to an adjacent region"""
        sess = self.sess
        cap = Region.capital_for(0, sess)
        # First of all, make sure alice is actually there
        self.assertEqual(self.alice.region.id, cap.id)

        londo = self.get_region("Orange Londo")
        self.assertIsNotNone(londo)

        self.alice.move(100, londo, 0)

        # Now she should be there
        self.assertEqual(self.alice.region.id, londo.id)
示例#19
0
def main():
    c = Config()
    reddit = c.praw()

    dbconn = DB(c)
    dbconn.drop_all()
    dbconn.create_all()
    
    sess = dbconn.session()
    
    source = sys.argv[1]
    regions = Region.create_from_json(sess, json_file=source)
    
    stamp()
示例#20
0
    def test_extract(self):
        """Emergency movement back to capital"""
        sess = self.sess
        cap = Region.capital_for(0, sess)
        # Move Alice somewhere else
        londo = self.get_region("Orange Londo")
        self.alice.move(100, londo, 0)

        # Should be in londo
        self.assertEqual(self.alice.region, londo)
        # Emergency move!
        self.alice.extract()

        # Should be back in capital
        self.assertEqual(self.alice.region, cap)
示例#21
0
    def test_extract(self):
        """Emergency movement back to capital"""
        sess = self.sess
        cap = Region.capital_for(0, sess)
        # Move Alice somewhere else
        londo = self.get_region("Orange Londo")
        self.alice.move(100, londo, 0)

        # Should be in londo
        self.assertEqual(self.alice.region, londo)
        # Emergency move!
        self.alice.extract()

        # Should be back in capital
        self.assertEqual(self.alice.region, cap)
示例#22
0
def main():
    c = Config()
    reddit = c.praw()

    dbconn = DB(c)
    dbconn.drop_all()
    dbconn.create_all()

    sess = dbconn.session()

    source = sys.argv[1]
    regions = Region.create_from_json(sess, json_file=source)

    # Create team DB entries
    TeamInfo.create_defaults(sess, c)

    stamp()
示例#23
0
    def test_default_sector_movement(self):
        self.conf["game"]["num_sectors"] = 7

        # Alice should be in sector 0 by default
        self.assertEqual(self.alice.sector, 0)

        sess = self.sess
        cap = Region.capital_for(0, sess)
        self.assertEqual(self.alice.region.id, cap.id)
        londo = self.get_region("Orange Londo")
        self.assertIsNotNone(londo)

        # This seed means that it'll pick 5.  I deliberately chose a seed that
        # would result in itself.
        random.seed(5)
        self.alice.move(100, londo, 0, conf=self.conf)

        self.assertEqual(self.alice.sector, 5)
示例#24
0
def main():
    full = "sqlite:///%s" % realpath(sys.argv[1])
    print full
    engine = create_engine(full)
    sessionfactory = sessionmaker(bind=engine)

    session = sessionfactory()

    with open(sys.argv[2], 'r') as f:
        text = f.read()
        print text
        j = json.loads(text)
        for user in j:
            u = User(**user)
            u.region = Region.capital_for(u.team, session)
            session.add(u)
            print "Imported %s" % u.name
        session.commit()
示例#25
0
    def test_default_sector_movement(self):
        self.conf["game"]["num_sectors"] = 7

        # Alice should be in sector 0 by default
        self.assertEqual(self.alice.sector, 0)

        sess = self.sess
        cap = Region.capital_for(0, sess)
        self.assertEqual(self.alice.region.id, cap.id)
        londo = self.get_region("Orange Londo")
        self.assertIsNotNone(londo)

        # This seed means that it'll pick 5.  I deliberately chose a seed that
        # would result in itself.
        random.seed(5)
        self.alice.move(100, londo, 0, conf=self.conf)

        self.assertEqual(self.alice.sector, 5)
示例#26
0
    def test_patch_add(self):
        """Should be able to patch in a new region"""
        NEW_LANDS = """
[
    {
        "name": "Periopolis",
        "srname": "ct_periopolis",
            "connections": ["Sapphire"],
        "capital": 1
    },
    {
        "name": "Sapphire",
        "srname": "ct_sapphire",
        "connections": ["Orange Londo"]
    },
    {
        "name": "Orange Londo",
        "srname": "ct_orangelondo",
        "connections": ["Oraistedarg", "flooland"],
        "owner": 0
    },
    {
        "name": "Oraistedarg",
        "srname": "ct_oraistedarg",
        "connections": [],
        "capital": 0
    },
    {
        "name": "flooland",
        "srname": "ct_flooland",
        "connections": []
    }
]
"""
        self.assert_(self.get_region("sapphire"))

        # doesn't already exist
        region = self.get_region('flooland')
        self.assertFalse(region)

        londo = self.get_region("Orange Londo")
        self.assertEqual(len(londo.borders), 2)  # ora and sapph

        Region.patch_from_json(self.sess, NEW_LANDS)

        # Should exist now
        region = self.get_region('flooland')
        self.assert_(region)
        self.assertEqual(len(region.borders), 1)

        # Should connect to londo
        self.assertEqual(region.borders[0], londo)
        self.assertEqual(len(londo.borders), 3)

        # Now there are 5 regions
        regnum = self.sess.query(Region).count()
        self.assertEqual(regnum, 5)

        # Meanwhile, periopolis is unchanged
        peri = self.get_region('Periopolis')
        self.assertEqual(len(peri.borders), 1)
示例#27
0
    def get_region(self, name, as_who=None):
        if not as_who:
            as_who = self.alice

        return Region.get_region(name, self.context(player=as_who))
示例#28
0
    def get_region(self, name, as_who=None):
        if not as_who:
            as_who = self.alice

        return Region.get_region(name, self.context(player=as_who))
示例#29
0
    def test_patch_add(self):
        """Should be able to patch in a new region"""
        NEW_LANDS = """
[
    {
        "name": "Periopolis",
        "srname": "ct_periopolis",
            "connections": ["Sapphire"],
        "capital": 1
    },
    {
        "name": "Sapphire",
        "srname": "ct_sapphire",
        "connections": ["Orange Londo"]
    },
    {
        "name": "Orange Londo",
        "srname": "ct_orangelondo",
        "connections": ["Oraistedarg", "flooland"],
        "owner": 0
    },
    {
        "name": "Oraistedarg",
        "srname": "ct_oraistedarg",
        "connections": [],
        "capital": 0
    },
    {
        "name": "flooland",
        "srname": "ct_flooland",
        "connections": []
    }
]
"""
        self.assert_(self.get_region("sapphire"))

        # doesn't already exist
        region = self.get_region('flooland')
        self.assertFalse(region)

        londo = self.get_region("Orange Londo")
        self.assertEqual(len(londo.borders), 2)  # ora and sapph

        Region.patch_from_json(self.sess, NEW_LANDS)

        # Should exist now
        region = self.get_region('flooland')
        self.assert_(region)
        self.assertEqual(len(region.borders), 1)

        # Should connect to londo
        self.assertEqual(region.borders[0], londo)
        self.assertEqual(len(londo.borders), 3)

        # Now there are 5 regions
        regnum = self.sess.query(Region).count()
        self.assertEqual(regnum, 5)

        # Meanwhile, periopolis is unchanged
        peri = self.get_region('Periopolis')
        self.assertEqual(len(peri.borders), 1)