-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
coriolis.api.v1.replica_actions
module
- Loading branch information
1 parent
c999dfe
commit 44d2f42
Showing
1 changed file
with
105 additions
and
0 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,105 @@ | ||
# Copyright 2023 Cloudbase Solutions Srl | ||
# All Rights Reserved. | ||
|
||
from unittest import mock | ||
|
||
from webob import exc | ||
|
||
from coriolis.api.v1 import replica_actions | ||
from coriolis.api.v1.views import replica_tasks_execution_view | ||
from coriolis import exception | ||
from coriolis.replicas import api | ||
from coriolis.tests import test_base | ||
from coriolis.tests import testutils | ||
|
||
|
||
class ReplicaActionsControllerTestCase(test_base.CoriolisBaseTestCase): | ||
"""Test suite for the Coriolis Replica Actions v1 API""" | ||
|
||
def setUp(self): | ||
super(ReplicaActionsControllerTestCase, self).setUp() | ||
self.replica_actions = replica_actions.ReplicaActionsController() | ||
|
||
@mock.patch.object(replica_tasks_execution_view, 'single') | ||
@mock.patch.object(api.API, 'delete_disks') | ||
def test_delete_disks( | ||
self, | ||
mock_delete_disks, | ||
mock_single | ||
): | ||
mock_req = mock.Mock() | ||
mock_context = mock.Mock() | ||
mock_req.environ = {'coriolis.context': mock_context} | ||
id = mock.sentinel.id | ||
body = mock.sentinel.body | ||
|
||
result = testutils.get_wrapped_function( | ||
self.replica_actions._delete_disks)( | ||
mock_req, | ||
id, | ||
body | ||
) | ||
|
||
self.assertEqual( | ||
mock_single.return_value, | ||
result | ||
) | ||
|
||
mock_context.can.assert_called_once_with( | ||
"migration:replicas:delete_disks") | ||
mock_delete_disks.assert_called_once_with(mock_context, id) | ||
mock_single.assert_called_once_with(mock_delete_disks.return_value) | ||
|
||
@mock.patch.object(replica_tasks_execution_view, 'single') | ||
@mock.patch.object(api.API, 'delete_disks') | ||
def test_delete_disks_not_found( | ||
self, | ||
mock_delete_disks, | ||
mock_single | ||
): | ||
mock_req = mock.Mock() | ||
mock_context = mock.Mock() | ||
mock_req.environ = {'coriolis.context': mock_context} | ||
id = mock.sentinel.id | ||
body = mock.sentinel.body | ||
mock_delete_disks.side_effect = exception.NotFound() | ||
|
||
self.assertRaises( | ||
exc.HTTPNotFound, | ||
testutils.get_wrapped_function(self.replica_actions._delete_disks), | ||
req=mock_req, | ||
id=id, | ||
body=body | ||
) | ||
|
||
mock_context.can.assert_called_once_with( | ||
"migration:replicas:delete_disks") | ||
mock_delete_disks.assert_called_once_with(mock_context, id) | ||
mock_single.assert_not_called() | ||
|
||
@mock.patch.object(replica_tasks_execution_view, 'single') | ||
@mock.patch.object(api.API, 'delete_disks') | ||
def test_delete_disks_invalid_parameter_value( | ||
self, | ||
mock_delete_disks, | ||
mock_single | ||
): | ||
mock_req = mock.Mock() | ||
mock_context = mock.Mock() | ||
mock_req.environ = {'coriolis.context': mock_context} | ||
id = mock.sentinel.id | ||
body = mock.sentinel.body | ||
mock_delete_disks.side_effect = exception.InvalidParameterValue("err") | ||
|
||
self.assertRaises( | ||
exc.HTTPNotFound, | ||
testutils.get_wrapped_function(self.replica_actions._delete_disks), | ||
req=mock_req, | ||
id=id, | ||
body=body | ||
) | ||
|
||
mock_context.can.assert_called_once_with( | ||
"migration:replicas:delete_disks") | ||
mock_delete_disks.assert_called_once_with(mock_context, id) | ||
mock_single.assert_not_called() |