I use "mock.patch" http://www.voidspace.org.uk/python/mock/patch.html.
I don't use it with SQLA, but I'm writing a wrapper around a
webservice with a very similar SQLA API that needs to avoid making
outgoing http requests during tests. You can you mock.patch as a
decorator or as a "with" statement. The idea is to tell mock.patch
what python method/function is being patched and replace it with a
function that will return expected data, such as:

expected_data_stubs = [data1, data2, data3]

# ``Query._make_request`` will be patched with the lambda function
within the context manager
with patch('mylib.query.Query._make_request', lambda *args, **kwargs:
expeced_data_stubs.pop(0)):
    obj1 = manager.query(MyObject).get(1)  # lambda returns the 1st object
    obj2 = manager.query(MyObject).get(2)  # lambda returns the 2nd object
    obj3 = manager.query(MyObject).get(3)  # lambda returns the 3rd object

# outside the context manager, ``Query._make_request`` will be unpatched.
assert obj1.id == data1['id']
assert obj2.id == data2['id']
assert obj3.id == data3['id']

Maybe you could do something similar that would patch .all(), .get()
and .count() and return whatever you expect.


2011/1/16 Eric Lemoine <eric.lemo...@camptocamp.com>:
> Hello
>
> For testing purposed I'd like to do query.all(). query.get() and
> query.count() with no actual communication with the DBMS. Is this
> possible?
>
> Thanks a lot,
>
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : eric.lemo...@camptocamp.com
> http://www.camptocamp.com
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>



-- 
Alex | twitter.com/alexconrad

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to