Skip to content

Commit

Permalink
Fix typing for POST user endpoint (#31767)
Browse files Browse the repository at this point in the history
* Fix typing for POST user endpoint

This should raise exception not return it.

* fixup! Fix typing for POST user endpoint
  • Loading branch information
ephraimbuddy committed Jun 7, 2023
1 parent e162074 commit f7ed878
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/api_connexion/endpoints/user_endpoint.py
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
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

0 comments on commit f7ed878

Please sign in to comment.