mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-27 19:15:05 -04:00
b38a76cd1d
actual mock objects from the mock library. I'd like to use mock for new tests so we might as well use it in obvious places. - use unittest.mock in py3.3 - changelog - add a note to README.unittests - add tests_require in setup.py - have tests import from sqlalchemy.testing.mock - apply usage of mock to one of the event tests. we can be using this approach all over the place.
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from sqlalchemy import *
|
|
from sqlalchemy.testing import eq_
|
|
from sqlalchemy.testing import engines
|
|
from sqlalchemy.testing import fixtures
|
|
from sqlalchemy.testing.mock import Mock
|
|
|
|
def mock_dbapi():
|
|
return Mock(paramstyle='qmark',
|
|
connect=Mock(
|
|
return_value=Mock(
|
|
cursor=Mock(
|
|
return_value=Mock(
|
|
description=None,
|
|
rowcount=None)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
class MxODBCTest(fixtures.TestBase):
|
|
|
|
def test_native_odbc_execute(self):
|
|
t1 = Table('t1', MetaData(), Column('c1', Integer))
|
|
dbapi = mock_dbapi()
|
|
|
|
engine = engines.testing_engine('mssql+mxodbc://localhost',
|
|
options={'module': dbapi, '_initialize': False})
|
|
conn = engine.connect()
|
|
|
|
# crud: uses execute
|
|
conn.execute(t1.insert().values(c1='foo'))
|
|
conn.execute(t1.delete().where(t1.c.c1 == 'foo'))
|
|
conn.execute(t1.update().where(t1.c.c1 == 'foo').values(c1='bar'))
|
|
|
|
# select: uses executedirect
|
|
conn.execute(t1.select())
|
|
|
|
# manual flagging
|
|
conn.execution_options(native_odbc_execute=True).\
|
|
execute(t1.select())
|
|
conn.execution_options(native_odbc_execute=False).\
|
|
execute(t1.insert().values(c1='foo'))
|
|
|
|
eq_(
|
|
[c[2] for c in
|
|
dbapi.connect.return_value.cursor.return_value.execute.mock_calls],
|
|
[{'direct': True}, {'direct': True}, {'direct': True},
|
|
{'direct': True}, {'direct': False}, {'direct': True}]
|
|
)
|