Esempio n. 1
0
     {'$skip': '5'},
     unicode(S().offset(5))),
    ])
def test(context, qargs, expected):
    try:
        ctx = urlquery.parse(context, qargs)
    except NotImplementedError:
        pytest.skip("not implemented")
    else:
        assert unicode(ctx['sqlobj']) == expected


qargs = ['$select', '$top', '$skip', '$filter']
vals = ['badstringvalue', None, '']
bad_inputs = ((context(S()), {q: v}) for q, v in product(qargs, vals))


@pytest.mark.parametrize('context,qargs', bad_inputs)
def test_matrix_fail(context, qargs):
    with pytest.raises(RequestParseError):
        urlquery.parse(context, qargs)


@pytest.mark.parametrize('context,qargs', [
    (context(users.join(addresses).select()), {'$select': 'id'}),
    (context(users.update()), {'$select': 'name'}),
    ])
def test_req_parse_error(context, qargs):
    with pytest.raises(RequestParseError):
        urlquery.parse(context, qargs)
Esempio n. 2
0
from odata import parser, urlpath
from odata.exc import NotFoundException, RequestParseError
from fixtures import tables, users, addresses
import pytest

expected = [
    ('GET', '/users', unicode(select().select_from(users))),
    ('GET', '/users(5)', unicode(
        select().select_from(users).where(users.c.id == 5))),
    ('GET', '/users(5)/addresses', unicode(
        select().select_from(users.join(addresses)).where(users.c.id == 5))),
    ('GET', '/addresses/user_id', unicode(
        select().select_from(addresses).column(addresses.c.user_id))),
    ('DELETE', '/users(5)', unicode(users.delete().where(users.c.id == 5))),
    ('DELETE', '/users(5)/fullname', unicode(
        users.update().where(users.c.id == 5).values({
            users.c.fullname: None}))),
    ('POST', '/users', unicode(users.insert())),
    ('PUT', '/users', unicode(users.update())),
    ]


def make_context(verb):
    return dict(sqlobj=parser.verbfuncs[verb],
                response_headers={},
                tables=tables,
                request_payload=None)


@pytest.mark.parametrize('verb,path,query', expected)
def test_expected(verb, path, query):
    context = make_context(verb)