forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AIP-84 Delete Variable (apache#42798)
- Loading branch information
1 parent
9ded623
commit 000d2da
Showing
9 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from __future__ import annotations | ||
|
||
from fastapi import Depends, HTTPException | ||
from sqlalchemy.orm import Session | ||
from typing_extensions import Annotated | ||
|
||
from airflow.api_fastapi.db.common import get_session | ||
from airflow.api_fastapi.openapi.exceptions import create_openapi_http_exception_doc | ||
from airflow.api_fastapi.views.router import AirflowRouter | ||
from airflow.models.variable import Variable | ||
|
||
variables_router = AirflowRouter(tags=["Variable"], prefix="/variables") | ||
|
||
|
||
@variables_router.delete( | ||
"/{variable_key}", | ||
status_code=204, | ||
responses=create_openapi_http_exception_doc([401, 403, 404]), | ||
) | ||
async def delete_variable( | ||
variable_key: str, | ||
session: Annotated[Session, Depends(get_session)], | ||
): | ||
"""Delete a variable entry.""" | ||
if Variable.delete(variable_key, session) == 0: | ||
raise HTTPException(404, f"The Variable with key: `{variable_key}` was not found") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from airflow.models.variable import Variable | ||
from airflow.utils.session import provide_session | ||
from tests.test_utils.db import clear_db_variables | ||
|
||
pytestmark = pytest.mark.db_test | ||
|
||
TEST_VARIABLE_KEY = "test_variable_key" | ||
TEST_VARIABLE_VAL = 3 | ||
TEST_VARIABLE_DESCRIPTION = "Some description for the variable" | ||
TEST_CONN_TYPE = "test_type" | ||
|
||
|
||
@provide_session | ||
def _create_variable(session) -> None: | ||
Variable.set( | ||
key=TEST_VARIABLE_KEY, value=TEST_VARIABLE_VAL, description=TEST_VARIABLE_DESCRIPTION, session=session | ||
) | ||
|
||
|
||
class TestVariableEndpoint: | ||
@pytest.fixture(autouse=True) | ||
def setup(self) -> None: | ||
clear_db_variables() | ||
|
||
def teardown_method(self) -> None: | ||
clear_db_variables() | ||
|
||
def create_variable(self): | ||
_create_variable() | ||
|
||
|
||
class TestDeleteVariable(TestVariableEndpoint): | ||
def test_delete_should_respond_204(self, test_client, session): | ||
self.create_variable() | ||
variables = session.query(Variable).all() | ||
assert len(variables) == 1 | ||
response = test_client.delete(f"/public/variables/{TEST_VARIABLE_KEY}") | ||
assert response.status_code == 204 | ||
variables = session.query(Variable).all() | ||
assert len(variables) == 0 | ||
|
||
def test_delete_should_respond_404(self, test_client): | ||
response = test_client.delete(f"/public/variables/{TEST_VARIABLE_KEY}") | ||
assert response.status_code == 404 | ||
body = response.json() | ||
assert f"The Variable with key: `{TEST_VARIABLE_KEY}` was not found" == body["detail"] |