فهرست منبع

Merge pull request #212 from smiclea/fix-tests

Fix failing tests
Nashwan Azhari 4 سال پیش
والد
کامیت
bd550e3939
4فایلهای تغییر یافته به همراه35 افزوده شده و 34 حذف شده
  1. 8 7
      coriolis/tests/conductor/rpc/test_server.py
  2. 2 25
      coriolis/tests/db/test_api.py
  3. 2 2
      coriolis/tests/test_schemas.py
  4. 23 0
      coriolis/tests/testutils.py

+ 8 - 7
coriolis/tests/conductor/rpc/test_server.py

@@ -6,7 +6,7 @@ from unittest import mock
 
 from coriolis.conductor.rpc import server
 from coriolis import exception
-from coriolis.tests import test_base
+from coriolis.tests import test_base, testutils
 
 
 @ddt.ddt
@@ -17,21 +17,22 @@ class ConductorServerEndpointTestCase(test_base.CoriolisBaseTestCase):
         super(ConductorServerEndpointTestCase, self).setUp()
         self.server = server.ConductorServerEndpoint()
 
-    @ddt.data({}, {mock.sentinel.instance: {}})
     @mock.patch.object(server.ConductorServerEndpoint, '_create_task')
     @mock.patch.object(server.ConductorServerEndpoint,
                        '_check_replica_running_executions')
     @mock.patch.object(server.ConductorServerEndpoint, '_get_replica')
-    def test_update_endpoint_not_found(self, replica_info, mock_get_replica,
-                                       mock_check_replica_running,
-                                       mock_create_task):
+    def test_delete_replica_disks_invalid_state(self, mock_get_replica,
+                                                mock_check_replica_running,
+                                                mock_create_task):
         mock_replica = mock_get_replica.return_value
         mock_replica.instances = [mock.sentinel.instance]
         mock_replica.info = {}
+        delete_replica_disks = testutils.get_wrapped_function(
+            self.server.delete_replica_disks)
 
         self.assertRaises(exception.InvalidReplicaState,
-                          self.server.delete_replica_disks,
-                          mock.sentinel.context, mock.sentinel.replica_id)
+                          delete_replica_disks,
+                          self.server, mock.sentinel.context, mock.sentinel.replica_id)
 
         mock_get_replica.assert_called_once_with(mock.sentinel.context,
                                                  mock.sentinel.replica_id)

+ 2 - 25
coriolis/tests/db/test_api.py

@@ -5,30 +5,7 @@ from unittest import mock
 
 from coriolis.db import api
 from coriolis import exception
-from coriolis.tests import test_base
-
-
-def get_wrapped_function(function):
-    """Get the method at the bottom of a stack of decorators."""
-    if not hasattr(function, '__closure__') or not function.__closure__:
-        return function
-
-    def _get_wrapped_function(function):
-        if not hasattr(function, '__closure__') or not function.__closure__:
-            return None
-
-        for closure in function.__closure__:
-            func = closure.cell_contents
-
-            deeper_func = _get_wrapped_function(func)
-            if deeper_func:
-                return deeper_func
-            elif hasattr(closure.cell_contents, '__call__'):
-                return closure.cell_contents
-
-        return function
-
-    return _get_wrapped_function(function)
+from coriolis.tests import test_base, testutils
 
 
 class DBAPITestCase(test_base.CoriolisBaseTestCase):
@@ -41,7 +18,7 @@ class DBAPITestCase(test_base.CoriolisBaseTestCase):
         # We only need to test the unwrapped functions. Without this,
         # when calling a coriolis.db.api function, it will try to
         # establish an SQL connection.
-        update_endpoint = get_wrapped_function(api.update_endpoint)
+        update_endpoint = testutils.get_wrapped_function(api.update_endpoint)
 
         self.assertRaises(exception.NotFound, update_endpoint,
                           mock.sentinel.context, mock.sentinel.endpoint_id,

+ 2 - 2
coriolis/tests/test_schemas.py

@@ -73,7 +73,7 @@ class SchemasTestCase(test_base.CoriolisBaseTestCase):
 
         schemas.validate_value(test_value, test_schema)
 
-        mock_validate.assert_called_once_with(test_value, test_schema)
+        mock_validate.assert_called_once_with(test_value, test_schema, format_checker=None)
 
     @mock.patch.object(json, 'loads')
     @mock.patch.object(jsonschema, 'validate')
@@ -87,4 +87,4 @@ class SchemasTestCase(test_base.CoriolisBaseTestCase):
         schemas.validate_string(test_string, test_schema)
 
         mock_loads.assert_called_once_with(test_string)
-        mock_validate.assert_called_once_with(test_value, test_schema)
+        mock_validate.assert_called_once_with(test_value, test_schema, format_checker=None)

+ 23 - 0
coriolis/tests/testutils.py

@@ -11,3 +11,26 @@ def identity_dec(item, *args, **kwargs):
 def make_identity_decorator_mock():
     """Returns a MagicMock with identity_dec as a side-effect."""
     return mock.MagicMock(side_effect=identity_dec)
+
+
+def get_wrapped_function(function):
+    """Get the method at the bottom of a stack of decorators."""
+    if not hasattr(function, '__closure__') or not function.__closure__:
+        return function
+
+    def _get_wrapped_function(function):
+        if not hasattr(function, '__closure__') or not function.__closure__:
+            return None
+
+        for closure in function.__closure__:
+            func = closure.cell_contents
+
+            deeper_func = _get_wrapped_function(func)
+            if deeper_func:
+                return deeper_func
+            elif hasattr(closure.cell_contents, '__call__'):
+                return closure.cell_contents
+
+        return function
+
+    return _get_wrapped_function(function)