def test_get_player_summary(self, mock_method):
     from lobbypy.models import Player
     instance = Player('0')
     mock_method.return_value = {}
     rv = instance._get_player_summary()
     mock_method.assert_called_once_with('0')
     self.assertEqual(rv, {})
示例#2
0
 def test_on_set_class(self, magic_make, magic_item_make, magic_broadcast):
     instance = self._makeOne()
     o = Player('')
     l = self._makeLobby(owner=o)
     t = Team('Red')
     l.teams.append(t)
     p = Player('0')
     t.join(p)
     db.session.add(o)
     db.session.add(l)
     db.session.add(t)
     db.session.add(p)
     db.session.commit()
     instance.lobby_id = l.id
     instance.ctx.g.player = p
     instance.allowed_methods = set([
         'on_leave', 'recv_connect', 'on_set_team', 'on_set_class',
         'on_toggle_ready'
     ])
     instance.on_set_class(0)
     self.assertEqual(
         instance.allowed_methods,
         set([
             'on_leave', 'recv_connect', 'on_set_class', 'on_toggle_ready',
             'on_set_team'
         ]))
     self.assertEqual(l.teams[0].players[0].class_id, 0)
 def test_not_can_join(self):
     instance = self._makeOne()
     from lobbypy.models import Player
     for i in range(9):
         p = Player('%d' % i)
         p.id = i
         instance.join(p)
     self.assertTrue(not instance.can_join())
 def test_not_can_join(self):
     instance = self._makeOne()
     from lobbypy.models import Player
     for i in range(9):
         p = Player('%d' % i)
         p.id = i
         instance.join(p)
     self.assertTrue(not instance.can_join())
示例#5
0
 def setUp(self):
     db.create_all()
     a = Player('')
     a.admin = True
     db.session.add(a)
     db.session.commit()
     self.admin = a
     with self.client.session_transaction() as sess:
         sess['user_id'] = a.id
 def test_not_can_set_class(self):
     instance = self._makeOne()
     from lobbypy.models import Player
     for i in range(9):
         p = Player('%d' % i)
         p.id = i
         instance.join(p)
         instance.players[-1].class_id = i
     for i in range(9):
         self.assertTrue(not instance.can_set_class(i))
 def test_not_can_set_class(self):
     instance = self._makeOne()
     from lobbypy.models import Player
     for i in range(9):
         p = Player('%d' % i)
         p.id = i
         instance.join(p)
         instance.players[-1].class_id = i
     for i in range(9):
         self.assertTrue(not instance.can_set_class(i))
示例#8
0
 def _makeLobby(self, name='test', owner=None, server_address='test',
         game_map='test', password='******', teams=lambda: []):
     from lobbypy.models import Lobby
     if owner is None:
         from lobbypy.models import Player
         owner = Player('')
     return Lobby(name, owner, server_address, game_map, password, teams)
示例#9
0
 def test_with_speced_lobbies(self):
     from lobbypy.models import Player, Lobby
     o = Player('1')
     p = Player('0')
     db.session.add(o)
     db.session.add(p)
     l = Lobby('test', o, 'test', 'test', 'test', teams=[])
     l.spectators.append(p)
     db.session.add(l)
     db.session.commit()
     rv = self._callFUT(p)
     l_dels = []
     for l_del in rv:
         l_dels.append(l_del)
     self.assertEqual(len(l_dels), 1)
     self.assertEqual(l_dels[0], (l, False))
 def test_len(self):
     instance = self._makeOne()
     from lobbypy.models import Player, LobbyPlayer
     p = Player('0')
     lp = LobbyPlayer(p)
     instance.players.append(lp)
     self.assertEqual(len(instance), 1)
 def test_leave(self):
     instance = self._makeOne()
     from lobbypy.models import Player
     p = Player('0')
     instance.spectators.append(p)
     instance.leave(p)
     self.assertEqual(len(instance.spectators), 0)
 def test_contains(self):
     instance = self._makeOne()
     from lobbypy.models import Player, LobbyPlayer
     p = Player('0')
     lp = LobbyPlayer(p)
     instance.players.append(lp)
     self.assertTrue(p in instance)
 def test_not_can_set_class(self):
     instance = self._makeOne()
     self.assertTrue(not instance.can_set_class(-1))
     self.assertTrue(not instance.can_set_class(2))
     from lobbypy.models import Player
     p1 = Player('0')
     p2 = Player('0')
     p1.id = 1
     p2.id = 2
     instance.join(p1)
     instance.join(p2)
     instance.players[0].class_id = 0
     instance.players[1].class_id = 0
     self.assertTrue(not instance.can_set_class(0))
     instance.players[0].class_id = 6
     self.assertTrue(not instance.can_set_class(6))
 def test_join(self):
     instance = self._makeOne()
     from lobbypy.models import Player
     p = Player('0')
     instance.join(p)
     self.assertEqual(len(instance.players), 1)
     self.assertEqual(instance.players[0].player, p)
示例#15
0
 def test_delete_player(self):
     p = Player('0')
     db.session.add(p)
     db.session.commit()
     resp = self.client.delete('/admin/rest/players/%d' % p.id)
     self.assertStatus(resp, 200)
     players = Player.query.filter_by(steam_id = '0').all()
     self.assertEqual(len(players), 0)
示例#16
0
def create_or_login(resp):
    match = _steam_id_re.search(resp.identity_url)
    g.player = Player.get_or_create(match.group(1))
    db.session.commit()
    session['user_id'] = g.player.id
    flash('You are logged in as %s' % g.player.steam_id)
    current_app.logger.info('Player: %d logged in' % g.player.id)
    return redirect(oid.get_next_url())
示例#17
0
def create_or_login(resp):
    match = _steam_id_re.search(resp.identity_url)
    g.player = Player.get_or_create(match.group(1))
    db.session.commit()
    session['user_id'] = g.player.id
    flash('You are logged in as %s' % g.player.steam_id)
    current_app.logger.info('Player: %d logged in' % g.player.id)
    return redirect(oid.get_next_url())
 def test_set_class(self):
     instance = self._makeOne()
     from lobbypy.models import Player, LobbyPlayer
     p = Player('0')
     lp = LobbyPlayer(p)
     instance.players.append(lp)
     instance.set_class(p, 1)
     self.assertEqual(instance.players[0].class_id, 1)
 def test_toggle_ready(self):
     instance = self._makeOne()
     from lobbypy.models import Player, LobbyPlayer
     p = Player('0')
     lp = LobbyPlayer(p)
     instance.players.append(lp)
     instance.toggle_ready(p)
     self.assertTrue(instance.players[0].ready)
示例#20
0
def add_admin(steam_id):
    config_app(app)
    from lobbypy.utils import db
    from lobbypy.models import Player
    player = Player.query.filter_by(steam_id=steam_id).first()
    if player:
        player.admin = True
    else:
        player = Player(steam_id)
        player.admin = True
    password = prompt_pass("Enter password for the Administrator")
    if password == prompt_pass("Re-enter password for the Administrator"):
        player.password = crypt(password)
        db.session.add(player)
        db.session.commit()
    else:
        print "Passwords do not match, re-run command"
示例#21
0
 def test_on_kick(self, magic_make, magic_item_make, magic_broadcast):
     instance = self._makeOne()
     o = Player('')
     l = self._makeLobby(owner=o)
     t = Team('Red')
     l.teams.append(t)
     p = Player('0')
     t.join(p)
     db.session.add(o)
     db.session.add(l)
     db.session.add(t)
     db.session.add(p)
     db.session.commit()
     instance.lobby_id = l.id
     g.player = o
     instance.on_kick(p.id)
     l = db.session.merge(l)
     self.assertEqual(len(l.teams[0]), 0)
示例#22
0
 def test_with_teamed_lobbies(self):
     from lobbypy.models import Player, Lobby, Team
     o = Player('1')
     p = Player('0')
     db.session.add(o)
     db.session.add(p)
     l = Lobby('test', o, 'test', 'test', 'test', teams=[])
     t = Team('Red')
     l.teams.append(t)
     l.teams[0].join(p)
     db.session.add(l)
     db.session.commit()
     rv = self._callFUT(p)
     l_dels = []
     for l_del in rv:
         l_dels.append(l_del)
     self.assertEqual(len(l_dels), 1)
     self.assertEqual(l_dels[0], (l, False))
示例#23
0
 def test_update_player(self):
     p = Player('0')
     db.session.add(p)
     db.session.commit()
     resp = self.client.put('/admin/rest/players/%d' % p.id,
             data=dict(steam_id='1'))
     self.assertStatus(resp, 200)
     p = db.session.merge(p)
     self.assertEqual(p.steam_id, '1')
示例#24
0
 def test_get_player_listing(self, magic_get_summary):
     db.session.add(Player('0'))
     db.session.commit()
     magic_get_summary.return_value = {'personaname':'Anonymous'}
     resp = self.client.get('/admin/rest/players')
     self.assertStatus(resp, 200)
     self.assertTrue('players' in resp.json)
     players = resp.json['players']
     self.assertEqual(len(players), 2)
示例#25
0
 def test_on_join(self, magic_make, magic_item_make, magic_broadcast):
     instance = self._makeOne()
     o = Player('0')
     p = Player('1')
     l = self._makeLobby(owner=o)
     db.session.add(o)
     db.session.add(l)
     db.session.add(p)
     db.session.commit()
     g.player = p
     instance.recv_connect()
     instance.spawn.return_value = 'jerb'
     rv = instance.on_join(l.id)
     self.assertTrue(rv)
     l = Lobby.query.first()
     self.assertEqual(l.spectators[0], p)
     self.assertEqual(instance.allowed_methods,
                      set(['on_leave', 'recv_connect', 'on_set_team']))
     self.assertEqual(instance.lobby_id, l.id)
示例#26
0
 def test_get_lobby_listing(self, magic_get_summary):
     p = Player('0')
     db.session.add(self._makeLobby('A', self.admin, 'a', '', ''))
     db.session.add(self._makeLobby('B', p, 'b', '', ''))
     db.session.commit()
     magic_get_summary.return_value = {'personaname':'Anonymous'}
     resp = self.client.get('/admin/rest/lobbies')
     self.assertTrue('lobbies' in resp.json)
     lobbies = resp.json['lobbies']
     self.assertEqual(len(lobbies), 2)
示例#27
0
def add_admin(steam_id):
    config_app(app, **config)
    from lobbypy.utils import db
    from lobbypy.models import Player
    player = Player.query.filter_by(steam_id = steam_id).first()
    if player:
        player.admin = True
    else:
        player = Player(steam_id)
        player.admin = True
    password = prompt_pass(
            "Enter password for the Administrator")
    if password == prompt_pass(
            "Re-enter password for the Administrator"):
        player.password = crypt(password)
        db.session.add(player)
        db.session.commit()
    else:
        print "Passwords do not match, re-run command"
示例#28
0
 def test_with_no_lobbies(self):
     from lobbypy.models import Player
     p = Player('0')
     db.session.add(p)
     db.session.commit()
     rv = self._callFUT(p)
     l_dels = []
     for l_del in rv:
         l_dels.append(l_del)
     self.assertEqual(len(l_dels), 0)
 def test_set_team(self):
     instance = self._makeOne()
     from lobbypy.models import Player, Team
     t = Team('Red')
     instance.teams.append(t)
     p = Player('0')
     instance.spectators.append(p)
     instance.set_team(p, 0)
     self.assertEqual(len(instance.teams[0].players), 1)
     self.assertEqual(instance.teams[0].players[0].player, p)
 def test_can_set_class(self):
     instance = self._makeOne()
     for i in [0, 1, 3, 6]:
         self.assertTrue(instance.can_set_class(i))
     self.assertTrue(instance.can_set_class(None))
     from lobbypy.models import Player
     instance.join(Player('0'))
     instance.players[0].class_id = 0
     self.assertTrue(instance.can_set_class(0))
     instance.players[0].class_id = 1
     self.assertTrue(instance.can_set_class(1))
 def test_player_count(self):
     instance = self._makeOne()
     from lobbypy.models import Player, Team, LobbyPlayer
     p = Player('0')
     lp = LobbyPlayer(p)
     t_A = Team('Red')
     t_A.players.extend(2 * [lp])
     t_B = Team('Blu')
     t_A.players.extend(3 * [lp])
     instance.teams.extend([t_A, t_B])
     self.assertEqual(instance.player_count, 5)
示例#32
0
 def test_append_spectator(self):
     l = self._makeLobby('Lobby', self.admin, 'test', 'test', 'test')
     p = Player('0')
     db.session.add(p)
     db.session.add(l)
     db.session.commit()
     resp = self.client.post('/admin/rest/lobbies/%d/spectators' % l.id,
             data=dict(player_id = p.id))
     self.assertStatus(resp, 200)
     l = db.session.merge(l)
     self.assertEqual(len(l.spectators), 1)
示例#33
0
 def test_on_leave(self, magic_make, magic_item_make, magic_broadcast):
     instance = self._makeOne()
     o = Player('')
     l = self._makeLobby(owner=o)
     p = Player('0')
     l.join(p)
     db.session.add(o)
     db.session.add(l)
     db.session.add(p)
     db.session.commit()
     instance.lobby_id = l.id
     instance.ctx.g.player = p
     instance.subscribe('/lobby/%d' % l.id)
     instance.allowed_methods = set(
         ['on_leave', 'recv_connect', 'on_set_team'])
     instance.on_leave()
     self.assertEqual(instance.allowed_methods,
                      set(['on_join', 'on_create_lobby', 'recv_connect']))
     self.assertTrue(instance.lobby_id is None)
     self.assertEqual(len(l.spectators), 0)
示例#34
0
 def _makeLobby(self,
                owner=None,
                name='Lobby',
                server_address='server:9999',
                game_map='cp_lololol',
                password='******'):
     from lobbypy.models import Lobby
     if owner is None:
         from lobbypy.models import Player
         owner = Player('-1')
     return Lobby(name, owner, server_address, game_map, password, teams=[])
 def test_set_class(self):
     instance = self._makeOne()
     from lobbypy.models import Player, Team, LobbyPlayer
     t = Team('Red')
     p = Player('0')
     lp = LobbyPlayer(p)
     t.players.append(lp)
     instance.teams.append(t)
     print len(instance.teams)
     instance.set_class(p, 0)
     self.assertEqual(instance.teams[0].players[0].class_id, 0)