-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Raise exception if multiple VFolders exist in decorator
Add changelog Add test code for decorator
- Loading branch information
1 parent
482da3b
commit a472541
Showing
4 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Raise exception if multiple VFolders exist in decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
from unittest.mock import AsyncMock, MagicMock | ||
from unittest.mock import AsyncMock, MagicMock, Mock | ||
from uuid import UUID | ||
|
||
import pytest | ||
from aiohttp import web | ||
|
||
from ai.backend.manager.api import vfolder | ||
from ai.backend.manager.api.vfolder import with_vfolder_rows_resolved | ||
from ai.backend.manager.models.vfolder import VFolderPermissionSetAlias | ||
from ai.backend.manager.api.exceptions import TooManyVFoldersFound, VFolderNotFound | ||
from ai.backend.manager.api.vfolder import with_vfolder_rows_resolved, with_vfolder_status_checked | ||
from ai.backend.manager.models.vfolder import ( | ||
VFolderPermissionSetAlias, | ||
VFolderRow, | ||
VFolderStatusSet, | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
|
@@ -27,3 +33,55 @@ async def dummy_handler(request, row): | |
await dummy_handler(mock_request) | ||
call = mock_resolver.await_args_list[1] | ||
assert isinstance(call.args[2], str) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"vfolder_status", | ||
[ | ||
VFolderStatusSet.ALL, | ||
VFolderStatusSet.READABLE, | ||
VFolderStatusSet.MOUNTABLE, | ||
VFolderStatusSet.UPDATABLE, | ||
VFolderStatusSet.DELETABLE, | ||
VFolderStatusSet.PURGABLE, | ||
VFolderStatusSet.RECOVERABLE, | ||
VFolderStatusSet.INACCESSIBLE, | ||
], | ||
) | ||
async def test_too_many_vfolders(vfolder_status): | ||
@with_vfolder_status_checked(vfolder_status) | ||
async def too_many_vfolders_handler(request, row: VFolderRow): | ||
return AsyncMock(return_value=web.Response(text="no response")) | ||
|
||
mock_entry = { | ||
"id": "fake-vfolder-id", | ||
"host": "fake-vfolder-host", | ||
"user_email": "[email protected]", | ||
"user": "fake-user", | ||
"group_name": "fake-group", | ||
"group": "fake-group-id", | ||
} | ||
with pytest.raises(TooManyVFoldersFound): | ||
await too_many_vfolders_handler(Mock(), [mock_entry, mock_entry]) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"vfolder_status", | ||
[ | ||
VFolderStatusSet.ALL, | ||
VFolderStatusSet.READABLE, | ||
VFolderStatusSet.MOUNTABLE, | ||
VFolderStatusSet.UPDATABLE, | ||
VFolderStatusSet.DELETABLE, | ||
VFolderStatusSet.PURGABLE, | ||
VFolderStatusSet.RECOVERABLE, | ||
VFolderStatusSet.INACCESSIBLE, | ||
], | ||
) | ||
async def test_no_vfolders(vfolder_status): | ||
@with_vfolder_status_checked(vfolder_status) | ||
async def no_vfolders_handler(request, row: VFolderRow): | ||
return AsyncMock(return_value=web.Response(text="no response")) | ||
|
||
with pytest.raises(VFolderNotFound): | ||
await no_vfolders_handler(Mock(), []) |