/usr/lib/python2.7/dist-packages/sqlalchemy/testing/suite/test_sequence.py is in python-sqlalchemy 0.8.4-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | from .. import fixtures, config
from ..config import requirements
from ..assertions import eq_
from ... import testing
from ... import Integer, String, Sequence, schema
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))
)
Table('seq_opt_pk', metadata,
Column('id', Integer, Sequence('tab_id_seq', optional=True),
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
)
@requirements.sequences_optional
def test_optional_seq(self):
r = config.db.execute(
self.tables.seq_opt_pk.insert(),
data="some data"
)
eq_(
r.inserted_primary_key,
[1]
)
def _assert_round_trip(self, table, conn):
row = conn.execute(table.select()).first()
eq_(
row,
(1, "some data")
)
class HasSequenceTest(fixtures.TestBase):
__requires__ = 'sequences',
def test_has_sequence(self):
s1 = Sequence('user_id_seq')
testing.db.execute(schema.CreateSequence(s1))
try:
eq_(testing.db.dialect.has_sequence(testing.db,
'user_id_seq'), True)
finally:
testing.db.execute(schema.DropSequence(s1))
@testing.requires.schemas
def test_has_sequence_schema(self):
s1 = Sequence('user_id_seq', schema="test_schema")
testing.db.execute(schema.CreateSequence(s1))
try:
eq_(testing.db.dialect.has_sequence(testing.db,
'user_id_seq', schema="test_schema"), True)
finally:
testing.db.execute(schema.DropSequence(s1))
def test_has_sequence_neg(self):
eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq'),
False)
@testing.requires.schemas
def test_has_sequence_schemas_neg(self):
eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq',
schema="test_schema"),
False)
@testing.requires.schemas
def test_has_sequence_default_not_in_remote(self):
s1 = Sequence('user_id_seq')
testing.db.execute(schema.CreateSequence(s1))
try:
eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq',
schema="test_schema"),
False)
finally:
testing.db.execute(schema.DropSequence(s1))
@testing.requires.schemas
def test_has_sequence_remote_not_in_default(self):
s1 = Sequence('user_id_seq', schema="test_schema")
testing.db.execute(schema.CreateSequence(s1))
try:
eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq'),
False)
finally:
testing.db.execute(schema.DropSequence(s1))
|