A collection of classes and commands for automated command line scripting using Python.
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.
 
 

85 lines
2.3 KiB

import pytest
from scripttease.exceptions import InvalidInput
from scripttease.lib.commands.mysql import *
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():
c = mysql_dump("testing", complete_inserts=True)
s = c.get_statement()
assert "mysqldump" in s
assert "--complete-inserts" in s
assert "> testing.sql" in s
# 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
def test_mysql_exists():
c = mysql_exists("testing")
s = c.get_statement()
assert "mysql" in s
assert "testing_exists" in s
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
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
def test_mysql_user():
c = mysql_user("bob", password="secret")
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
with pytest.raises(InvalidInput):
mysql_user("bob", op="nonexistent")