~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/testing/suite/test_sequence.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from .. import fixtures, config
 
2
from ..config import requirements
 
3
from ..assertions import eq_
 
4
from ... import testing
 
5
 
 
6
from ... import Integer, String, Sequence, schema
 
7
 
 
8
from ..schema import Table, Column
 
9
 
 
10
class SequenceTest(fixtures.TablesTest):
 
11
    __requires__ = ('sequences',)
 
12
 
 
13
    run_create_tables = 'each'
 
14
 
 
15
    @classmethod
 
16
    def define_tables(cls, metadata):
 
17
        Table('seq_pk', metadata,
 
18
                Column('id', Integer, Sequence('tab_id_seq'), primary_key=True),
 
19
                Column('data', String(50))
 
20
            )
 
21
 
 
22
        Table('seq_opt_pk', metadata,
 
23
                Column('id', Integer, Sequence('tab_id_seq', optional=True),
 
24
                                                primary_key=True),
 
25
                Column('data', String(50))
 
26
            )
 
27
 
 
28
    def test_insert_roundtrip(self):
 
29
        config.db.execute(
 
30
            self.tables.seq_pk.insert(),
 
31
            data="some data"
 
32
        )
 
33
        self._assert_round_trip(self.tables.seq_pk, config.db)
 
34
 
 
35
    def test_insert_lastrowid(self):
 
36
        r = config.db.execute(
 
37
            self.tables.seq_pk.insert(),
 
38
            data="some data"
 
39
        )
 
40
        eq_(
 
41
            r.inserted_primary_key,
 
42
            [1]
 
43
        )
 
44
 
 
45
    def test_nextval_direct(self):
 
46
        r = config.db.execute(
 
47
            self.tables.seq_pk.c.id.default
 
48
        )
 
49
        eq_(
 
50
            r, 1
 
51
        )
 
52
 
 
53
    @requirements.sequences_optional
 
54
    def test_optional_seq(self):
 
55
        r = config.db.execute(
 
56
            self.tables.seq_opt_pk.insert(),
 
57
            data="some data"
 
58
        )
 
59
        eq_(
 
60
            r.inserted_primary_key,
 
61
            [1]
 
62
        )
 
63
 
 
64
 
 
65
    def _assert_round_trip(self, table, conn):
 
66
        row = conn.execute(table.select()).first()
 
67
        eq_(
 
68
            row,
 
69
            (1, "some data")
 
70
        )
 
71
 
 
72
 
 
73
class HasSequenceTest(fixtures.TestBase):
 
74
    __requires__ = 'sequences',
 
75
 
 
76
    def test_has_sequence(self):
 
77
        s1 = Sequence('user_id_seq')
 
78
        testing.db.execute(schema.CreateSequence(s1))
 
79
        try:
 
80
            eq_(testing.db.dialect.has_sequence(testing.db,
 
81
                'user_id_seq'), True)
 
82
        finally:
 
83
            testing.db.execute(schema.DropSequence(s1))
 
84
 
 
85
    @testing.requires.schemas
 
86
    def test_has_sequence_schema(self):
 
87
        s1 = Sequence('user_id_seq', schema="test_schema")
 
88
        testing.db.execute(schema.CreateSequence(s1))
 
89
        try:
 
90
            eq_(testing.db.dialect.has_sequence(testing.db,
 
91
                'user_id_seq', schema="test_schema"), True)
 
92
        finally:
 
93
            testing.db.execute(schema.DropSequence(s1))
 
94
 
 
95
    def test_has_sequence_neg(self):
 
96
        eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq'),
 
97
            False)
 
98
 
 
99
    @testing.requires.schemas
 
100
    def test_has_sequence_schemas_neg(self):
 
101
        eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq',
 
102
                            schema="test_schema"),
 
103
            False)
 
104
 
 
105
    @testing.requires.schemas
 
106
    def test_has_sequence_default_not_in_remote(self):
 
107
        s1 = Sequence('user_id_seq')
 
108
        testing.db.execute(schema.CreateSequence(s1))
 
109
        try:
 
110
            eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq',
 
111
                            schema="test_schema"),
 
112
                False)
 
113
        finally:
 
114
            testing.db.execute(schema.DropSequence(s1))
 
115
 
 
116
    @testing.requires.schemas
 
117
    def test_has_sequence_remote_not_in_default(self):
 
118
        s1 = Sequence('user_id_seq', schema="test_schema")
 
119
        testing.db.execute(schema.CreateSequence(s1))
 
120
        try:
 
121
            eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq'),
 
122
                False)
 
123
        finally:
 
124
            testing.db.execute(schema.DropSequence(s1))
 
125
 
 
126