Skip to content

Commit

Permalink
Gracefully handle server not found (#397)
Browse files Browse the repository at this point in the history
* Gracefully handle server not found

* add test for server not found
  • Loading branch information
aktech authored Jul 16, 2024
1 parent 563b8df commit 3df80a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jhub_apps/hub_client/hub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ def start_server(self, username, servername):
else:
# Get named server
server = self.get_server(username, servername)
user_options = server["user_options"]
if not server:
return None
user_options = server["user_options"]
url = f"/users/{username}/servers/{servername}"
data = {"name": servername, **user_options}
r = requests.post(API_URL + url, headers=self._headers(), json=data)
Expand Down
13 changes: 13 additions & 0 deletions jhub_apps/tests/tests_unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ def test_api_get_server(get_user, client):
assert response.json() == server_data["panel-app"]


@patch.object(HubClient, "get_user")
def test_api_get_server_not_found(get_user, client):
server_data = {"panel-app": {}}
get_users_response = {'name': 'aktech', 'servers': server_data}
get_user.return_value = get_users_response
response = client.get("/server/panel-app-not-found")
get_user.assert_called_once_with()
assert response.status_code == 404
assert response.json() == {
'detail': "server 'panel-app-not-found' not found",
}


@patch.object(HubClient, "create_server")
def test_api_create_server(create_server, client):
from jhub_apps.service.models import UserOptions
Expand Down

0 comments on commit 3df80a3

Please sign in to comment.