Exemple #1
0
    def test_execute(self, mock_hook):
        operator = KylinCubeOperator(
            task_id='kylin_task',
            dag=self.dag,
            **self._config
        )
        hook = MagicMock()
        hook.invoke_command = ['fullbuild', 'build', 'merge', 'refresh',
                               'delete', 'build_streaming', 'merge_streaming', 'refresh_streaming',
                               'disable', 'enable', 'purge', 'clone', 'drop']
        mock_hook.return_value = hook
        mock_hook.cube_run.return_value = {}

        self.assertIsNotNone(operator)
        self.assertEqual(self._config['kylin_conn_id'], operator.kylin_conn_id)
        self.assertEqual(self._config['project'], operator.project)
        self.assertEqual(self._config['cube'], operator.cube)
        self.assertEqual(self._config['command'], operator.command)
        self.assertEqual(self._config['start_time'], operator.start_time)
        self.assertEqual(self._config['end_time'], operator.end_time)
        operator.execute(None)
        mock_hook.assert_called_once_with(
            kylin_conn_id=self._config['kylin_conn_id'],
            project=self._config['project'],
            dsn=None
        )

        mock_hook.return_value.cube_run.assert_called_once_with('kylin_sales_cube',
                                                                'build',
                                                                end=datetime(2012, 1, 3, 0, 0),
                                                                name=None,
                                                                offset_end=None,
                                                                offset_start=None,
                                                                start=datetime(2012, 1, 2, 0, 0))
Exemple #2
0
    def test_execute_build_time_out_error(self, mock_hook):
        operator = KylinCubeOperator(is_track_job=True,
                                     timeout=5,
                                     interval=1,
                                     task_id='kylin_task',
                                     dag=self.dag,
                                     **self._config)
        hook = MagicMock()
        hook.invoke_command = self.cube_command
        hook.cube_run.return_value = self.build_response

        hook.get_job_status.return_value = "RUNNING"
        mock_hook.return_value = hook
        with pytest.raises(AirflowException):
            operator.execute(None)
Exemple #3
0
    def test_execute_build(self, mock_hook):
        operator = KylinCubeOperator(
            is_track_job=True, timeout=5, interval=1, task_id='kylin_task', dag=self.dag, **self._config
        )
        hook = MagicMock()
        hook.invoke_command = self.cube_command
        hook.cube_run.return_value = self.build_response

        hook.get_job_status.side_effect = ["RUNNING", "RUNNING", "FINISHED"]
        mock_hook.return_value = hook
        self.assertEqual(operator.execute(None)['uuid'], "c143e0e4-ac5f-434d-acf3-46b0d15e3dc6")