Example #1
0
def test_demo_set_current_node_invalid(db, socket):
    game = DemoGameFactory()
    game.board.play(1)
    game.board.play(2)
    game.apply_board_change()

    svc = GameService(db, socket, game.demo_control)

    with pytest.raises(ServiceError):
        svc.execute('set_current_node', {'game_id': game.id, 'node_id': 2})

    assert game.board.current_node_id == 1
Example #2
0
def test_demo_set_current_node(db, socket):
    game = DemoGameFactory()
    game.board.play(1)
    game.board.play(2)
    game.apply_board_change()

    socket.subscribe('demo_current_node_id/'+str(game.id))
    svc = GameService(db, socket, game.demo_control)
    svc.execute('set_current_node', {'game_id': game.id, 'node_id': 1})

    assert game.board.current_node_id == 1
    assert len(socket.sent_messages) == 1
    assert socket.sent_messages[0]['method'] == 'demo_current_node_id'
    assert socket.sent_messages[0]['data']['game_id'] == game.id
    assert socket.sent_messages[0]['data']['node_id'] == 1
Example #3
0
def test_demo_tool_triangle(db, socket):
    game = DemoGameFactory()
    svc = GameService(db, socket, game.demo_control)

    svc.execute('demo_tool_triangle', {'game_id': game.id, 'coord': 180})

    assert game.board.current_node.symbols['180'] == SYMBOL_TRIANGLE
Example #4
0
def test_close_game_demo(db, socket):
    game = DemoGameFactory()
    socket.subscribe('game_finished')

    svc = GameService(db, socket, game.demo_owner)
    svc.execute('close_game', {'game_id': game.id})

    assert len(socket.sent_messages) == 1
    assert socket.sent_messages[0]['method'] == 'game_finished'
Example #5
0
def test_popular_games_not_private(db):
    demo = DemoGameFactory(room__users_max=10)
    game = GameFactory(room__users_max=11)
    GameFactory(is_private=True, room__users_max=12)

    svc = DashboardService(db)
    popular = svc.execute('popular_games')

    assert len(popular) == 2
    assert popular[0]['id'] == game.id
    assert popular[1]['id'] == demo.id
Example #6
0
def test_demo_control(db, socket):
    user = UserFactory()
    game = DemoGameFactory(demo_control=user)

    svc = GameService(db, socket, game.demo_owner)

    with pytest.raises(InvalidPlayerError):
        svc.execute('move', {'game_id': game.id, 'move': 30})

    assert game.board.at(30) == EMPTY
    assert game.board.current == BLACK
Example #7
0
def test_move_demo(db, socket):
    game = DemoGameFactory()
    socket.subscribe('game_update/'+str(game.id))

    svc = GameService(db, socket, game.demo_control)
    svc.execute('move', {'game_id': game.id, 'move': 30})

    assert game.board.at(30) == BLACK
    assert game.board.current == WHITE
    assert len(socket.sent_messages) == 1
    assert socket.sent_messages[0]['method'] == 'game_update'
Example #8
0
def test_popular_games_age(db):
    demo = DemoGameFactory(room__users_max=10)
    game = GameFactory(room__users_max=11)
    GameFactory(created_at=datetime.utcnow() - timedelta(days=30),
                room__users_max=12)

    svc = DashboardService(db)
    popular = svc.execute('popular_games')

    assert len(popular) == 2
    assert popular[0]['id'] == game.id
    assert popular[1]['id'] == demo.id
Example #9
0
def test_open_game_demo(db, socket):
    game = DemoGameFactory()
    socket.subscribe('game_started')

    svc = GameService(db, socket, game.demo_owner)
    svc.execute('open_game', {'game_id': game.id})

    assert len(socket.sent_messages) == 4
    assert socket.sent_messages[0]['method'] == 'room_user'
    assert socket.sent_messages[1]['method'] == 'room_logs'
    assert socket.sent_messages[2]['method'] == 'game_data'
    assert socket.sent_messages[3]['method'] == 'game_started'
Example #10
0
def test_edit_info(db, socket):
    game = DemoGameFactory()
    socket.subscribe('game_info/'+str(game.id))
    svc = GameService(db, socket, game.demo_owner)
    svc.execute('edit_info', {'game_id': game.id,
                              'title': 'new title',
                              'black_display': 'new black',
                              'white_display': 'new white'})

    assert game.title == 'new title'
    assert game.black_display == 'new black'
    assert game.white_display == 'new white'

    assert len(socket.sent_messages) == 1
    assert socket.sent_messages[0]['method'] == 'game_info'
    assert socket.sent_messages[0]['data']['game_id'] == game.id
Example #11
0
def test_active_games_demo_not_in_room(db):
    DemoGameFactory(demo_owner__is_online=False)
    assert Game.active_games(db).count() == 0
Example #12
0
def test_active_games_demo_offline(db):
    demo = DemoGameFactory(demo_owner__is_online=False)
    RoomUserFactory(room=demo.room, user=demo.demo_owner)
    assert Game.active_games(db).count() == 0
Example #13
0
def test_demo_resign(db, socket):
    game = DemoGameFactory()
    svc = GameService(db, socket, game.demo_control)

    with pytest.raises(ServiceError):
        svc.execute('move', {'game_id': game.id, 'move': RESIGN})