コード例 #1
0
def test_decks_where_deck_type() -> None:
    args = {'deckType': DeckType.LEAGUE.value}
    assert "= 'League'" in query.decks_where(args, 1)
    args = {'deckType': DeckType.TOURNAMENT.value}
    assert "= 'Gatherling'" in query.decks_where(args, 1)
    args = {'deckType': DeckType.ALL.value}
    assert "= 'League'" not in query.decks_where(args, 1)
    assert "= 'Gatherling'" not in query.decks_where(args, 1)
コード例 #2
0
def decks_api() -> Response:
    """
    Grab a slice of results from a 0-indexed resultset of decks.
    Input:
        {
            'archetypeId': <int?>,
            'cardName': <str?>,
            'competitionId': <int?>,
            'personId': <int?>,
            'deckType': <'league'|'tournament'|'all'>,
            'page': <int>,
            'pageSize': <int>,
            'personId': <int?>,
            'sortBy': <str>,
            'sortOrder': <'ASC'|'DESC'>,
            'seasonId': <int|'all'>
        }
    Output:
        {
            'page': <int>,
            'pages': <int>,
            'decks': [<deck>]
        }
    """
    if not request.args.get('sortBy') and request.args.get('competitionId'):
        sort_by = 'top8'
        sort_order = 'ASC'
    elif not request.args.get('sortBy'):
        sort_by = 'date'
        sort_order = 'DESC'
    else:
        sort_by = str(request.args.get('sortBy'))
        sort_order = str(request.args.get('sortOrder'))
    assert sort_order in ['ASC', 'DESC']
    order_by = query.decks_order_by(sort_by, sort_order)
    page_size = int(request.args.get('pageSize', 20))
    page = int(request.args.get('page', 0))
    start = page * page_size
    limit = f'LIMIT {start}, {page_size}'
    # Don't restrict by season if we're loading something with a date by its id.
    season_id = 'all' if request.args.get(
        'competitionId') else rotation.season_id(
            str(request.args.get('seasonId')), None)
    where = query.decks_where(request.args, session.get('person_id'))
    total = deck.load_decks_count(where=where, season_id=season_id)
    pages = max(ceil(total / page_size) - 1, 0)  # 0-indexed
    ds = deck.load_decks(where=where,
                         order_by=order_by,
                         limit=limit,
                         season_id=season_id)
    prepare_decks(ds)
    r = {'page': page, 'pages': pages, 'decks': ds}
    resp = return_json(r, camelize=True)
    resp.set_cookie('page_size', str(page_size))
    return resp
コード例 #3
0
def test_decks_where() -> None:
    args = {'deckType': DeckType.LEAGUE.value}
    assert "= 'League'" in query.decks_where(args, False, 1)
    assert 'd.retired' in query.decks_where(args, False, 1)
    assert 'd.retired' not in query.decks_where(args, True, 1)
    args = {'deckType': DeckType.TOURNAMENT.value}
    assert "= 'Gatherling'" in query.decks_where(args, False, 1)
    args = {'deckType': DeckType.ALL.value}
    assert "= 'League'" not in query.decks_where(args, False, 1)
    assert "= 'Gatherling'" not in query.decks_where(args, False, 1)
コード例 #4
0
def decks_api() -> Response:
    """
    Grab a slice of results from a 0-indexed resultset of decks.
    Input:
        {
            'archetypeId': <int?>,
            'cardName': <str?>,
            'competitionId': <int?>,
            'deckType': <'league'|'tournament'|'all'>,
            'page': <int>,
            'pageSize': <int>,
            'personId': <int?>,
            'sortBy': <str>,
            'sortOrder': <'ASC'|'DESC'>,
            'seasonId': <int|'all'>
        }
    Output:
        {
            'page': <int>,
            'objects': [<deck>]
            'total': <int>
        }
    """
    order_by = query.decks_order_by(request.args.get('sortBy'),
                                    request.args.get('sortOrder'),
                                    request.args.get('competitionId'))
    page_size = int(request.args.get('pageSize', DEFAULT_LIVE_TABLE_PAGE_SIZE))
    page = int(request.args.get('page', 0))
    start = page * page_size
    limit = f'LIMIT {start}, {page_size}'
    # Don't restrict by season if we're loading something with a date by its id.
    season_id = 'all' if request.args.get(
        'competitionId') else seasons.season_id(
            str(request.args.get('seasonId')), None)
    where = query.decks_where(request.args, session.get('admin'),
                              session.get('person_id'))
    total = deck.load_decks_count(where=where, season_id=season_id)
    ds = deck.load_decks(where=where,
                         order_by=order_by,
                         limit=limit,
                         season_id=season_id)
    prepare_decks(ds)
    r = {'page': page, 'total': total, 'objects': ds}
    resp = return_json(r, camelize=True)
    resp.set_cookie('page_size', str(page_size))
    return resp