コード例 #1
0
    def test_starting_rev_pre_context_stamp(self):
        env_file_fixture("""
assert context.get_starting_revision_argument() == 'x'
""")
        assert_raises_message(util.CommandError,
                              "No starting revision argument is available.",
                              command.stamp, self.cfg, a)
コード例 #2
0
def test_drop_check():
    context = op_fixture('mysql')
    assert_raises_message(
        NotImplementedError,
        "MySQL does not support CHECK constraints.",
        op.drop_constraint, "f1", "t1", "check"
    )
コード例 #3
0
ファイル: test_op.py プロジェクト: shadowmint/py-test-watcher
def test_naming_changes():
    context = op_fixture()
    op.alter_column("t", "c", name="x")
    context.assert_("ALTER TABLE t RENAME c TO x")

    context = op_fixture()
    op.alter_column("t", "c", new_column_name="x")
    context.assert_("ALTER TABLE t RENAME c TO x")

    context = op_fixture('mssql')
    op.drop_index('ik_test', tablename='t1')
    context.assert_("DROP INDEX [t1].ik_test")

    context = op_fixture('mssql')
    op.drop_index('ik_test', table_name='t1')
    context.assert_("DROP INDEX [t1].ik_test")

    context = op_fixture('mysql')
    op.drop_constraint("f1", "t1", type="foreignkey")
    context.assert_("ALTER TABLE t1 DROP FOREIGN KEY f1")

    context = op_fixture('mysql')
    op.drop_constraint("f1", "t1", type_="foreignkey")
    context.assert_("ALTER TABLE t1 DROP FOREIGN KEY f1")

    assert_raises_message(
        TypeError,
        "Unknown arguments: badarg2, badarg1",
        op.alter_column, "t", "c", badarg1="x", badarg2="y"
    )
コード例 #4
0
def test_invalid_format():
    context, t1 = _table_fixture("sqlite", False)
    assert_raises_message(TypeError, "List expected", op.bulk_insert, t1,
                          {"id": 5})

    assert_raises_message(TypeError, "List of dictionaries expected",
                          op.bulk_insert, t1, [(5, )])
コード例 #5
0
    def test_starting_rev_current_pre_context(self):
        env_file_fixture("""
assert context.get_starting_revision_argument() is None
""")
        assert_raises_message(util.CommandError,
                              "No starting revision argument is available.",
                              command.current, self.cfg)
コード例 #6
0
def test_col_alter_type_required():
    context = op_fixture('mysql')
    assert_raises_message(
        util.CommandError,
        "All MySQL ALTER COLUMN operations require the existing type.",
        op.alter_column, 't1', 'c1', nullable=False, server_default="q"
    )
コード例 #7
0
    def test_error_on_new_with_missing_revision(self):
        self.cfg.set_main_option("file_template", "%%(slug)s_%%(rev)s")
        script = ScriptDirectory.from_config(self.cfg)
        a = util.rev_id()
        script.generate_revision(a, "foobar", refresh=True)
        assert_raises_message(
            util.CommandError,
            "Could not determine revision id from filename foobar_%s.py. "
            "Be sure the 'revision' variable is declared "
            "inside the script." % a,
            write_script,
            script,
            a,
            """
        down_revision = None

        from alembic import op

        def upgrade():
            op.execute("CREATE TABLE foo(id integer)")

        def downgrade():
            op.execute("DROP TABLE foo")

        """,
        )
コード例 #8
0
ファイル: test_sqlite.py プロジェクト: witsch/alembic
def test_add_explicit_constraint():
    context = op_fixture('sqlite')
    assert_raises_message(
        NotImplementedError,
        "No support for ALTER of constraints in SQLite dialect",
        op.create_check_constraint, "foo", "sometable",
        column('name') > 5)
コード例 #9
0
def test_col_alter_type_required():
    context = op_fixture('mysql')
    assert_raises_message(
        util.CommandError,
        "All MySQL ALTER COLUMN operations require the existing type.",
        op.alter_column, 't1', 'c1', nullable=False, server_default="q"
    )
コード例 #10
0
def test_drop_check():
    context = op_fixture('mysql')
    assert_raises_message(
        NotImplementedError,
        "MySQL does not support CHECK constraints.",
        op.drop_constraint, "f1", "t1", "check"
    )
コード例 #11
0
ファイル: test_config.py プロジェクト: Lifto/alembic
def test_no_script_error():
    cfg = config.Config()
    assert_raises_message(
        util.CommandError,
        "No 'script_location' key found in configuration.",
        ScriptDirectory.from_config, cfg
    )
コード例 #12
0
def test_drop_generic_constraint():
    context = op_fixture('mysql')
    assert_raises_message(
        NotImplementedError,
        "No generic 'DROP CONSTRAINT' in MySQL - please "
        "specify constraint type",
        op.drop_constraint, "f1", "t1"
    )
コード例 #13
0
def test_drop_unknown():
    context = op_fixture('mysql')
    assert_raises_message(
        TypeError,
        "'type' can be one of 'check', 'foreignkey', "
        "'primary', 'unique', None",
        op.drop_constraint, "f1", "t1", "typo"
    )
コード例 #14
0
    def test_starting_rev_pre_context_stamp(self):
        env_file_fixture("""
assert context.get_starting_revision_argument() == 'x'
""")
        assert_raises_message(
            util.CommandError,
            "No starting revision argument is available.",
            command.stamp, self.cfg, a)
コード例 #15
0
def test_drop_unknown():
    context = op_fixture('mysql')
    assert_raises_message(
        TypeError,
        "'type' can be one of 'check', 'foreignkey', "
        "'primary', 'unique', None",
        op.drop_constraint, "f1", "t1", "typo"
    )
コード例 #16
0
def test_drop_generic_constraint():
    context = op_fixture('mysql')
    assert_raises_message(
        NotImplementedError,
        "No generic 'DROP CONSTRAINT' in MySQL - please "
        "specify constraint type",
        op.drop_constraint, "f1", "t1"
    )
コード例 #17
0
    def test_map_to_no_pk_selectable(self):
        db = sqlsoup.SQLSoup(engine)

        table = Table('users', db._metadata, Column('id', Integer))
        assert_raises_message(sqlsoup.SQLSoupError,
                              "table 'users' does not have a primary ",
                              db.map_to,
                              'users',
                              selectable=table)
コード例 #18
0
ファイル: test_sqlsoup.py プロジェクト: kenwilcox/sqlsoup
    def test_map_to_attr_present(self):
        db = sqlsoup.SQLSoup(engine)

        users = db.users
        assert_raises_message(
            sqlsoup.SQLSoupError,
            "Attribute 'users' is already mapped",
            db.map_to, 'users', tablename='users'
        )
コード例 #19
0
    def test_map_to_attr_present(self):
        db = sqlsoup.SQLSoup(engine)

        users = db.users
        assert_raises_message(sqlsoup.SQLSoupError,
                              "Attribute 'users' is already mapped",
                              db.map_to,
                              'users',
                              tablename='users')
コード例 #20
0
ファイル: test_sqlsoup.py プロジェクト: kenwilcox/sqlsoup
    def test_map_to_no_pk_selectable(self):
        db = sqlsoup.SQLSoup(engine)

        table = Table('users', db._metadata, Column('id', Integer))
        assert_raises_message(
            sqlsoup.SQLSoupError,
            "table 'users' does not have a primary ",
            db.map_to, 'users', selectable=table
        )
コード例 #21
0
ファイル: test_sqlsoup.py プロジェクト: kenwilcox/sqlsoup
    def test_map_to_nothing(self):
        db = sqlsoup.SQLSoup(engine)

        assert_raises_message(
            sqlsoup.ArgumentError,
            "'tablename' or 'selectable' argument is "
                                    "required.",
            db.map_to, 'users',
        )
コード例 #22
0
ファイル: test_sqlsoup.py プロジェクト: kenwilcox/sqlsoup
    def test_map_to_table_not_string(self):
        db = sqlsoup.SQLSoup(engine)

        table = Table('users', db._metadata, Column('id', Integer, primary_key=True))
        assert_raises_message(
            sqlsoup.ArgumentError,
            "'tablename' argument must be a string.",
            db.map_to, 'users', tablename=table
        )
コード例 #23
0
ファイル: test_sqlsoup.py プロジェクト: kenwilcox/sqlsoup
    def test_map_to_table_or_selectable(self):
        db = sqlsoup.SQLSoup(engine)

        table = Table('users', db._metadata, Column('id', Integer, primary_key=True))
        assert_raises_message(
            sqlsoup.ArgumentError,
            "'tablename' and 'selectable' arguments are mutually exclusive",
            db.map_to, 'users', tablename='users', selectable=table
        )
コード例 #24
0
    def test_starting_rev_current_pre_context(self):
        env_file_fixture("""
assert context.get_starting_revision_argument() is None
""")
        assert_raises_message(
            util.CommandError,
            "No starting revision argument is available.",
            command.current, self.cfg
        )
コード例 #25
0
ファイル: test_sqlite.py プロジェクト: witsch/alembic
def test_drop_explicit_constraint():
    context = op_fixture('sqlite')
    assert_raises_message(
        NotImplementedError,
        "No support for ALTER of constraints in SQLite dialect",
        op.drop_constraint,
        "foo",
        "sometable",
    )
コード例 #26
0
def test_invalid_relative_downgrade_path():
    assert_raises_message(util.CommandError,
                          "Relative revision -5 didn't produce 5 migrations",
                          env._downgrade_revs, "-5", b.revision)

    assert_raises_message(
        util.CommandError,
        r"Relative revision \+2 didn't produce 2 migrations",
        env._downgrade_revs, "+2", b.revision)
コード例 #27
0
ファイル: test_sqlite.py プロジェクト: 6si/alembic
def test_drop_explicit_constraint():
    context = op_fixture('sqlite')
    assert_raises_message(
        NotImplementedError,
        "No support for ALTER of constraints in SQLite dialect",
        op.drop_constraint,
        "foo",
        "sometable",
    )
コード例 #28
0
ファイル: test_mssql.py プロジェクト: Lifto/alembic
 def test_alter_column_nullable_type_required(self):
     context = op_fixture('mssql')
     assert_raises_message(
         util.CommandError,
         "MS-SQL ALTER COLUMN operations with NULL or "
         "NOT NULL require the existing_type or a new "
         "type_ be passed.",
         op.alter_column, "t", "c", nullable=False
     )
コード例 #29
0
    def test_map_to_nothing(self):
        db = sqlsoup.SQLSoup(engine)

        assert_raises_message(
            sqlsoup.ArgumentError,
            "'tablename' or 'selectable' argument is "
            "required.",
            db.map_to,
            'users',
        )
コード例 #30
0
    def test_map_to_table_not_string(self):
        db = sqlsoup.SQLSoup(engine)

        table = Table('users', db._metadata,
                      Column('id', Integer, primary_key=True))
        assert_raises_message(sqlsoup.ArgumentError,
                              "'tablename' argument must be a string.",
                              db.map_to,
                              'users',
                              tablename=table)
コード例 #31
0
ファイル: test_sqlsoup.py プロジェクト: kenwilcox/sqlsoup
    def test_map_to_string_not_selectable(self):
        db = sqlsoup.SQLSoup(engine)

        assert_raises_message(
            sqlsoup.ArgumentError,
            "'selectable' argument must be a "
                                    "table, select, join, or other "
                                    "selectable construct.",
            db.map_to, 'users', selectable='users'
        )
コード例 #32
0
    def test_map_to_string_not_selectable(self):
        db = sqlsoup.SQLSoup(engine)

        assert_raises_message(sqlsoup.ArgumentError,
                              "'selectable' argument must be a "
                              "table, select, join, or other "
                              "selectable construct.",
                              db.map_to,
                              'users',
                              selectable='users')
コード例 #33
0
 def test_alter_column_nullable_type_required(self):
     context = op_fixture('mssql')
     assert_raises_message(util.CommandError,
                           "MS-SQL ALTER COLUMN operations with NULL or "
                           "NOT NULL require the existing_type or a new "
                           "type_ be passed.",
                           op.alter_column,
                           "t",
                           "c",
                           nullable=False)
コード例 #34
0
ファイル: test_sqlite.py プロジェクト: 6si/alembic
def test_add_explicit_constraint():
    context = op_fixture('sqlite')
    assert_raises_message(
        NotImplementedError,
        "No support for ALTER of constraints in SQLite dialect",
        op.create_check_constraint,
        "foo",
        "sometable",
        column('name') > 5
    )
コード例 #35
0
    def test_downgrade_wo_colon(self):
        env_file_fixture("""
context.configure(dialect_name='sqlite')
""")
        assert_raises_message(
            util.CommandError,
            "downgrade with --sql requires <fromrev>:<torev>",
            command.downgrade,
            self.cfg, b, sql=True
        )
コード例 #36
0
ファイル: test_sqlsoup.py プロジェクト: kenwilcox/sqlsoup
    def test_map_to_invalid_schema(self):
        db = sqlsoup.SQLSoup(engine)

        table = Table('users', db._metadata, Column('id', Integer))
        assert_raises_message(
            sqlsoup.ArgumentError,
            "'tablename' argument is required when "
                                "using 'schema'.",
            db.map_to, 'users', selectable=table, schema='hoho'
        )
コード例 #37
0
ファイル: test_op.py プロジェクト: briandailey/alembic
def test_cant_op():
    if hasattr(op, '_proxy'):
        del op._proxy
    assert_raises_message(
        NameError,
        "Can't invoke function 'inline_literal', as the "
        "proxy object has not yet been established "
        "for the Alembic 'Operations' class.  "
        "Try placing this code inside a callable.",
        op.inline_literal, "asdf"
    )
コード例 #38
0
    def test_map_to_invalid_schema(self):
        db = sqlsoup.SQLSoup(engine)

        table = Table('users', db._metadata, Column('id', Integer))
        assert_raises_message(sqlsoup.ArgumentError,
                              "'tablename' argument is required when "
                              "using 'schema'.",
                              db.map_to,
                              'users',
                              selectable=table,
                              schema='hoho')
コード例 #39
0
ファイル: test_op.py プロジェクト: shadowmint/py-test-watcher
def test_cant_op():
    if hasattr(op, '_proxy'):
        del op._proxy
    assert_raises_message(
        NameError,
        "Can't invoke function 'inline_literal', as the "
        "proxy object has not yet been established "
        "for the Alembic 'Operations' class.  "
        "Try placing this code inside a callable.",
        op.inline_literal, "asdf"
    )
コード例 #40
0
ファイル: test_revision_paths.py プロジェクト: Lifto/alembic
def test_invalid_relative_upgrade_path():
    assert_raises_message(
        util.CommandError,
        "Relative revision -2 didn't produce 2 migrations",
        env._upgrade_revs, "-2", b.revision
    )

    assert_raises_message(
        util.CommandError,
        r"Relative revision \+5 didn't produce 5 migrations",
        env._upgrade_revs, "+5", b.revision
    )
コード例 #41
0
    def test_map_to_table_or_selectable(self):
        db = sqlsoup.SQLSoup(engine)

        table = Table('users', db._metadata,
                      Column('id', Integer, primary_key=True))
        assert_raises_message(
            sqlsoup.ArgumentError,
            "'tablename' and 'selectable' arguments are mutually exclusive",
            db.map_to,
            'users',
            tablename='users',
            selectable=table)
コード例 #42
0
def test_invalid_format():
    context, t1 = _table_fixture("sqlite", False)
    assert_raises_message(
        TypeError,
        "List expected",
        op.bulk_insert, t1, {"id":5}
    )

    assert_raises_message(
        TypeError,
        "List of dictionaries expected",
        op.bulk_insert, t1, [(5, )]
    )
コード例 #43
0
    def test_error_on_new_with_missing_revision(self):
        self.cfg.set_main_option("file_template", "%%(slug)s_%%(rev)s")
        script = ScriptDirectory.from_config(self.cfg)
        a = util.rev_id()
        script.generate_revision(a, "foobar", refresh=True)
        assert_raises_message(
            util.CommandError,
            "Could not determine revision id from filename foobar_%s.py. "
            "Be sure the 'revision' variable is declared "
            "inside the script." % a, write_script, script, a, """
        down_revision = None

        from alembic import op

        def upgrade():
            op.execute("CREATE TABLE foo(id integer)")

        def downgrade():
            op.execute("DROP TABLE foo")

        """)
コード例 #44
0
ファイル: test_revision_paths.py プロジェクト: Lifto/alembic
def test_invalid_move_higher_to_lower():
    assert_raises_message(
       util.CommandError,
        "Revision %s is not an ancestor of %s" % (c.revision, b.revision),
        env._downgrade_revs, c.revision[0:4], b.revision
    )
コード例 #45
0
ファイル: test_revision_paths.py プロジェクト: Lifto/alembic
def test_invalid_move_rev_to_none():
    assert_raises_message(
        util.CommandError,
        "Revision %s is not an ancestor of base" % b.revision,
        env._downgrade_revs, b.revision[0:3], None
    )
コード例 #46
0
def test_invalid_move_higher_to_lower():
    assert_raises_message(
        util.CommandError,
        "Revision %s is not an ancestor of %s" % (c.revision, b.revision),
        env._downgrade_revs, c.revision[0:4], b.revision)
コード例 #47
0
def test_invalid_move_rev_to_none():
    assert_raises_message(
        util.CommandError,
        "Revision %s is not an ancestor of base" % b.revision,
        env._downgrade_revs, b.revision[0:3], None)