Skip to content

Commit

Permalink
Merge pull request #10 from mj0nez/fix/create-volume-tests
Browse files Browse the repository at this point in the history
fix: create volume tests
  • Loading branch information
mxab authored Mar 28, 2024
2 parents 4d57047 + 508c5e5 commit 2dd2ed0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
A Jupyterhub plugin to spawn single-user notebook servers via [Nomad](https://www.nomadproject.io/). The project provides templates to allow users to influence how their servers are spawned (see the [showcase](#-show-case) and [recipes](#-recipes) for more details.).

After login users can select and image, resource and connect it with volumes (csi / host)
After login users can select an image, resources and connect it with volumes (csi / host)

```sh
pip install jupyterhub-nomad-spawner
Expand Down
29 changes: 21 additions & 8 deletions tests/nomad/test_nomad_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import httpx
import pytest

from jupyterhub_nomad_spawner.nomad.nomad_service import NomadService
from jupyterhub_nomad_spawner.nomad.nomad_service import NomadService, NomadException


@pytest.mark.respx(base_url="http://localhost:4646")
@pytest.mark.asyncio
async def test_register_volume(respx_mock):
respx_mock.put(
"/v1/volume/csi/volume123",
"/v1/volume/csi/volume123/create",
json={
"Volumes": [
{
Expand All @@ -20,6 +20,12 @@ async def test_register_volume(respx_mock):
"ExternalID": "volume123",
"Name": "volume123",
"PluginID": "csi_plugin_1",
"RequestedCapabilities": [
{
"AccessMode": "single-node-writer",
"AttachmentMode": "file-system",
}
],
}
]
},
Expand All @@ -32,9 +38,9 @@ async def test_register_volume(respx_mock):

@pytest.mark.respx(base_url="http://localhost:4646")
@pytest.mark.asyncio
async def test_register_volume(respx_mock):
async def test_register_existing_volume(respx_mock):
respx_mock.put(
"/v1/volume/csi/volume123",
"/v1/volume/csi/volume123/create",
json={
"Volumes": [
{
Expand All @@ -44,14 +50,21 @@ async def test_register_volume(respx_mock):
"ExternalID": "volume123",
"Name": "volume123",
"PluginID": "csi_plugin_1",
"RequestedCapabilities": [
{
"AccessMode": "single-node-writer",
"AttachmentMode": "file-system",
}
],
}
]
},
).mock(return_value=httpx.Response(200))
).mock(return_value=httpx.Response(403))

async with httpx.AsyncClient(base_url="http://localhost:4646") as client:
service = NomadService(client=client, log=logging.getLogger("test"))
await service.create_volume(id="volume123", plugin_id="csi_plugin_1")
with pytest.raises(NomadException):
async with httpx.AsyncClient(base_url="http://localhost:4646") as client:
service = NomadService(client=client, log=logging.getLogger("test"))
await service.create_volume(id="volume123", plugin_id="csi_plugin_1")


@pytest.mark.respx(base_url="http://localhost:4646")
Expand Down

0 comments on commit 2dd2ed0

Please sign in to comment.