def test_should_raise_exception_on_invalid_configuration(self, conn_uri): with mock.patch.dict("os.environ", AIRFLOW_CONN_KUBERNETES_DEFAULT=conn_uri ), self.assertRaisesRegex( AirflowException, "Invalid connection configuration"): kubernetes_hook = KubernetesHook() kubernetes_hook.get_conn()
def test_kube_config_path(self, mock_kube_config_loader, mock_kube_config_merger): kubernetes_hook = KubernetesHook(conn_id='kubernetes_kube_config_path') api_conn = kubernetes_hook.get_conn() mock_kube_config_loader.assert_called_once_with("path/to/file") mock_kube_config_merger.assert_called_once() self.assertIsInstance(api_conn, kubernetes.client.api_client.ApiClient)
def test_kube_config_connection(self, mock_kube_config_loader, mock_kube_config_merger, mock_tempfile): kubernetes_hook = KubernetesHook(conn_id='kubernetes_kube_config') api_conn = kubernetes_hook.get_conn() mock_tempfile.is_called_once() mock_kube_config_loader.assert_called_once() mock_kube_config_merger.assert_called_once() self.assertIsInstance(api_conn, kubernetes.client.api_client.ApiClient)
def test_default_kube_config_connection( self, mock_kube_config_loader, mock_kube_config_merger, ): kubernetes_hook = KubernetesHook( conn_id='kubernetes_default_kube_config') api_conn = kubernetes_hook.get_conn() mock_kube_config_loader.assert_called_once_with("/mock/config") mock_kube_config_merger.assert_called_once() self.assertIsInstance(api_conn, kubernetes.client.api_client.ApiClient)
def test_in_cluster_connection(self, mock_kube_config_loader): kubernetes_hook = KubernetesHook(conn_id='kubernetes_in_cluster') api_conn = kubernetes_hook.get_conn() mock_kube_config_loader.assert_called_once() self.assertIsInstance(api_conn, kubernetes.client.api_client.ApiClient)