From: Mike Bayer Date: Wed, 6 Feb 2013 20:49:32 +0000 (-0500) Subject: - add an "empty_inserts" requirement target plus a suite test X-Git-Tag: rel_0_8_0~24^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2121c1690a17090a4027874751e90d02b4126fd2;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - add an "empty_inserts" requirement target plus a suite test - add suite tests for basic explicit Sequence support, result-row column access (tests that name_normalize is set correctly among many other things) --- diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py index 2fb1b31434..f7d00afb29 100644 --- a/lib/sqlalchemy/testing/requirements.py +++ b/lib/sqlalchemy/testing/requirements.py @@ -68,6 +68,16 @@ class SuiteRequirements(Requirements): return exclusions.open() + @property + def empty_inserts(self): + """target platform supports INSERT with no values, i.e. + INSERT DEFAULT VALUES or equivalent.""" + + return exclusions.only_if( + lambda: self.config.db.dialect.supports_empty_insert, + "empty inserts not supported" + ) + @property def returning(self): """target platform supports RETURNING.""" diff --git a/lib/sqlalchemy/testing/suite/__init__.py b/lib/sqlalchemy/testing/suite/__init__.py index bb0465c9ed..f65dd1a343 100644 --- a/lib/sqlalchemy/testing/suite/__init__.py +++ b/lib/sqlalchemy/testing/suite/__init__.py @@ -1,6 +1,8 @@ from sqlalchemy.testing.suite.test_ddl import * from sqlalchemy.testing.suite.test_insert import * +from sqlalchemy.testing.suite.test_sequence import * +from sqlalchemy.testing.suite.test_results import * from sqlalchemy.testing.suite.test_update_delete import * from sqlalchemy.testing.suite.test_reflection import * from sqlalchemy.testing.suite.test_types import * diff --git a/lib/sqlalchemy/testing/suite/test_insert.py b/lib/sqlalchemy/testing/suite/test_insert.py index b2b2a0aa8b..e3ef2b2063 100644 --- a/lib/sqlalchemy/testing/suite/test_insert.py +++ b/lib/sqlalchemy/testing/suite/test_insert.py @@ -107,6 +107,24 @@ class InsertBehaviorTest(fixtures.TablesTest): assert r.is_insert assert not r.returns_rows + @requirements.empty_inserts + def test_empty_insert(self): + r = config.db.execute( + self.tables.autoinc_pk.insert(), + ) + assert r.closed + + r = config.db.execute( + self.tables.autoinc_pk.select() + ) + + eq_( + r.fetchall(), + [(1, None)] + ) + + + class ReturningTest(fixtures.TablesTest): run_deletes = 'each' diff --git a/lib/sqlalchemy/testing/suite/test_results.py b/lib/sqlalchemy/testing/suite/test_results.py new file mode 100644 index 0000000000..f81e30e0b7 --- /dev/null +++ b/lib/sqlalchemy/testing/suite/test_results.py @@ -0,0 +1,69 @@ +from .. import fixtures, config +from ..config import requirements +from .. import exclusions +from ..assertions import eq_ +from .. import engines + +from sqlalchemy import Integer, String, select, util + +from ..schema import Table, Column + + +class RowFetchTest(fixtures.TablesTest): + + @classmethod + def define_tables(cls, metadata): + Table('plain_pk', metadata, + Column('id', Integer, primary_key=True), + Column('data', String(50)) + ) + + @classmethod + def insert_data(cls): + config.db.execute( + cls.tables.plain_pk.insert(), + [ + {"id":1, "data":"d1"}, + {"id":2, "data":"d2"}, + {"id":3, "data":"d3"}, + ] + ) + + def test_via_string(self): + row = config.db.execute( + self.tables.plain_pk.select().\ + order_by(self.tables.plain_pk.c.id) + ).first() + + eq_( + row['id'], 1 + ) + eq_( + row['data'], "d1" + ) + + def test_via_int(self): + row = config.db.execute( + self.tables.plain_pk.select().\ + order_by(self.tables.plain_pk.c.id) + ).first() + + eq_( + row[0], 1 + ) + eq_( + row[1], "d1" + ) + + def test_via_col_object(self): + row = config.db.execute( + self.tables.plain_pk.select().\ + order_by(self.tables.plain_pk.c.id) + ).first() + + eq_( + row[self.tables.plain_pk.c.id], 1 + ) + eq_( + row[self.tables.plain_pk.c.data], "d1" + ) \ No newline at end of file diff --git a/lib/sqlalchemy/testing/suite/test_sequence.py b/lib/sqlalchemy/testing/suite/test_sequence.py new file mode 100644 index 0000000000..0b60aa5b7c --- /dev/null +++ b/lib/sqlalchemy/testing/suite/test_sequence.py @@ -0,0 +1,54 @@ +from .. import fixtures, config +from ..config import requirements +from ..assertions import eq_ + +from sqlalchemy import Integer, String, Sequence + +from ..schema import Table, Column + +class SequenceTest(fixtures.TablesTest): + __requires__ = ('sequences',) + + run_create_tables = 'each' + + @classmethod + def define_tables(cls, metadata): + Table('seq_pk', metadata, + Column('id', Integer, Sequence('tab_id_seq'), primary_key=True), + Column('data', String(50)) + ) + + def test_insert_roundtrip(self): + config.db.execute( + self.tables.seq_pk.insert(), + data="some data" + ) + self._assert_round_trip(self.tables.seq_pk, config.db) + + def test_insert_lastrowid(self): + r = config.db.execute( + self.tables.seq_pk.insert(), + data="some data" + ) + eq_( + r.inserted_primary_key, + [1] + ) + + def test_nextval_direct(self): + r = config.db.execute( + self.tables.seq_pk.c.id.default + ) + eq_( + r, 1 + ) + + + + def _assert_round_trip(self, table, conn): + row = conn.execute(table.select()).first() + eq_( + row, + (1, "some data") + ) + diff --git a/test/sql/test_query.py b/test/sql/test_query.py index 2c0ee4a186..16b0f79fd9 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -1785,18 +1785,18 @@ class CompoundTest(fixtures.TestBase): global metadata, t1, t2, t3 metadata = MetaData(testing.db) t1 = Table('t1', metadata, - Column('col1', Integer, Sequence('t1pkseq'), primary_key=True), + Column('col1', Integer, test_needs_autoincrement=True, primary_key=True), Column('col2', String(30)), Column('col3', String(40)), Column('col4', String(30)) ) t2 = Table('t2', metadata, - Column('col1', Integer, Sequence('t2pkseq'), primary_key=True), + Column('col1', Integer, test_needs_autoincrement=True, primary_key=True), Column('col2', String(30)), Column('col3', String(40)), Column('col4', String(30))) t3 = Table('t3', metadata, - Column('col1', Integer, Sequence('t3pkseq'), primary_key=True), + Column('col1', Integer, test_needs_autoincrement=True, primary_key=True), Column('col2', String(30)), Column('col3', String(40)), Column('col4', String(30)))