You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.3 KiB
86 lines
2.3 KiB
4 years ago
|
import pytest
|
||
2 years ago
|
from scripttease.exceptions import InvalidInput
|
||
|
from scripttease.lib.commands.mysql import *
|
||
4 years ago
|
|
||
|
|
||
|
def test_mysql_create():
|
||
|
c = mysql_create("testing", owner="bob", password="P455W0rD")
|
||
|
s = c.get_statement()
|
||
|
assert "mysqladmin" in s
|
||
|
assert '--password="P455W0rD"' in s
|
||
|
assert "--host=" in s
|
||
|
assert "--port=" in s
|
||
|
assert '--execute="GRANT ALL ON testing.* TO \'bob\'@\'localhost\'"' in s
|
||
|
|
||
|
|
||
|
def test_mysql_drop():
|
||
|
c = mysql_drop("testing")
|
||
|
s = c.get_statement()
|
||
|
assert "mysqladmin" in s
|
||
|
assert "drop testing" in s
|
||
|
|
||
|
|
||
|
def test_mysql_dump():
|
||
2 years ago
|
c = mysql_dump("testing", complete_inserts=True)
|
||
4 years ago
|
s = c.get_statement()
|
||
|
assert "mysqldump" in s
|
||
|
assert "--complete-inserts" in s
|
||
|
assert "> testing.sql" in s
|
||
|
|
||
|
|
||
2 years ago
|
# def test_mysql_exec():
|
||
|
# c = mysql("SELECT * FROM projects", database="testing")
|
||
|
# s = c.get_statement()
|
||
|
# assert "mysql" in s
|
||
|
# assert "--execute=" in s
|
||
|
# assert '"SELECT * FROM projects"' in s
|
||
4 years ago
|
|
||
|
|
||
|
def test_mysql_exists():
|
||
|
c = mysql_exists("testing")
|
||
|
s = c.get_statement()
|
||
|
assert "mysql" in s
|
||
2 years ago
|
assert "testing_exists" in s
|
||
4 years ago
|
|
||
|
|
||
|
def test_mysql_grant():
|
||
|
c = mysql_grant("bob", database="testing")
|
||
|
s = c.get_statement()
|
||
|
assert "mysql" in s
|
||
|
assert "GRANT" in s
|
||
|
assert "testing.*" in s
|
||
|
assert "'bob'@'localhost'" in s
|
||
|
|
||
|
|
||
2 years ago
|
def test_mysql_load():
|
||
|
c = mysql_load("testing", "path/to/file.sql", bogus=1)
|
||
|
s = c.get_statement()
|
||
|
assert "mysql" in s
|
||
|
assert "testing" in s
|
||
|
assert "< path/to/file.sql" in s
|
||
|
assert "--bogus=1" in s # to test passing any key
|
||
|
|
||
|
|
||
4 years ago
|
def test_mysql_user():
|
||
2 years ago
|
c = mysql_user("bob", password="secret")
|
||
4 years ago
|
s = c.get_statement()
|
||
|
assert "mysql" in s
|
||
|
assert "CREATE USER IF NOT EXISTS" in s
|
||
|
assert "'bob'@'localhost'" in s
|
||
|
assert "IDENTIFIED BY PASSWORD('secret')" in s
|
||
|
|
||
|
c = mysql_user("bob", op="drop", passwd="secret")
|
||
|
s = c.get_statement()
|
||
|
assert "mysql" in s
|
||
|
assert "DROP USER IF EXISTS" in s
|
||
|
assert "'bob'@'localhost'" in s
|
||
|
|
||
|
c = mysql_user("bob", op="exists", passwd="secret")
|
||
|
s = c.get_statement()
|
||
|
assert "mysql" in s
|
||
|
assert "mysql_user_exists" in s
|
||
|
assert "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'bob')" in s
|
||
|
|
||
2 years ago
|
with pytest.raises(InvalidInput):
|
||
4 years ago
|
mysql_user("bob", op="nonexistent")
|