diff options
-rw-r--r-- | nova/db/sqlalchemy/api.py | 2 | ||||
-rw-r--r-- | nova/tests/test_db_api.py | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index a0f679d73..9f7da2c39 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -95,6 +95,7 @@ def require_admin_context(f): """ + @functools.wraps(f) def wrapper(*args, **kwargs): nova.context.require_admin_context(args[0]) return f(*args, **kwargs) @@ -112,6 +113,7 @@ def require_context(f): """ + @functools.wraps(f) def wrapper(*args, **kwargs): nova.context.require_context(args[0]) return f(*args, **kwargs) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 130ed22af..dc2cf0d24 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -1177,6 +1177,22 @@ class DbApiTestCase(DbTestCase): _compare(bw_usages[2], expected_bw_usages[2]) timeutils.clear_time_override() + def _test_decorator_wraps_helper(self, decorator): + def test_func(): + """Test docstring.""" + + decorated_func = decorator(test_func) + + self.assertEquals(test_func.func_name, decorated_func.func_name) + self.assertEquals(test_func.__doc__, decorated_func.__doc__) + self.assertEquals(test_func.__module__, decorated_func.__module__) + + def test_require_context_decorator_wraps_functions_properly(self): + self._test_decorator_wraps_helper(sqlalchemy_api.require_context) + + def test_require_admin_context_decorator_wraps_functions_properly(self): + self._test_decorator_wraps_helper(sqlalchemy_api.require_admin_context) + def _get_fake_aggr_values(): return {'name': 'fake_aggregate'} |