def test_begin_comit(): with capture_context_buffer(transactional_ddl=True) as buf: command.upgrade(cfg, a, sql=True) assert "BEGIN;" in buf.getvalue() assert "COMMIT;" in buf.getvalue() with capture_context_buffer(transactional_ddl=False) as buf: command.upgrade(cfg, a, sql=True) assert "BEGIN;" not in buf.getvalue() assert "COMMIT;" not in buf.getvalue()
def test_offline_inline_enum_drop(self): self._inline_enum_script() with capture_context_buffer() as buf: command.downgrade(self.cfg, "%s:base" % self.rid, sql=True) assert "DROP TABLE sometable" in buf.getvalue() # no drop since we didn't emit events assert "DROP TYPE pgenum" not in buf.getvalue()
def test_version_from_middle_update(): with capture_context_buffer() as buf: command.upgrade(cfg, "%s:%s" % (b, c), sql=True) assert "CREATE TABLE alembic_version" not in buf.getvalue() assert "UPDATE alembic_version" in buf.getvalue() assert "CREATE STEP 1" not in buf.getvalue() assert "CREATE STEP 2" not in buf.getvalue() assert "CREATE STEP 3" in buf.getvalue()
def test_version_from_none_insert(): with capture_context_buffer() as buf: command.upgrade(cfg, a, sql=True) assert "CREATE TABLE alembic_version" in buf.getvalue() assert "INSERT INTO alembic_version" in buf.getvalue() assert "CREATE STEP 1" in buf.getvalue() assert "CREATE STEP 2" not in buf.getvalue() assert "CREATE STEP 3" not in buf.getvalue()
def test_version_to_none(self): with capture_context_buffer() as buf: command.downgrade(cfg, "%s:base" % c, sql=True) assert "CREATE TABLE alembic_version" not in buf.getvalue() assert "INSERT INTO alembic_version" not in buf.getvalue() assert "DROP TABLE alembic_version" in buf.getvalue() assert "DROP STEP 3" in buf.getvalue() assert "DROP STEP 2" in buf.getvalue() assert "DROP STEP 1" in buf.getvalue()
def test_version_to_middle(): with capture_context_buffer() as buf: command.downgrade(cfg, "%s:%s" % (c, a), sql=True) assert "CREATE TABLE alembic_version" not in buf.getvalue() assert "INSERT INTO alembic_version" not in buf.getvalue() assert "DROP TABLE alembic_version" not in buf.getvalue() assert "DROP STEP 3" in buf.getvalue() assert "DROP STEP 2" in buf.getvalue() assert "DROP STEP 1" not in buf.getvalue()
def test_batch_separator_default(self): with capture_context_buffer() as buf: command.upgrade(self.cfg, self.a, sql=True) assert "/" in buf.getvalue() assert ";" not in buf.getvalue()
def test_begin_comit(self): with capture_context_buffer(transactional_ddl=True) as buf: command.upgrade(self.cfg, self.a, sql=True) assert "SET TRANSACTION READ WRITE\n\n/" in buf.getvalue() assert "COMMIT\n\n/" in buf.getvalue()
def test_offline_distinct_enum_drop(self): self._distinct_enum_script() with capture_context_buffer() as buf: command.downgrade(self.cfg, "%s:base" % self.rid, sql=True) assert "DROP TABLE sometable" in buf.getvalue() assert "DROP TYPE pgenum" in buf.getvalue()
def test_offline_distinct_enum_create(self): self._distinct_enum_script() with capture_context_buffer() as buf: command.upgrade(self.cfg, self.rid, sql=True) assert "CREATE TYPE pgenum AS ENUM ('one','two','three')" in buf.getvalue() assert "CREATE TABLE sometable (\n data pgenum\n)" in buf.getvalue()
def test_batch_separator_default(self): with capture_context_buffer() as buf: command.upgrade(self.cfg, self.a, sql=True) assert "GO" in buf.getvalue()
def test_batch_separator_custom(self): with capture_context_buffer(oracle_batch_separator="BYE") as buf: command.upgrade(self.cfg, self.a, sql=True) assert "BYE" in buf.getvalue()
def test_begin_comit(self): with capture_context_buffer(transactional_ddl=True) as buf: command.upgrade(self.cfg, self.a, sql=True) assert "BEGIN TRANSACTION;" in buf.getvalue() assert "COMMIT;" in buf.getvalue()
def test_stamp(): with capture_context_buffer() as buf: command.stamp(cfg, "head", sql=True) assert "UPDATE alembic_version SET version_num='%s';" % c in buf.getvalue()
def test_batch_separator_custom(self): with capture_context_buffer(mssql_batch_separator="BYE") as buf: command.upgrade(self.cfg, self.a, sql=True) assert "BYE" in buf.getvalue()
def test_encode(self): with capture_context_buffer(output_encoding='utf-8') as buf: command.upgrade(cfg, a, sql=True) assert "« S’il vous plaît…".encode("utf-8") in buf.getvalue()