Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST API set description on POST to /variables endpoint #36820

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions airflow/api_connexion/endpoints/variable_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def post_variables() -> Response:
"""Create a variable."""
try:
data = variable_schema.load(get_json_request_dict())

except ValidationError as err:
raise BadRequest("Invalid Variable schema", detail=str(err.messages))
Variable.set(data["key"], data["val"])
Variable.set(data["key"], data["val"], description=data.get("description", None))
return variable_schema.dump(data)
20 changes: 14 additions & 6 deletions tests/api_connexion/endpoints/test_variable_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,21 @@ def test_should_raises_401_unauthenticated(self):


class TestPostVariables(TestVariableEndpoint):
def test_should_create_variable(self, session):
@pytest.mark.parametrize(
"description",
[
pytest.param(None, id="not-set"),
pytest.param("", id="empty"),
pytest.param("Spam Egg", id="desc-set"),
],
)
def test_should_create_variable(self, description, session):
payload = {"key": "var_create", "value": "{}"}
if description is not None:
payload["description"] = description
response = self.client.post(
"/api/v1/variables",
json={
"key": "var_create",
"value": "{}",
},
json=payload,
environ_overrides={"REMOTE_USER": "test"},
)
assert response.status_code == 200
Expand All @@ -350,7 +358,7 @@ def test_should_create_variable(self, session):
assert response.json == {
"key": "var_create",
"value": "{}",
"description": None,
"description": description,
}

def test_should_reject_invalid_request(self, session):
Expand Down