@pytest.mark.parametrize('context,qargs,expected', [ (context(S()), {'$select': 'id'}, unicode(S().column(users.c.id))), (context(S()), {'$select': '*'}, unicode(users.select())), (context(S()), {'$select': 'users.id'}, unicode(S().column(users.c.id))), (context(S()), {'$select': 'users.*'}, unicode(users.select())), (context(select().select_from(users.join(addresses))), {'$select': 'name'}, unicode(select([users.c.name]).select_from(users.join(addresses)))), (context(S()), {'$select': 'name,fullname'}, unicode(select([users.c.name, users.c.fullname], None, [users]))), (context(S()), {'$top': '5'}, unicode(S().limit(5))), (context(S()), {'$skip': '5'}, unicode(S().offset(5))), ]) def test(context, qargs, expected): try: ctx = urlquery.parse(context, qargs)
from itertools import product, chain from sqlalchemy import select 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)