Skip to content

Commit

Permalink
test: changed test duplicate to cover exception path
Browse files Browse the repository at this point in the history
  • Loading branch information
mj0nez committed Mar 28, 2024
1 parent 8855e36 commit 400af5e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tests/nomad/test_nomad_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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")
Expand Down Expand Up @@ -38,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 @@ -50,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 400af5e

Please sign in to comment.