Esempio n. 1
0
File: webapp.py Progetto: heckj/om
def current_gamestate():
    gs = GameState()
    return jsonify(state=gs.state_dict())
Esempio n. 2
0
File: webapp.py Progetto: heckj/om
def current_state_planets():
    gs = GameState()
    planet_list = json.dumps(gs.planet_list())
    resp = Response(planet_list, 200, mimetype='application/json')
    return resp
Esempio n. 3
0
 def setUp(self):
     self.gamestate = GameState()
     self.gamestate.reset()
Esempio n. 4
0
File: webapp.py Progetto: heckj/om
def testview(name=None):
    gs = GameState()
    context = {'name': name,
               'state': gs.state_list()}
    return render_template('test.html', **context)
Esempio n. 5
0
class TestGameState(unittest.TestCase):
    def setUp(self):
        self.gamestate = GameState()
        self.gamestate.reset()

    def test_get_ship(self):
        self.assertIsNone(self.gamestate.get_ship(None))

        self.assertEqual(len(self.gamestate.actors), 0)
        ship_ref = self.gamestate.create_ship()
        another_ref = self.gamestate.get_ship(ship_ref.uuid)
        self.assertEqual(ship_ref, another_ref)

    def test_create_ship(self):
        self.assertEqual(len(self.gamestate.actors), 0)
        ship_ref = self.gamestate.create_ship()
        self.assertIsNotNone(ship_ref)
        self.assertEqual(len(self.gamestate.actors), 1)

    def test_clear(self):
        self.assertEqual(len(self.gamestate.actors), 0)
        self.gamestate.create_ship()
        self.assertEqual(len(self.gamestate.actors), 1)
        self.gamestate.reset()
        self.assertEqual(len(self.gamestate.actors), 0)

    def test_add_actor(self):
        thing1 = gameobjects.ActiveObject()
        thing2 = gameobjects.ActiveObject()
        self.gamestate._add_actor(thing1)
        self.gamestate._add_actor(thing2)
        self.assertEqual(len(self.gamestate.actors), 2)

    def test_save_and_load(self):
        thing1 = gameobjects.ActiveObject()
        thing2 = gameobjects.ActiveObject()
        self.gamestate._add_actor(thing1)
        self.gamestate._add_actor(thing2)

        self.gamestate.save_state('test_data')
        self.gamestate.load_state('test_data')
        self.assertEqual(len(self.gamestate.actors), 2)
        os.unlink('test_data')

    def test_load_sample(self):
        self.gamestate.load_state('sample_data.json')
        self.assertEqual(len(self.gamestate.actors), 2)
        self.assertIn('abc123', self.gamestate.actors)
        self.assertIn('xyz879', self.gamestate.actors)
        self.assertEqual(len(self.gamestate.planets), 4)

    def test_list_planets(self):
        self.gamestate.load_state('sample_data.json')
        self.assertEqual(len(self.gamestate.planets), 4)
        planet_list = self.gamestate.planet_list()
        self.assertIsNotNone(planet_list)
        self.assertEquals(len(planet_list), 4)