def test_minimum_version(self): with mock.patch( "sqlalchemy.dialects.oracle.cx_oracle.OracleDialect_cx_oracle." "_parse_cx_oracle_ver", lambda self, vers: (5, 1, 5)): assert_raises_message( exc.InvalidRequestError, "cx_Oracle version 5.2 and above are supported", cx_oracle.OracleDialect_cx_oracle, dbapi=Mock() ) with mock.patch( "sqlalchemy.dialects.oracle.cx_oracle.OracleDialect_cx_oracle." "_parse_cx_oracle_ver", lambda self, vers: (5, 3, 1)): cx_oracle.OracleDialect_cx_oracle(dbapi=Mock())
def test_update_multi_missing_broken_multi_rowcount(self): @util.memoized_property def rowcount(self): if len(self.context.compiled_parameters) > 1: return -1 else: return self.context.rowcount with patch.object( config.db.dialect, "supports_sane_multi_rowcount", False): with patch( "sqlalchemy.engine.result.ResultProxy.rowcount", rowcount): Foo = self.classes.Foo s1 = self._fixture() f1s1 = Foo(value='f1 value') s1.add(f1s1) s1.commit() f1s1.value = 'f2 value' s1.flush() eq_(f1s1.version_id, 2)
def test_update_multi_missing_broken_multi_rowcount(self): @util.memoized_property def rowcount(self): if len(self.context.compiled_parameters) > 1: return -1 else: return self.context.rowcount with patch.object( config.db.dialect, "supports_sane_multi_rowcount", False): with patch( "sqlalchemy.engine.result.ResultProxy.rowcount", rowcount): Foo = self.classes.Foo s1 = self._fixture() f1s1 = Foo(value='f1 value') s1.add(f1s1) s1.commit() f1s1.value = 'f2 value' s1.flush() eq_(f1s1.version_id, 2)
def test_bind_through_execute( self, statement, expected_get_bind_args, expected_engine_name ): users, Address, addresses, User = ( self.tables.users, self.classes.Address, self.tables.addresses, self.classes.User, ) self.mapper_registry.map_imperatively( User, users, properties={"addresses": relationship(Address)} ) self.mapper_registry.map_imperatively(Address, addresses) e1 = engines.testing_engine() e2 = engines.testing_engine() e3 = engines.testing_engine() canary = mock.Mock() class GetBindSession(Session): def _connection_for_bind(self, bind, **kw): canary._connection_for_bind(bind, **kw) return mock.Mock() def get_bind(self, **kw): canary.get_bind(**kw) return Session.get_bind(self, **kw) sess = GetBindSession(e3, future=True) sess.bind_mapper(User, e1) sess.bind_mapper(Address, e2) lambda_args = dict( session=sess, User=User, Address=Address, e1=e1, e2=e2, e3=e3, addresses=addresses, ) statement = testing.resolve_lambda(statement, **lambda_args) expected_get_bind_args = testing.resolve_lambda( expected_get_bind_args, **lambda_args ) engine = {"e1": e1, "e2": e2, "e3": e3}[expected_engine_name] with mock.patch( "sqlalchemy.orm.context.ORMCompileState.orm_setup_cursor_result" ): sess.execute(statement) eq_( canary.mock_calls, [ mock.call.get_bind(**expected_get_bind_args), mock.call._connection_for_bind(engine), ], ) sess.close()
def test_bad_make_row_callable(self, env, cmd): with mock.patch('audit_alembic.test_auditor', _custom_auditor(lambda **_: None)), \ pytest.raises(exc.AuditRuntimeError): cmd.upgrade(env.R.A)
def test_null_version_callable_raises_warning(self, env, cmd): with mock.patch('audit_alembic.test_auditor', audit_alembic.Auditor.create(lambda **kw: None)), \ pytest.warns(exc.UserVersionWarning): cmd.upgrade(env.R.A)
def mocked_date(fixed_date): with mock.patch("api.events.request_parsing.date") as mock_date: mock_date.today.return_value = fixed_date mock_date.side_effect = lambda *args, **kw: datetime.date(*args, **kw) yield