示例#1
0
 def test_executemany_wrong_flag_options(self):
     for opt in [1, True, "batch_insert"]:
         assert_raises_message(
             exc.ArgumentError,
             "Invalid value for 'executemany_mode': %r" % opt,
             engines.testing_engine,
             options={"executemany_mode": opt},
         )
示例#2
0
    def test_gen_path_invalid_from_col(self):
        User = self.classes.User

        result = Load(User)
        result.path = self._make_path_registry([User, "name"])
        assert_raises_message(
            sa.exc.ArgumentError,
            "Attribute 'name' of entity 'Mapper|User|users' does "
            "not refer to a mapped entity", result._generate_path, result.path,
            User.addresses, "relationship")
示例#3
0
    def test_row_proc_not_created(self):
        User = self.classes.User
        s = Session()

        q = s.query(User.id, User.name)
        stmt = select([User.id])

        assert_raises_message(
            exc.NoSuchColumnError,
            "Could not locate column in row for column 'users.name'",
            q.from_statement(stmt).all)
示例#4
0
 def test_autocommit_isolation_level(self):
     c = testing.db.connect().execution_options(
         isolation_level='AUTOCOMMIT')
     # If we're really in autocommit mode then we'll get an error saying
     # that the prepared transaction doesn't exist. Otherwise, we'd
     # get an error saying that the command can't be run within a
     # transaction.
     assert_raises_message(
         exc.ProgrammingError,
         'prepared transaction with identifier "gilberte" does not exist',
         c.execute, "commit prepared 'gilberte'")
示例#5
0
 def test_autocommit_isolation_level(self):
     c = testing.db.connect().execution_options(
         isolation_level='AUTOCOMMIT')
     # If we're really in autocommit mode then we'll get an error saying
     # that the prepared transaction doesn't exist. Otherwise, we'd
     # get an error saying that the command can't be run within a
     # transaction.
     assert_raises_message(
         exc.ProgrammingError,
         'prepared transaction with identifier "gilberte" does not exist',
         c.execute, "commit prepared 'gilberte'")
示例#6
0
    def test_gen_path_invalid_from_col(self):
        User = self.classes.User

        result = Load(User)
        result.path = self._make_path_registry([User, "name"])
        assert_raises_message(
            sa.exc.ArgumentError,
            "Attribute 'name' of entity 'Mapper|User|users' does "
            "not refer to a mapped entity",
            result._generate_path, result.path, User.addresses, "relationship"

        )
示例#7
0
    def test_gen_path_attr_entity_invalid_raiseerr(self):
        User = self.classes.User
        Order = self.classes.Order

        l = Load(User)

        assert_raises_message(
            sa.exc.ArgumentError,
            "Attribute 'Order.items' does not link from element 'Mapper|User|users'",
            l._generate_path,
            inspect(User)._path_registry, Order.items, "relationship",
        )
示例#8
0
    def test_row_proc_not_created(self):
        User = self.classes.User
        s = Session()

        q = s.query(User.id, User.name)
        stmt = select([User.id])

        assert_raises_message(
            exc.NoSuchColumnError,
            "Could not locate column in row for column 'users.name'",
            q.from_statement(stmt).all
        )
示例#9
0
    def test_gen_path_attr_entity_invalid_raiseerr(self):
        User = self.classes.User
        Order = self.classes.Order

        l = Load(User)

        assert_raises_message(
            sa.exc.ArgumentError,
            "Attribute 'Order.items' does not link from element 'Mapper|User|users'",
            l._generate_path,
            inspect(User)._path_registry, Order.items, "relationship",
        )
    def test_nested_text_wo_option(self):
        # a statement that returns a multi-row, nested result.
        stmt = 'select customer.id, (select "order".id from "order" '\
                'where customer.id="order".customer_id) as n1 from '\
                'customer where customer.id=3'

        # without the option, it runs in "table" row mode and we
        # get an error.
        assert_raises_message(
            exc.DBAPIError,
            "Subquery returned more than one row",
            config.db.execute, stmt
        )
示例#11
0
    def test_foreignkey_missing_insert(self):
        t1 = Table("t1", metadata, Column("id", Integer, primary_key=True))
        t2 = Table("t2", metadata, Column("id", Integer, ForeignKey("t1.id"), primary_key=True))
        metadata.create_all()

        # want to ensure that "null value in column "id" violates not-
        # null constraint" is raised (IntegrityError on psycoopg2, but
        # ProgrammingError on pg8000), and not "ProgrammingError:
        # (ProgrammingError) relationship "t2_id_seq" does not exist".
        # the latter corresponds to autoincrement behavior, which is not
        # the case here due to the foreign key.

        for eng in [
            engines.testing_engine(options={"implicit_returning": False}),
            engines.testing_engine(options={"implicit_returning": True}),
        ]:
            assert_raises_message(exc.DBAPIError, "violates not-null constraint", eng.execute, t2.insert())
示例#12
0
    def test_foreignkey_missing_insert(self):
        t1 = Table('t1', metadata, Column('id', Integer, primary_key=True))
        t2 = Table(
            't2', metadata,
            Column('id', Integer, ForeignKey('t1.id'), primary_key=True))
        metadata.create_all()

        # want to ensure that "null value in column "id" violates not-
        # null constraint" is raised (IntegrityError on psycoopg2, but
        # ProgrammingError on pg8000), and not "ProgrammingError:
        # (ProgrammingError) relationship "t2_id_seq" does not exist".
        # the latter corresponds to autoincrement behavior, which is not
        # the case here due to the foreign key.

        for eng in [
                engines.testing_engine(options={'implicit_returning': False}),
                engines.testing_engine(options={'implicit_returning': True})
        ]:
            assert_raises_message(exc.DBAPIError,
                                  'violates not-null constraint', eng.execute,
                                  t2.insert())
示例#13
0
    def _assert_data_noautoincrement(self, table):
        self.engine = \
            engines.testing_engine(options={'implicit_returning'
                                   : False})
        metadata.bind = self.engine
        table.insert().execute({'id': 30, 'data': 'd1'})
        if self.engine.driver == 'pg8000':
            exception_cls = exc.ProgrammingError
        elif self.engine.driver == 'pypostgresql':
            exception_cls = Exception
        else:
            exception_cls = exc.IntegrityError
        assert_raises_message(exception_cls, 'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'})
        assert_raises_message(exception_cls, 'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'},
                              {'data': 'd3'})
        assert_raises_message(exception_cls, 'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'})
        assert_raises_message(exception_cls, 'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'},
                              {'data': 'd3'})
        table.insert().execute({
            'id': 31,
            'data': 'd2'
        }, {
            'id': 32,
            'data': 'd3'
        })
        table.insert(inline=True).execute({'id': 33, 'data': 'd4'})
        assert table.select().execute().fetchall() == [(30, 'd1'), (31, 'd2'),
                                                       (32, 'd3'), (33, 'd4')]
        table.delete().execute()

        # test the same series of events using a reflected version of
        # the table

        m2 = MetaData(self.engine)
        table = Table(table.name, m2, autoload=True)
        table.insert().execute({'id': 30, 'data': 'd1'})
        assert_raises_message(exception_cls, 'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'})
        assert_raises_message(exception_cls, 'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'},
                              {'data': 'd3'})
        table.insert().execute({
            'id': 31,
            'data': 'd2'
        }, {
            'id': 32,
            'data': 'd3'
        })
        table.insert(inline=True).execute({'id': 33, 'data': 'd4'})
        assert table.select().execute().fetchall() == [(30, 'd1'), (31, 'd2'),
                                                       (32, 'd3'), (33, 'd4')]
示例#14
0
    def _assert_data_noautoincrement(self, table):
        self.engine = \
            engines.testing_engine(options={'implicit_returning'
                                   : False})
        metadata.bind = self.engine
        table.insert().execute({'id': 30, 'data': 'd1'})
        if self.engine.driver == 'pg8000':
            exception_cls = exc.ProgrammingError
        elif self.engine.driver == 'pypostgresql':
            exception_cls = Exception
        else:
            exception_cls = exc.IntegrityError
        assert_raises_message(exception_cls,
                              'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'})
        assert_raises_message(exception_cls,
                              'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'},
                              {'data': 'd3'})
        assert_raises_message(exception_cls,
                              'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'})
        assert_raises_message(exception_cls,
                              'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'},
                              {'data': 'd3'})
        table.insert().execute({'id': 31, 'data': 'd2'}, {'id': 32,
                               'data': 'd3'})
        table.insert(inline=True).execute({'id': 33, 'data': 'd4'})
        assert table.select().execute().fetchall() == [(30, 'd1'), (31,
                'd2'), (32, 'd3'), (33, 'd4')]
        table.delete().execute()

        # test the same series of events using a reflected version of
        # the table

        m2 = MetaData(self.engine)
        table = Table(table.name, m2, autoload=True)
        table.insert().execute({'id': 30, 'data': 'd1'})
        assert_raises_message(exception_cls,
                              'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'})
        assert_raises_message(exception_cls,
                              'violates not-null constraint',
                              table.insert().execute, {'data': 'd2'},
                              {'data': 'd3'})
        table.insert().execute({'id': 31, 'data': 'd2'}, {'id': 32,
                               'data': 'd3'})
        table.insert(inline=True).execute({'id': 33, 'data': 'd4'})
        assert table.select().execute().fetchall() == [(30, 'd1'), (31,
                'd2'), (32, 'd3'), (33, 'd4')]
示例#15
0
 def _assert_eager_with_entity_exception(self, entity_list, options,
                                         message):
     assert_raises_message(sa.exc.ArgumentError,
                           message,
                           create_session().query(*entity_list).options,
                           *options)
示例#16
0
 def _assert_eager_with_just_column_exception(self, column, eager_option,
                                              message):
     assert_raises_message(sa.exc.ArgumentError, message,
                           create_session().query(column).options,
                           joinedload(eager_option))
示例#17
0
 def _assert_eager_with_entity_exception(self, entity_list, options,
                                         message):
     assert_raises_message(sa.exc.ArgumentError, message,
                           create_session().query(*entity_list).options,
                           *options)
示例#18
0
 def _assert_eager_with_just_column_exception(self, column,
                                              eager_option, message):
     assert_raises_message(sa.exc.ArgumentError, message,
                           create_session().query(column).options,
                           joinedload(eager_option))
示例#19
0
    def _assert_data_noautoincrement(self, table):
        self.engine = engines.testing_engine(options={"implicit_returning": False})
        metadata.bind = self.engine
        table.insert().execute({"id": 30, "data": "d1"})
        if self.engine.driver == "pg8000":
            exception_cls = exc.ProgrammingError
        elif self.engine.driver == "pypostgresql":
            exception_cls = Exception
        else:
            exception_cls = exc.IntegrityError
        assert_raises_message(exception_cls, "violates not-null constraint", table.insert().execute, {"data": "d2"})
        assert_raises_message(
            exception_cls, "violates not-null constraint", table.insert().execute, {"data": "d2"}, {"data": "d3"}
        )
        assert_raises_message(exception_cls, "violates not-null constraint", table.insert().execute, {"data": "d2"})
        assert_raises_message(
            exception_cls, "violates not-null constraint", table.insert().execute, {"data": "d2"}, {"data": "d3"}
        )
        table.insert().execute({"id": 31, "data": "d2"}, {"id": 32, "data": "d3"})
        table.insert(inline=True).execute({"id": 33, "data": "d4"})
        assert table.select().execute().fetchall() == [(30, "d1"), (31, "d2"), (32, "d3"), (33, "d4")]
        table.delete().execute()

        # test the same series of events using a reflected version of
        # the table

        m2 = MetaData(self.engine)
        table = Table(table.name, m2, autoload=True)
        table.insert().execute({"id": 30, "data": "d1"})
        assert_raises_message(exception_cls, "violates not-null constraint", table.insert().execute, {"data": "d2"})
        assert_raises_message(
            exception_cls, "violates not-null constraint", table.insert().execute, {"data": "d2"}, {"data": "d3"}
        )
        table.insert().execute({"id": 31, "data": "d2"}, {"id": 32, "data": "d3"})
        table.insert(inline=True).execute({"id": 33, "data": "d4"})
        assert table.select().execute().fetchall() == [(30, "d1"), (31, "d2"), (32, "d3"), (33, "d4")]