Skip to content

Commit 2dd2ed0

Browse files
authored
Merge pull request #10 from mj0nez/fix/create-volume-tests
fix: create volume tests
2 parents 4d57047 + 508c5e5 commit 2dd2ed0

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
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.).
77

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

1010
```sh
1111
pip install jupyterhub-nomad-spawner

tests/nomad/test_nomad_service.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import httpx
44
import pytest
55

6-
from jupyterhub_nomad_spawner.nomad.nomad_service import NomadService
6+
from jupyterhub_nomad_spawner.nomad.nomad_service import NomadService, NomadException
77

88

99
@pytest.mark.respx(base_url="http://localhost:4646")
1010
@pytest.mark.asyncio
1111
async def test_register_volume(respx_mock):
1212
respx_mock.put(
13-
"/v1/volume/csi/volume123",
13+
"/v1/volume/csi/volume123/create",
1414
json={
1515
"Volumes": [
1616
{
@@ -20,6 +20,12 @@ async def test_register_volume(respx_mock):
2020
"ExternalID": "volume123",
2121
"Name": "volume123",
2222
"PluginID": "csi_plugin_1",
23+
"RequestedCapabilities": [
24+
{
25+
"AccessMode": "single-node-writer",
26+
"AttachmentMode": "file-system",
27+
}
28+
],
2329
}
2430
]
2531
},
@@ -32,9 +38,9 @@ async def test_register_volume(respx_mock):
3238

3339
@pytest.mark.respx(base_url="http://localhost:4646")
3440
@pytest.mark.asyncio
35-
async def test_register_volume(respx_mock):
41+
async def test_register_existing_volume(respx_mock):
3642
respx_mock.put(
37-
"/v1/volume/csi/volume123",
43+
"/v1/volume/csi/volume123/create",
3844
json={
3945
"Volumes": [
4046
{
@@ -44,14 +50,21 @@ async def test_register_volume(respx_mock):
4450
"ExternalID": "volume123",
4551
"Name": "volume123",
4652
"PluginID": "csi_plugin_1",
53+
"RequestedCapabilities": [
54+
{
55+
"AccessMode": "single-node-writer",
56+
"AttachmentMode": "file-system",
57+
}
58+
],
4759
}
4860
]
4961
},
50-
).mock(return_value=httpx.Response(200))
62+
).mock(return_value=httpx.Response(403))
5163

52-
async with httpx.AsyncClient(base_url="http://localhost:4646") as client:
53-
service = NomadService(client=client, log=logging.getLogger("test"))
54-
await service.create_volume(id="volume123", plugin_id="csi_plugin_1")
64+
with pytest.raises(NomadException):
65+
async with httpx.AsyncClient(base_url="http://localhost:4646") as client:
66+
service = NomadService(client=client, log=logging.getLogger("test"))
67+
await service.create_volume(id="volume123", plugin_id="csi_plugin_1")
5568

5669

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

0 commit comments

Comments
 (0)