Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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
Example #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)
Example #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
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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()
Example #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)
Example #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)
Example #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()
Example #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)
Example #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()
Example #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)
Example #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)
Example #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))
Example #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))
Example #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)