Ejemplo n.º 1
0
class TestCheckOperator(unittest.TestCase):
    def setUp(self):
        self._operator = SQLCheckOperator(task_id="test_task", sql="sql")

    @mock.patch.object(SQLCheckOperator, "get_db_hook")
    def test_execute_no_records(self, mock_get_db_hook):
        mock_get_db_hook.return_value.get_first.return_value = []

        with pytest.raises(AirflowException, match=r"The query returned None"):
            self._operator.execute()

    @mock.patch.object(SQLCheckOperator, "get_db_hook")
    def test_execute_not_all_records_are_true(self, mock_get_db_hook):
        mock_get_db_hook.return_value.get_first.return_value = ["data", ""]

        with pytest.raises(AirflowException, match=r"Test failed."):
            self._operator.execute()
Ejemplo n.º 2
0
    schema='public',
    table='artists',
    truncate=False,
    redshift_conn_id='redshift')

load_time = LoadDimensionOperator(
    task_id='load_dim_time',
    dag=dag,
    insert_table_sql=insert_tables.time,
    schema='public',
    table='time',
    truncate=False,
    redshift_conn_id='redshift')

dq_songplays = SQLCheckOperator(task_id='dq_songplays',
                                dag=dag,
                                conn_id='redshift',
                                sql=quality_checks.songplays)

dq_users = SQLCheckOperator(task_id='dq_users',
                            dag=dag,
                            conn_id='redshift',
                            sql=quality_checks.users)

dq_songs = SQLCheckOperator(task_id='dq_songs',
                            dag=dag,
                            conn_id='redshift',
                            sql=quality_checks.songs)

dq_artists = SQLCheckOperator(task_id='dq_artists',
                              dag=dag,
                              conn_id='redshift',
Ejemplo n.º 3
0
 def setUp(self):
     self._operator = SQLCheckOperator(task_id="test_task", sql="sql")
Ejemplo n.º 4
0
 def setup_method(self):
     self.task_id = "test_task"
     self.conn_id = "sql_default"
     self._operator = SQLCheckOperator(task_id=self.task_id,
                                       conn_id=self.conn_id,
                                       sql="sql")