diff --git a/jhub_apps/hub_client/hub_client.py b/jhub_apps/hub_client/hub_client.py index cc79d72b..c7224d86 100644 --- a/jhub_apps/hub_client/hub_client.py +++ b/jhub_apps/hub_client/hub_client.py @@ -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) diff --git a/jhub_apps/tests/tests_unit/test_api.py b/jhub_apps/tests/tests_unit/test_api.py index 396f91d1..a99f3953 100644 --- a/jhub_apps/tests/tests_unit/test_api.py +++ b/jhub_apps/tests/tests_unit/test_api.py @@ -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