コード例 #1
0
ファイル: test_mysql.py プロジェクト: tchoedak/prefect
 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()
コード例 #2
0
ファイル: test_mysql.py プロジェクト: tchoedak/prefect
    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"
コード例 #3
0
ファイル: test_mysql.py プロジェクト: tchoedak/prefect
 def test_construction(self):
     task = MySQLExecute(db_name="test",
                         user="******",
                         password="******",
                         host="test")
     assert (task.commit is False) and (task.charset == "utf8mb4")
コード例 #4
0
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)