diff --git a/oslo_context/context.py b/oslo_context/context.py index 0238533..d3da603 100644 --- a/oslo_context/context.py +++ b/oslo_context/context.py @@ -31,6 +31,8 @@ import itertools import threading import uuid +from positional import positional + _request_store = threading.local() @@ -68,6 +70,7 @@ class RequestContext(object): user_idt_format = u'{user} {tenant} {domain} {user_domain} {p_domain}' + @positional(enforcement=positional.WARN) def __init__(self, auth_token=None, user=None, tenant=None, domain=None, user_domain=None, project_domain=None, is_admin=False, read_only=False, show_deleted=False, request_id=None, diff --git a/oslo_context/tests/test_context.py b/oslo_context/tests/test_context.py index e50b99c..559562b 100644 --- a/oslo_context/tests/test_context.py +++ b/oslo_context/tests/test_context.py @@ -14,8 +14,10 @@ # License for the specific language governing permissions and limitations # under the License. +import fixtures import hashlib import uuid +import warnings from oslotest import base as test_base @@ -27,6 +29,21 @@ def generate_id(name): return hashlib.md5(name.encode('utf-8')).hexdigest() +class WarningsFixture(fixtures.Fixture): + + def __init__(self, action="always", category=DeprecationWarning): + super(WarningsFixture, self).__init__() + self.action = action + self.category = category + + def setUp(self): + super(WarningsFixture, self).setUp() + self._w = warnings.catch_warnings(record=True) + self.log = self._w.__enter__() + self.addCleanup(self._w.__exit__) + warnings.simplefilter(self.action, self.category) + + class Object(object): pass @@ -35,6 +52,7 @@ class ContextTest(test_base.BaseTestCase): def setUp(self): super(ContextTest, self).setUp() + self.warnings = self.useFixture(WarningsFixture()) self.useFixture(fixture.ClearRequestContext()) def test_context(self): @@ -439,3 +457,10 @@ class ContextTest(test_base.BaseTestCase): 'roles': roles, 'is_admin_project': False}, ctx.to_policy_values()) + + def test_positional_args(self): + context.RequestContext('abc', 'def') + + self.assertEqual(1, len(self.warnings.log)) + self.assertIn('__init__ takes at most 1 positional', + str(self.warnings.log[0].message)) diff --git a/requirements.txt b/requirements.txt index 95d0fe8..99569a8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,5 @@ # process, which may cause wedges in the gate later. pbr>=1.6 # Apache-2.0 + +positional>=1.0.1 # Apache-2.0 diff --git a/test-requirements.txt b/test-requirements.txt index 79fca04..43374b4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,6 +2,7 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. +fixtures>=3.0.0 # Apache-2.0/BSD hacking<0.11,>=0.10.0 oslotest>=1.10.0 # Apache-2.0 coverage>=3.6 # Apache-2.0