Skip to content

Commit

Permalink
Merge "Pop extra keys from context in from_dict()"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Aug 22, 2013
2 parents 311be1e + 5e573aa commit 8805ed7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nova/context.py
Expand Up @@ -139,6 +139,8 @@ def to_dict(self):

@classmethod
def from_dict(cls, values):
values.pop('user', None)
values.pop('tenant', None)
return cls(**values)

def elevated(self, read_deleted=None, overwrite=False):
Expand Down
18 changes: 18 additions & 0 deletions nova/tests/test_context.py
Expand Up @@ -101,3 +101,21 @@ def test_service_catalog_cinder_only(self):
ctxt = context.RequestContext('111', '222',
service_catalog=service_catalog)
self.assertEquals(ctxt.service_catalog, volume_catalog)

def test_to_dict_from_dict_no_log(self):
warns = []

def stub_warn(msg, *a, **kw):
if (a and len(a) == 1 and isinstance(a[0], dict) and a[0]):
a = a[0]
warns.append(str(msg) % a)

self.stubs.Set(context.LOG, 'warn', stub_warn)

ctxt = context.RequestContext('111',
'222',
roles=['admin', 'weasel'])

ctxt = context.RequestContext.from_dict(ctxt.to_dict())

self.assertEqual(len(warns), 0, warns)

0 comments on commit 8805ed7

Please sign in to comment.