summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/conftest.py6
-rw-r--r--test/test_completion_engine.py7
-rw-r--r--test/test_main.py22
-rw-r--r--test/test_sqlexecute.py3
-rw-r--r--test/utils.py4
5 files changed, 35 insertions, 7 deletions
diff --git a/test/conftest.py b/test/conftest.py
index d7d10ce..1325596 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -6,8 +6,8 @@ import mycli.sqlexecute
@pytest.fixture(scope="function")
def connection():
- create_db('_test_db')
- connection = db_connection('_test_db')
+ create_db('mycli_test_db')
+ connection = db_connection('mycli_test_db')
yield connection
connection.close()
@@ -22,7 +22,7 @@ def cursor(connection):
@pytest.fixture
def executor(connection):
return mycli.sqlexecute.SQLExecute(
- database='_test_db', user=USER,
+ database='mycli_test_db', user=USER,
host=HOST, password=PASSWORD, port=PORT, socket=None, charset=CHARSET,
local_infile=False, ssl=None, ssh_user=SSH_USER, ssh_host=SSH_HOST,
ssh_port=SSH_PORT, ssh_password=None, ssh_key_filename=None
diff --git a/test/test_completion_engine.py b/test/test_completion_engine.py
index 8b06ed3..318b632 100644
--- a/test/test_completion_engine.py
+++ b/test/test_completion_engine.py
@@ -542,7 +542,14 @@ def test_favorite_name_suggestion(expression):
suggestions = suggest_type(expression, expression)
assert suggestions == [{'type': 'favoritequery'}]
+
def test_order_by():
text = 'select * from foo order by '
suggestions = suggest_type(text, text)
assert suggestions == [{'tables': [(None, 'foo', None)], 'type': 'column'}]
+
+
+def test_quoted_where():
+ text = "'where i=';"
+ suggestions = suggest_type(text, text)
+ assert suggestions == [{'type': 'keyword'}]
diff --git a/test/test_main.py b/test/test_main.py
index 7731603..64cba0a 100644
--- a/test/test_main.py
+++ b/test/test_main.py
@@ -25,7 +25,7 @@ os.environ['MYSQL_TEST_LOGIN_FILE'] = login_path_file
CLI_ARGS = ['--user', USER, '--host', HOST, '--port', PORT,
'--password', PASSWORD, '--myclirc', default_config_file,
'--defaults-file', default_config_file,
- '_test_db']
+ 'mycli_test_db']
@dbtest
@@ -283,6 +283,20 @@ def test_list_dsn():
assert result.output == "test : mysql://test/test\n"
+def test_prettify_statement():
+ statement = 'SELECT 1'
+ m = MyCli()
+ pretty_statement = m.handle_prettify_binding(statement)
+ assert pretty_statement == 'SELECT\n 1;'
+
+
+def test_unprettify_statement():
+ statement = 'SELECT\n 1'
+ m = MyCli()
+ unpretty_statement = m.handle_unprettify_binding(statement)
+ assert unpretty_statement == 'SELECT 1;'
+
+
def test_list_ssh_config():
runner = CliRunner()
with NamedTemporaryFile(mode="w") as ssh_config:
@@ -305,19 +319,25 @@ def test_dsn(monkeypatch):
# Setup classes to mock mycli.main.MyCli
class Formatter:
format_name = None
+
class Logger:
def debug(self, *args, **args_dict):
pass
+
def warning(self, *args, **args_dict):
pass
+
class MockMyCli:
config = {'alias_dsn': {}}
+
def __init__(self, **args):
self.logger = Logger()
self.destructive_warning = False
self.formatter = Formatter()
+
def connect(self, **args):
MockMyCli.connect_args = args
+
def run_query(self, query, new_line=True):
pass
diff --git a/test/test_sqlexecute.py b/test/test_sqlexecute.py
index 0f38a97..38ca5ef 100644
--- a/test/test_sqlexecute.py
+++ b/test/test_sqlexecute.py
@@ -71,7 +71,7 @@ def test_table_and_columns_query(executor):
@dbtest
def test_database_list(executor):
databases = executor.databases()
- assert '_test_db' in databases
+ assert 'mycli_test_db' in databases
@dbtest
@@ -276,6 +276,7 @@ def test_multiple_results(executor):
@pytest.mark.parametrize(
'version_string, species, parsed_version_string, version',
(
+ ('5.7.25-TiDB-v6.1.0','TiDB', '5.7.25', 50725),
('5.7.32-35', 'Percona', '5.7.32', 50732),
('5.7.32-0ubuntu0.18.04.1', 'MySQL', '5.7.32', 50732),
('10.5.8-MariaDB-1:10.5.8+maria~focal', 'MariaDB', '10.5.8', 100508),
diff --git a/test/utils.py b/test/utils.py
index 66b4194..ab12248 100644
--- a/test/utils.py
+++ b/test/utils.py
@@ -41,8 +41,8 @@ dbtest = pytest.mark.skipif(
def create_db(dbname):
with db_connection().cursor() as cur:
try:
- cur.execute('''DROP DATABASE IF EXISTS _test_db''')
- cur.execute('''CREATE DATABASE _test_db''')
+ cur.execute('''DROP DATABASE IF EXISTS mycli_test_db''')
+ cur.execute('''CREATE DATABASE mycli_test_db''')
except:
pass