def test_query_string_must_be_provided(self): task = MySQLExecute(db_name="test", user="******", password="******", host="test") with pytest.raises(ValueError, match="A query string must be provided"): task.run()
def test_run_args_used_over_init_args(self, monkeypatch): mock_connect = MagicMock() monkeypatch.setattr("pymysql.connect", mock_connect) task = MySQLExecute(db_name="test", user="******", password="******", host="test") task.run(query="select * from users", password="******") assert mock_connect.call_args[1]["password"] == "password_from_secret"
def test_construction(self): task = MySQLExecute(db_name="test", user="******", password="******", host="test") assert (task.commit is False) and (task.charset == "utf8mb4")
EXAMPLE_TABLE = "user" HOST = "localhost" PORT = 3306 DB_NAME = "ext" USER = "******" PASSWORD = "******" mysql_fetch = MySQLFetch(host=HOST, port=PORT, db_name=DB_NAME, user=USER, password=PASSWORD) mysql_exec = MySQLExecute(host=HOST, port=PORT, db_name=DB_NAME, user=USER, password=PASSWORD) @task def print_results(x): print(x) with Flow("MySQL Example") as flow: # fetch 3 results fetch_results = mysql_fetch(query=f"SELECT * FROM {EXAMPLE_TABLE}", fetch="many", fetch_count=3) print_results(fetch_results)