コード例 #1
0
 def test_mysql_operator_test(self):
     sql = """
     CREATE TABLE IF NOT EXISTS test_airflow (
         dummy VARCHAR(50)
     );
     """
     op = MySqlOperator(task_id='basic_mysql', sql=sql, dag=self.dag)
     op.run(start_date=DEFAULT_DATE,
            end_date=DEFAULT_DATE,
            ignore_ti_state=True)
コード例 #2
0
 def test_mysql_operator_test_multi(self):
     sql = [
         "CREATE TABLE IF NOT EXISTS test_airflow (dummy VARCHAR(50))",
         "TRUNCATE TABLE test_airflow",
         "INSERT INTO test_airflow VALUES ('X')",
     ]
     from airflow.providers.mysql.operators.mysql import MySqlOperator
     op = MySqlOperator(
         task_id='mysql_operator_test_multi',
         sql=sql,
         dag=self.dag,
     )
     op.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True)
コード例 #3
0
 def test_mysql_operator_test_multi(self, client):
     with MySqlContext(client):
         sql = [
             "CREATE TABLE IF NOT EXISTS test_airflow (dummy VARCHAR(50))",
             "TRUNCATE TABLE test_airflow",
             "INSERT INTO test_airflow VALUES ('X')",
         ]
         op = MySqlOperator(
             task_id='mysql_operator_test_multi',
             sql=sql,
             dag=self.dag,
         )
         op.run(start_date=DEFAULT_DATE,
                end_date=DEFAULT_DATE,
                ignore_ti_state=True)
コード例 #4
0
    def test_overwrite_schema(self):
        """
        Verifies option to overwrite connection schema
        """
        sql = "SELECT 1;"
        op = MySqlOperator(
            task_id='test_mysql_operator_test_schema_overwrite',
            sql=sql,
            dag=self.dag,
            database="foobar",
        )

        from _mysql_exceptions import OperationalError
        try:
            op.run(start_date=DEFAULT_DATE,
                   end_date=DEFAULT_DATE,
                   ignore_ti_state=True)
        except OperationalError as e:
            assert "Unknown database 'foobar'" in str(e)
コード例 #5
0
    def test_overwrite_schema(self, client):
        """
        Verifies option to overwrite connection schema
        """
        with MySqlContext(client):
            sql = "SELECT 1;"
            op = MySqlOperator(
                task_id='test_mysql_operator_test_schema_overwrite',
                sql=sql,
                dag=self.dag,
                database="foobar",
            )

            from MySQLdb import OperationalError  # pylint: disable=no-name-in-module

            try:
                op.run(start_date=DEFAULT_DATE,
                       end_date=DEFAULT_DATE,
                       ignore_ti_state=True)
            except OperationalError as e:
                assert "Unknown database 'foobar'" in str(e)