summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Cope <olly@ollycope.com>2018-01-29 18:46:16 +0000
committerOlly Cope <olly@ollycope.com>2018-01-29 18:46:16 +0000
commit2e7b48fd1456e1e48e066bd37770b6bfd1c2f026 (patch)
tree64e61d1495c8a27248506d7f0d8d79abbb5094d3
parentc4e152e31f4f93fd06a84068a067d8270d94d625 (diff)
downloadyoyo-2e7b48fd1456e1e48e066bd37770b6bfd1c2f026.tar.gz
Backout double quoting in test modules
-rw-r--r--yoyo/backends.py6
-rw-r--r--yoyo/tests/conftest.py17
-rw-r--r--yoyo/tests/test_backends.py28
-rw-r--r--yoyo/tests/test_cli_script.py12
-rw-r--r--yoyo/tests/test_migrations.py86
5 files changed, 75 insertions, 74 deletions
diff --git a/yoyo/backends.py b/yoyo/backends.py
index 40d6b96..5b9f815 100644
--- a/yoyo/backends.py
+++ b/yoyo/backends.py
@@ -106,7 +106,7 @@ class DatabaseBackend(object):
driver_module = None
connection = None
- lock_table = '_yoyo_lock'
+ lock_table = 'yoyo_lock'
create_migration_table_sql = """
CREATE TABLE "{table_name}" (
id VARCHAR(255) NOT NULL PRIMARY KEY,
@@ -162,14 +162,14 @@ class DatabaseBackend(object):
Return True if the database supports committing/rolling back
DDL statements within a transaction
"""
- table_name = '_yoyo_tmp_{}'.format(utils.get_random_string(10))
+ table_name = 'yoyo_tmp_{}'.format(utils.get_random_string(10))
sql = self.create_test_table_sql.format(table_name=table_name)
with self.transaction() as t:
self.execute(sql)
t.rollback()
try:
with self.transaction():
- self.execute("DROP TABLE \"{}\"".format(table_name))
+ self.execute("DROP TABLE {}".format(table_name))
except self.DatabaseError:
return True
return False
diff --git a/yoyo/tests/conftest.py b/yoyo/tests/conftest.py
index 9e1d5fc..a5848c4 100644
--- a/yoyo/tests/conftest.py
+++ b/yoyo/tests/conftest.py
@@ -14,25 +14,26 @@ def backend(request):
backend = get_backend(request.param)
with backend.transaction():
if backend.__class__ is backends.MySQLBackend:
- backend.execute('CREATE TABLE "_yoyo_t" '
+ backend.execute('CREATE TABLE yoyo_t '
'(id CHAR(1) primary key) '
'ENGINE=InnoDB')
else:
- backend.execute('CREATE TABLE "_yoyo_t" '
+ backend.execute('CREATE TABLE yoyo_t '
'(id CHAR(1) primary key)')
try:
yield backend
finally:
backend.rollback()
+ drop_yoyo_tables(backend)
+
+
+def drop_yoyo_tables(backend):
for table in backend.list_tables():
- if table.startswith('_yoyo'):
+ if table.startswith('yoyo') or table.startswith('_yoyo'):
with backend.transaction():
- backend.execute('DROP TABLE {}'.format(table))
+ backend.execute("DROP TABLE {}".format(table))
def pytest_configure(config):
for backend in get_test_backends():
- for table in backend.list_tables():
- if table.startswith('_yoyo'):
- with backend.transaction():
- backend.execute("DROP TABLE \"{}\"".format(table))
+ drop_yoyo_tables(backend)
diff --git a/yoyo/tests/test_backends.py b/yoyo/tests/test_backends.py
index 9a522b7..27242ff 100644
--- a/yoyo/tests/test_backends.py
+++ b/yoyo/tests/test_backends.py
@@ -13,36 +13,36 @@ class TestTransactionHandling(object):
def test_it_commits(self, backend):
with backend.transaction():
- backend.execute("INSERT INTO \"_yoyo_t\" values ('A')")
+ backend.execute("INSERT INTO yoyo_t values ('A')")
with backend.transaction():
- rows = list(backend.execute("SELECT * FROM \"_yoyo_t\"").fetchall())
+ rows = list(backend.execute("SELECT * FROM yoyo_t").fetchall())
assert rows == [('A',)]
def test_it_rolls_back(self, backend):
with pytest.raises(backend.DatabaseError):
with backend.transaction():
- backend.execute("INSERT INTO \"_yoyo_t\" values ('A')")
+ backend.execute("INSERT INTO yoyo_t values ('A')")
# Invalid SQL to produce an error
backend.execute("INSERT INTO nonexistant values ('A')")
with backend.transaction():
- rows = list(backend.execute("SELECT * FROM \"_yoyo_t\"").fetchall())
+ rows = list(backend.execute("SELECT * FROM yoyo_t").fetchall())
assert rows == []
def test_it_nests_transactions(self, backend):
with backend.transaction():
- backend.execute("INSERT INTO \"_yoyo_t\" values ('A')")
+ backend.execute("INSERT INTO yoyo_t values ('A')")
with backend.transaction() as trans:
- backend.execute("INSERT INTO \"_yoyo_t\" values ('B')")
+ backend.execute("INSERT INTO yoyo_t values ('B')")
trans.rollback()
with backend.transaction() as trans:
- backend.execute("INSERT INTO \"_yoyo_t\" values ('C')")
+ backend.execute("INSERT INTO yoyo_t values ('C')")
with backend.transaction():
- rows = list(backend.execute("SELECT * FROM \"_yoyo_t\"").fetchall())
+ rows = list(backend.execute("SELECT * FROM yoyo_t").fetchall())
assert rows == [('A',), ('C',)]
def test_backend_detects_transactional_ddl(self, backend):
@@ -65,17 +65,17 @@ class TestTransactionHandling(object):
return
with backend.transaction() as trans:
- backend.execute("CREATE TABLE \"_yoyo_a\" (id INT)") # implicit commit
- backend.execute("INSERT INTO \"_yoyo_a\" VALUES (1)")
- backend.execute("CREATE TABLE \"_yoyo_b\" (id INT)") # implicit commit
- backend.execute("INSERT INTO \"_yoyo_b\" VALUES (1)")
+ backend.execute("CREATE TABLE yoyo_a (id INT)") # implicit commit
+ backend.execute("INSERT INTO yoyo_a VALUES (1)")
+ backend.execute("CREATE TABLE yoyo_b (id INT)") # implicit commit
+ backend.execute("INSERT INTO yoyo_b VALUES (1)")
trans.rollback()
- count_a = backend.execute("SELECT COUNT(1) FROM \"_yoyo_a\"")\
+ count_a = backend.execute("SELECT COUNT(1) FROM yoyo_a")\
.fetchall()[0][0]
assert count_a == 1
- count_b = backend.execute("SELECT COUNT(1) FROM \"_yoyo_b\"")\
+ count_b = backend.execute("SELECT COUNT(1) FROM yoyo_b")\
.fetchall()[0][0]
assert count_b == 0
diff --git a/yoyo/tests/test_cli_script.py b/yoyo/tests/test_cli_script.py
index 229a2b5..54d67e8 100644
--- a/yoyo/tests/test_cli_script.py
+++ b/yoyo/tests/test_cli_script.py
@@ -155,8 +155,8 @@ class TestYoyoScript(TestInteractiveScript):
assert get_backend().rollback_migrations.call_count == 1
assert get_backend().apply_migrations.call_count == 1
- @with_migrations(m1='step("CREATE TABLE \\\"_yoyo_test1\\\" (id INT)")')
- @with_migrations(m2='step("CREATE TABLE \\\"_yoyo_test2\\\" (id INT)")')
+ @with_migrations(m1='step("CREATE TABLE yoyo_test1 (id INT)")')
+ @with_migrations(m2='step("CREATE TABLE yoyo_test2 (id INT)")')
def test_it_applies_from_multiple_sources(self, t1, t2):
with patch('yoyo.backends.DatabaseBackend.apply_migrations') \
as apply:
@@ -220,11 +220,11 @@ class TestYoyoScript(TestInteractiveScript):
with with_migrations(m1=('import time\n'
'step(lambda conn: time.sleep(0.1))\n'
- 'step("INSERT INTO _yoyo_t VALUES (\'A\')")')
+ 'step("INSERT INTO yoyo_t VALUES (\'A\')")')
) as tmpdir:
- assert '_yoyo_t' in backend.list_tables()
+ assert 'yoyo_t' in backend.list_tables()
backend.rollback()
- backend.execute("SELECT * FROM _yoyo_t")
+ backend.execute("SELECT * FROM yoyo_t")
run_migrations = partial(
main,
['apply', '-b', tmpdir, '--database', str(backend.uri)])
@@ -237,7 +237,7 @@ class TestYoyoScript(TestInteractiveScript):
# Exactly one instance of the migration script should have succeeded
backend.rollback()
- cursor = backend.execute('SELECT COUNT(1) from _yoyo_t')
+ cursor = backend.execute('SELECT COUNT(1) from yoyo_t')
assert cursor.fetchone()[0] == 1
diff --git a/yoyo/tests/test_migrations.py b/yoyo/tests/test_migrations.py
index 6617763..ad20e22 100644
--- a/yoyo/tests/test_migrations.py
+++ b/yoyo/tests/test_migrations.py
@@ -27,11 +27,11 @@ from yoyo.scripts import newmigration
@with_migrations(
"""
- step("CREATE TABLE \\\"_yoyo_test\\\" (id INT)")
+ step("CREATE TABLE yoyo_test (id INT)")
""",
"""
-step("INSERT INTO \\\"_yoyo_test\\\" VALUES (1)")
-step("INSERT INTO \\\"_yoyo_test\\\" VALUES ('x', 'y')")
+step("INSERT INTO yoyo_test VALUES (1)")
+step("INSERT INTO yoyo_test VALUES ('x', 'y')")
""")
def test_transaction_is_not_committed_on_error(tmpdir):
backend = get_backend(dburi)
@@ -39,15 +39,15 @@ def test_transaction_is_not_committed_on_error(tmpdir):
with pytest.raises(backend.DatabaseError):
backend.apply_migrations(migrations)
cursor = backend.cursor()
- cursor.execute("SELECT count(1) FROM \"_yoyo_test\"")
+ cursor.execute("SELECT count(1) FROM yoyo_test")
assert cursor.fetchone() == (0,)
@with_migrations(
- 'step("CREATE TABLE \\\"_yoyo_test\\\" (id INT)")',
+ 'step("CREATE TABLE yoyo_test (id INT)")',
'''
-step("INSERT INTO \\\"_yoyo_test\\\" VALUES (1)", "DELETE FROM \\\"_yoyo_test\\\" WHERE id=1")
-step("UPDATE \\\"_yoyo_test\\\" SET id=2 WHERE id=1", "UPDATE \\\"_yoyo_test\\\" SET id=1 WHERE id=2")
+step("INSERT INTO yoyo_test VALUES (1)", "DELETE FROM yoyo_test WHERE id=1")
+step("UPDATE yoyo_test SET id=2 WHERE id=1", "UPDATE yoyo_test SET id=1 WHERE id=2")
'''
)
def test_rollbacks_happen_in_reverse(tmpdir):
@@ -55,19 +55,19 @@ def test_rollbacks_happen_in_reverse(tmpdir):
migrations = read_migrations(tmpdir)
backend.apply_migrations(migrations)
cursor = backend.cursor()
- cursor.execute("SELECT * FROM \"_yoyo_test\"")
+ cursor.execute("SELECT * FROM yoyo_test")
assert cursor.fetchall() == [(2,)]
backend.rollback_migrations(migrations)
- cursor.execute("SELECT * FROM \"_yoyo_test\"")
+ cursor.execute("SELECT * FROM yoyo_test")
assert cursor.fetchall() == []
@with_migrations(
'''
- step("CREATE TABLE \\\"_yoyo_test\\\" (id INT)")
- step("INSERT INTO \\\"_yoyo_test\\\" VALUES (1)")
- step("INSERT INTO \\\"_yoyo_test\\\" VALUES ('a', 'b')", ignore_errors='all')
- step("INSERT INTO \\\"_yoyo_test\\\" VALUES (2)")
+ step("CREATE TABLE yoyo_test (id INT)")
+ step("INSERT INTO yoyo_test VALUES (1)")
+ step("INSERT INTO yoyo_test VALUES ('a', 'b')", ignore_errors='all')
+ step("INSERT INTO yoyo_test VALUES (2)")
'''
)
def test_execution_continues_with_ignore_errors(tmpdir):
@@ -75,20 +75,20 @@ def test_execution_continues_with_ignore_errors(tmpdir):
migrations = read_migrations(tmpdir)
backend.apply_migrations(migrations)
cursor = backend.cursor()
- cursor.execute("SELECT * FROM \"_yoyo_test\"")
+ cursor.execute("SELECT * FROM yoyo_test")
assert cursor.fetchall() == [(1,), (2,)]
@with_migrations(
'''
from yoyo import step, group
- step("CREATE TABLE \\\"_yoyo_test\\\" (id INT)")
+ step("CREATE TABLE yoyo_test (id INT)")
group(
- step("INSERT INTO \\\"_yoyo_test\\\" VALUES (1)"),
- step("INSERT INTO \\\"_yoyo_test\\\" VALUES ('a', 'b')"),
+ step("INSERT INTO yoyo_test VALUES (1)"),
+ step("INSERT INTO yoyo_test VALUES ('a', 'b')"),
ignore_errors='all'
)
- step("INSERT INTO \\\"_yoyo_test\\\" VALUES (2)")
+ step("INSERT INTO yoyo_test VALUES (2)")
'''
)
def test_execution_continues_with_ignore_errors_in_transaction(tmpdir):
@@ -96,16 +96,16 @@ def test_execution_continues_with_ignore_errors_in_transaction(tmpdir):
migrations = read_migrations(tmpdir)
backend.apply_migrations(migrations)
cursor = backend.cursor()
- cursor.execute("SELECT * FROM \"_yoyo_test\"")
+ cursor.execute("SELECT * FROM yoyo_test")
assert cursor.fetchall() == [(2,)]
@with_migrations(
'''
- step("CREATE TABLE \\\"_yoyo_test\\\" (id INT)")
- step("INSERT INTO \\\"_yoyo_test\\\" VALUES (1)",
- "DELETE FROM \\\"_yoyo_test\\\" WHERE id=2")
- step("UPDATE \\\"_yoyo_test\\\" SET id=2 WHERE id=1",
+ step("CREATE TABLE yoyo_test (id INT)")
+ step("INSERT INTO yoyo_test VALUES (1)",
+ "DELETE FROM yoyo_test WHERE id=2")
+ step("UPDATE yoyo_test SET id=2 WHERE id=1",
"SELECT nonexistent FROM imaginary", ignore_errors='rollback')
'''
)
@@ -114,55 +114,55 @@ def test_rollbackignores_errors(tmpdir):
migrations = read_migrations(tmpdir)
backend.apply_migrations(migrations)
cursor = backend.cursor()
- cursor.execute("SELECT * FROM \"_yoyo_test\"")
+ cursor.execute("SELECT * FROM yoyo_test")
assert cursor.fetchall() == [(2,)]
backend.rollback_migrations(migrations)
- cursor.execute("SELECT * FROM \"_yoyo_test\"")
+ cursor.execute("SELECT * FROM yoyo_test")
assert cursor.fetchall() == []
def test_migration_is_committed(backend):
- with migrations_dir('step("CREATE TABLE \\\"_yoyo_test\\\" (id INT)")') as tmpdir:
+ with migrations_dir('step("CREATE TABLE yoyo_test (id INT)")') as tmpdir:
migrations = read_migrations(tmpdir)
backend.apply_migrations(migrations)
backend.rollback()
- rows = backend.execute("SELECT * FROM \"_yoyo_test\"").fetchall()
+ rows = backend.execute("SELECT * FROM yoyo_test").fetchall()
assert list(rows) == []
def test_rollback_happens_on_step_failure(backend):
with migrations_dir('''
step("",
- "CREATE TABLE \\\"_yoyo_is_rolledback\\\" (i INT)"),
- step("CREATE TABLE \\\"_yoyo_test\\\" (s VARCHAR(100))",
- "DROP TABLE \\\"_yoyo_test\\\"")
+ "CREATE TABLE yoyo_is_rolledback (i INT)"),
+ step("CREATE TABLE yoyo_test (s VARCHAR(100))",
+ "DROP TABLE yoyo_test")
step("invalid sql!")''') as tmpdir:
migrations = read_migrations(tmpdir)
with pytest.raises(backend.DatabaseError):
backend.apply_migrations(migrations)
- # The _yoyo_test table should have either been deleted (transactional ddl)
+ # The yoyo_test table should have either been deleted (transactional ddl)
# or dropped (non-transactional-ddl)
with pytest.raises(backend.DatabaseError):
- backend.execute("SELECT * FROM \"_yoyo_test\"")
+ backend.execute("SELECT * FROM yoyo_test")
# Transactional DDL: rollback steps not executed
if backend.has_transactional_ddl:
with pytest.raises(backend.DatabaseError):
- backend.execute("SELECT * FROM \"_yoyo_is_rolledback\"")
+ backend.execute("SELECT * FROM yoyo_is_rolledback")
# Non-transactional DDL: ensure the rollback steps were executed
else:
- cursor = backend.execute("SELECT * FROM \"_yoyo_is_rolledback\"")
+ cursor = backend.execute("SELECT * FROM yoyo_is_rolledback")
assert list(cursor.fetchall()) == []
@with_migrations(
'''
- step("CREATE TABLE \\\"_yoyo_test\\\" (id INT)")
- step("DROP TABLE \\\"_yoyo_test\\\"")
+ step("CREATE TABLE yoyo_test (id INT)")
+ step("DROP TABLE yoyo_test")
'''
)
def test_specify_migration_table(tmpdir):
@@ -199,8 +199,8 @@ def test_migration_functions_have_namespace_access(tmpdir):
@with_migrations(
'''
from yoyo import group, step
- step("CREATE TABLE \\\"_yoyo_test\\\" (id INT)")
- group(step("INSERT INTO \\\"_yoyo_test\\\" VALUES (1)")),
+ step("CREATE TABLE yoyo_test (id INT)")
+ group(step("INSERT INTO yoyo_test VALUES (1)")),
'''
)
def test_migrations_can_import_step_and_group(tmpdir):
@@ -208,16 +208,16 @@ def test_migrations_can_import_step_and_group(tmpdir):
migrations = read_migrations(tmpdir)
backend.apply_migrations(migrations)
cursor = backend.cursor()
- cursor.execute("SELECT id FROM \"_yoyo_test\"")
+ cursor.execute("SELECT id FROM yoyo_test")
assert cursor.fetchall() == [(1,)]
@with_migrations(
'''
- step("CREATE TABLE \\\"_yoyo_test\\\" (id INT, c VARCHAR(1))")
- step("INSERT INTO \\\"_yoyo_test\\\" VALUES (1, 'a')")
- step("INSERT INTO \\\"_yoyo_test\\\" VALUES (2, 'b')")
- step("SELECT * FROM \\\"_yoyo_test\\\"")
+ step("CREATE TABLE yoyo_test (id INT, c VARCHAR(1))")
+ step("INSERT INTO yoyo_test VALUES (1, 'a')")
+ step("INSERT INTO yoyo_test VALUES (2, 'b')")
+ step("SELECT * FROM yoyo_test")
'''
)
def test_migrations_display_selected_data(tmpdir):