Skip to content
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
2 changes: 1 addition & 1 deletion airflow/api_connexion/endpoints/user_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def post_user() -> APIResponse:
user = security_manager.add_user(role=roles_to_add, **data)
if not user:
detail = f"Failed to add user `{username}`."
return Unknown(detail=detail)
raise Unknown(detail=detail)

return user_schema.dump(user)

Expand Down
14 changes: 14 additions & 0 deletions tests/api_connexion/endpoints/test_user_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,20 @@ def test_invalid_payload(self, autoclean_user_payload, payload_converter, error_
"type": EXCEPTIONS_LINK_MAP[400],
}

def test_internal_server_error(self, autoclean_user_payload):
with unittest.mock.patch.object(self.app.appbuilder.sm, "add_user", return_value=None):
response = self.client.post(
"/api/v1/users",
json=autoclean_user_payload,
environ_overrides={"REMOTE_USER": "test"},
)
assert response.json == {
"detail": "Failed to add user `example_user`.",
"status": 500,
"title": "Internal Server Error",
"type": EXCEPTIONS_LINK_MAP[500],
}


class TestPatchUser(TestUserEndpoint):
@pytest.mark.usefixtures("autoclean_admin_user")
Expand Down