]> git.phdru.name Git - sqlconvert.git/blob - tests/test_mysql2sqlite.py
Build(GHActions): Use `checkout@v4` instead of outdated `v2`
[sqlconvert.git] / tests / test_mysql2sqlite.py
1 from sqlparse import parse
2 from sqlobject.tests.dbtest import getConnection
3 import pytest
4
5 from sqlconvert.print_tokens import tlist2str
6 from sqlconvert.process_mysql import unescape_strings
7 from sqlconvert.process_tokens import escape_strings
8
9 connection = getConnection()
10 pytestmark = pytest.mark.skipif(connection.dbName != "sqlite",
11                                 reason="This test requires SQLite")
12
13 create_sqlite_test_table = """
14 CREATE TABLE test (
15     id INTEGER PRIMARY KEY AUTOINCREMENT,
16     test_str VARCHAR(255) NOT NULL
17 );
18 """
19
20
21 def test_mysql2sqlite_string():
22     connection.query(create_sqlite_test_table)
23     parsed = parse("insert into test (id, test_str) values "
24                    "(1, '\"te\\'st\\\"\\n')")[0]
25     unescape_strings(parsed)
26     escape_strings(parsed, 'sqlite')
27     query = tlist2str(parsed)
28     assert query == u"INSERT INTO test (id, test_str) VALUES " \
29                     u"(1, '\"te''st\"\n')"
30     connection.query(query)
31     test_str = connection.queryOne("SELECT test_str FROM test WHERE id=1")[0]
32     assert test_str == u"\"te'st\"\n"