1+ from unittest .mock import Mock
2+
13import pytest
4+
25from openstack_mcp_server .tools .block_storage_tools import BlockStorageTools
36from openstack_mcp_server .tools .response .block_storage import (
47 Volume ,
58 VolumeAttachment ,
69)
710
8- from unittest .mock import Mock
911
1012class TestBlockStorageTools :
1113 """Test cases for BlockStorageTools class."""
@@ -74,7 +76,8 @@ def test_get_volumes_success(self, mock_get_openstack_conn_block_storage):
7476 mock_conn .block_storage .volumes .assert_called_once ()
7577
7678 def test_get_volumes_empty_list (
77- self , mock_get_openstack_conn_block_storage
79+ self ,
80+ mock_get_openstack_conn_block_storage ,
7881 ):
7982 """Test getting volumes when no volumes exist."""
8083 mock_conn = mock_get_openstack_conn_block_storage
@@ -92,7 +95,8 @@ def test_get_volumes_empty_list(
9295 mock_conn .block_storage .volumes .assert_called_once ()
9396
9497 def test_get_volumes_single_volume (
95- self , mock_get_openstack_conn_block_storage
98+ self ,
99+ mock_get_openstack_conn_block_storage ,
96100 ):
97101 """Test getting volumes with a single volume."""
98102 mock_conn = mock_get_openstack_conn_block_storage
@@ -125,7 +129,8 @@ def test_get_volumes_single_volume(
125129 mock_conn .block_storage .volumes .assert_called_once ()
126130
127131 def test_get_volumes_multiple_statuses (
128- self , mock_get_openstack_conn_block_storage
132+ self ,
133+ mock_get_openstack_conn_block_storage ,
129134 ):
130135 """Test volumes with various statuses."""
131136 mock_conn = mock_get_openstack_conn_block_storage
@@ -175,7 +180,8 @@ def test_get_volumes_multiple_statuses(
175180 mock_conn .block_storage .volumes .assert_called_once ()
176181
177182 def test_get_volumes_with_special_characters (
178- self , mock_get_openstack_conn_block_storage
183+ self ,
184+ mock_get_openstack_conn_block_storage ,
179185 ):
180186 """Test volumes with special characters in names."""
181187 mock_conn = mock_get_openstack_conn_block_storage
@@ -229,7 +235,10 @@ def test_get_volumes_with_special_characters(
229235
230236 mock_conn .block_storage .volumes .assert_called_once ()
231237
232- def test_get_volume_details_success (self , mock_get_openstack_conn_block_storage ):
238+ def test_get_volume_details_success (
239+ self ,
240+ mock_get_openstack_conn_block_storage ,
241+ ):
233242 """Test getting volume details successfully."""
234243 mock_conn = mock_get_openstack_conn_block_storage
235244
@@ -268,7 +277,8 @@ def test_get_volume_details_success(self, mock_get_openstack_conn_block_storage)
268277 mock_conn .block_storage .get_volume .assert_called_once_with ("vol-123" )
269278
270279 def test_get_volume_details_with_attachments (
271- self , mock_get_openstack_conn_block_storage
280+ self ,
281+ mock_get_openstack_conn_block_storage ,
272282 ):
273283 """Test getting volume details with attachments."""
274284 mock_conn = mock_get_openstack_conn_block_storage
@@ -323,11 +333,14 @@ def test_get_volume_details_with_attachments(
323333 assert attach2 .device == "/dev/vdc"
324334 assert attach2 .attachment_id == "attach-2"
325335
326- def test_get_volume_details_error (self , mock_get_openstack_conn_block_storage ):
336+ def test_get_volume_details_error (
337+ self ,
338+ mock_get_openstack_conn_block_storage ,
339+ ):
327340 """Test getting volume details with error."""
328341 mock_conn = mock_get_openstack_conn_block_storage
329342 mock_conn .block_storage .get_volume .side_effect = Exception (
330- "Volume not found"
343+ "Volume not found" ,
331344 )
332345
333346 block_storage_tools = BlockStorageTools ()
@@ -336,7 +349,10 @@ def test_get_volume_details_error(self, mock_get_openstack_conn_block_storage):
336349 with pytest .raises (Exception , match = "Volume not found" ):
337350 block_storage_tools .get_volume_details ("nonexistent-vol" )
338351
339- def test_create_volume_success (self , mock_get_openstack_conn_block_storage ):
352+ def test_create_volume_success (
353+ self ,
354+ mock_get_openstack_conn_block_storage ,
355+ ):
340356 """Test creating volume successfully."""
341357 mock_conn = mock_get_openstack_conn_block_storage
342358
@@ -358,7 +374,11 @@ def test_create_volume_success(self, mock_get_openstack_conn_block_storage):
358374
359375 block_storage_tools = BlockStorageTools ()
360376 result = block_storage_tools .create_volume (
361- "new-volume" , 10 , "Test volume" , "ssd" , "nova"
377+ "new-volume" ,
378+ 10 ,
379+ "Test volume" ,
380+ "ssd" ,
381+ "nova" ,
362382 )
363383
364384 # Verify result is a Volume object
@@ -381,7 +401,8 @@ def test_create_volume_success(self, mock_get_openstack_conn_block_storage):
381401 )
382402
383403 def test_create_volume_minimal_params (
384- self , mock_get_openstack_conn_block_storage
404+ self ,
405+ mock_get_openstack_conn_block_storage ,
385406 ):
386407 """Test creating volume with minimal parameters."""
387408 mock_conn = mock_get_openstack_conn_block_storage
@@ -410,11 +431,15 @@ def test_create_volume_minimal_params(
410431 assert result .size == 5
411432
412433 mock_conn .block_storage .create_volume .assert_called_once_with (
413- size = 5 , image = None , bootable = None , name = "minimal-volume"
434+ size = 5 ,
435+ image = None ,
436+ bootable = None ,
437+ name = "minimal-volume" ,
414438 )
415439
416440 def test_create_volume_with_image_and_bootable (
417- self , mock_get_openstack_conn_block_storage
441+ self ,
442+ mock_get_openstack_conn_block_storage ,
418443 ):
419444 """Test creating volume with image and bootable parameters."""
420445 mock_conn = mock_get_openstack_conn_block_storage
@@ -465,15 +490,18 @@ def test_create_volume_error(self, mock_get_openstack_conn_block_storage):
465490 """Test creating volume with error."""
466491 mock_conn = mock_get_openstack_conn_block_storage
467492 mock_conn .block_storage .create_volume .side_effect = Exception (
468- "Quota exceeded"
493+ "Quota exceeded" ,
469494 )
470495
471496 block_storage_tools = BlockStorageTools ()
472497
473498 with pytest .raises (Exception , match = "Quota exceeded" ):
474499 block_storage_tools .create_volume ("fail-volume" , 100 )
475500
476- def test_delete_volume_success (self , mock_get_openstack_conn_block_storage ):
501+ def test_delete_volume_success (
502+ self ,
503+ mock_get_openstack_conn_block_storage ,
504+ ):
477505 """Test deleting volume successfully."""
478506 mock_conn = mock_get_openstack_conn_block_storage
479507
@@ -490,7 +518,9 @@ def test_delete_volume_success(self, mock_get_openstack_conn_block_storage):
490518 # Verify result is None
491519 assert result is None
492520 mock_conn .block_storage .delete_volume .assert_called_once_with (
493- "vol-delete" , force = False , ignore_missing = False
521+ "vol-delete" ,
522+ force = False ,
523+ ignore_missing = False ,
494524 )
495525
496526 def test_delete_volume_force (self , mock_get_openstack_conn_block_storage ):
@@ -510,14 +540,16 @@ def test_delete_volume_force(self, mock_get_openstack_conn_block_storage):
510540 assert result is None
511541
512542 mock_conn .block_storage .delete_volume .assert_called_once_with (
513- "vol-force-delete" , force = True , ignore_missing = False
543+ "vol-force-delete" ,
544+ force = True ,
545+ ignore_missing = False ,
514546 )
515547
516548 def test_delete_volume_error (self , mock_get_openstack_conn_block_storage ):
517549 """Test deleting volume with error."""
518550 mock_conn = mock_get_openstack_conn_block_storage
519551 mock_conn .block_storage .delete_volume .side_effect = Exception (
520- "Volume not found"
552+ "Volume not found" ,
521553 )
522554
523555 block_storage_tools = BlockStorageTools ()
@@ -526,7 +558,10 @@ def test_delete_volume_error(self, mock_get_openstack_conn_block_storage):
526558 with pytest .raises (Exception , match = "Volume not found" ):
527559 block_storage_tools .delete_volume ("nonexistent-vol" )
528560
529- def test_extend_volume_success (self , mock_get_openstack_conn_block_storage ):
561+ def test_extend_volume_success (
562+ self ,
563+ mock_get_openstack_conn_block_storage ,
564+ ):
530565 """Test extending volume successfully."""
531566 mock_conn = mock_get_openstack_conn_block_storage
532567
@@ -537,14 +572,18 @@ def test_extend_volume_success(self, mock_get_openstack_conn_block_storage):
537572 assert result is None
538573
539574 mock_conn .block_storage .extend_volume .assert_called_once_with (
540- "vol-extend" , 20
575+ "vol-extend" ,
576+ 20 ,
541577 )
542578
543- def test_extend_volume_invalid_size (self , mock_get_openstack_conn_block_storage ):
579+ def test_extend_volume_invalid_size (
580+ self ,
581+ mock_get_openstack_conn_block_storage ,
582+ ):
544583 """Test extending volume with invalid size."""
545584 mock_conn = mock_get_openstack_conn_block_storage
546585 mock_conn .block_storage .extend_volume .side_effect = Exception (
547- "Invalid size"
586+ "Invalid size" ,
548587 )
549588
550589 block_storage_tools = BlockStorageTools ()
@@ -556,7 +595,7 @@ def test_extend_volume_error(self, mock_get_openstack_conn_block_storage):
556595 """Test extending volume with error."""
557596 mock_conn = mock_get_openstack_conn_block_storage
558597 mock_conn .block_storage .extend_volume .side_effect = Exception (
559- "Volume busy"
598+ "Volume busy" ,
560599 )
561600
562601 block_storage_tools = BlockStorageTools ()
@@ -643,4 +682,4 @@ def test_all_block_storage_methods_have_docstrings(self):
643682 )
644683 assert len (docstring .strip ()) > 0 , (
645684 f"{ method_name } docstring should not be empty"
646- )
685+ )
0 commit comments