Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.191.189.119
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/automx/env/lib/python3.5/site-packages/sqlalchemy/testing/suite/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /srv/automx/env/lib/python3.5/site-packages/sqlalchemy/testing/suite/test_sequence.py
from .. import config
from .. import fixtures
from ..assertions import eq_
from ..config import requirements
from ..schema import Column
from ..schema import Table
from ... import Integer
from ... import MetaData
from ... import schema
from ... import Sequence
from ... import String
from ... import testing


class SequenceTest(fixtures.TablesTest):
    __requires__ = ("sequences",)
    __backend__ = True

    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 SequenceCompilerTest(testing.AssertsCompiledSQL, fixtures.TestBase):
    __requires__ = ("sequences",)
    __backend__ = True

    def test_literal_binds_inline_compile(self):
        table = Table(
            "x",
            MetaData(),
            Column("y", Integer, Sequence("y_seq")),
            Column("q", Integer),
        )

        stmt = table.insert().values(q=5)

        seq_nextval = testing.db.dialect.statement_compiler(
            statement=None, dialect=testing.db.dialect
        ).visit_sequence(Sequence("y_seq"))
        self.assert_compile(
            stmt,
            "INSERT INTO x (y, q) VALUES (%s, 5)" % (seq_nextval,),
            literal_binds=True,
            dialect=testing.db.dialect,
        )


class HasSequenceTest(fixtures.TestBase):
    __requires__ = ("sequences",)
    __backend__ = True

    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=config.test_schema)
        testing.db.execute(schema.CreateSequence(s1))
        try:
            eq_(
                testing.db.dialect.has_sequence(
                    testing.db, "user_id_seq", schema=config.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=config.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=config.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=config.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))

Anon7 - 2022
AnonSec Team