def test_correct_name(self, mock_hook): op = GcfFunctionDeleteOperator( name="projects/project_name/locations/project_location/functions" "/function_name", task_id="id") op.execute(None) mock_hook.assert_called_once_with(api_version='v1', gcp_conn_id='google_cloud_default')
def test_invalid_name(self, mock_hook): with self.assertRaises(AttributeError) as cm: op = GcfFunctionDeleteOperator(name="invalid_name", task_id="id") op.execute(None) err = cm.exception self.assertEqual( str(err), 'Parameter name must match pattern: {}'.format( FUNCTION_NAME_PATTERN)) mock_hook.assert_not_called()
def test_gcf_error_silenced_when_function_doesnt_exist(self, mock_hook): op = GcfFunctionDeleteOperator(name=self._FUNCTION_NAME, task_id="id") mock_hook.return_value.delete_function.side_effect = mock.Mock( side_effect=HttpError(resp=MOCK_RESP_404, content=b'not found')) op.execute(None) mock_hook.assert_called_once_with(api_version='v1', gcp_conn_id='google_cloud_default') mock_hook.return_value.delete_function.assert_called_once_with( 'projects/project_name/locations/project_location/functions/function_name' )
def test_non_404_gcf_error_bubbled_up(self, mock_hook): op = GcfFunctionDeleteOperator(name=self._FUNCTION_NAME, task_id="id") resp = type('', (object, ), {"status": 500})() mock_hook.return_value.delete_function.side_effect = mock.Mock( side_effect=HttpError(resp=resp, content=b'error')) with self.assertRaises(HttpError): op.execute(None) mock_hook.assert_called_once_with(api_version='v1', gcp_conn_id='google_cloud_default') mock_hook.return_value.delete_function.assert_called_once_with( 'projects/project_name/locations/project_location/functions/function_name' )
def test_delete_execute(self, mock_hook): mock_hook.return_value.delete_function.return_value = \ self._DELETE_FUNCTION_EXPECTED op = GcfFunctionDeleteOperator(name=self._FUNCTION_NAME, task_id="id") result = op.execute(None) mock_hook.assert_called_once_with(api_version='v1', gcp_conn_id='google_cloud_default') mock_hook.return_value.delete_function.assert_called_once_with( 'projects/project_name/locations/project_location/functions/function_name' ) self.assertEqual(result['name'], self._FUNCTION_NAME)