Browse Source

Correctly mock keystoneclient.Client.auto_token property with Mox

Recent Mox doesn't stub out class properties any more (check
https://code.google.com/p/pymox/issues/detail?id=11), so we have to do
that manually. Avoids the following error:

FAIL: test_get_default_role
(openstack_dashboard.test.api_tests.keystone_tests.RoleAPITests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/Projects/openstack/horizon/openstack_dashboard/test/api_tests/keystone_tests.py", line 76, in test_get_default_role
    keystoneclient = self.stub_keystoneclient()
  File "/root/Projects/openstack/horizon/openstack_dashboard/test/helpers.py", line 280, in stub_keystoneclient
    self.keystoneclient = self.mox.CreateMock(keystone_client.Client)
  File "/usr/lib/python2.7/site-packages/mox.py", line 258, in CreateMock
    new_mock = MockObject(class_to_mock, attrs=attrs)
  File "/usr/lib/python2.7/site-packages/mox.py", line 556, in __init__
    attr = getattr(class_to_mock, method)
  File "/usr/lib/python2.7/site-packages/mox.py", line 608, in __getattr__
    raise UnknownMethodCallError(name)
UnknownMethodCallError: Method called is not a member of the object: Method called is not a member of the object: auth_token
>>  raise UnknownMethodCallError('auth_token')

Change-Id: I54fd0de298dc66344470147d9bcec6b62baf8297
changes/21/514521/1
Sascha Peilicke 9 years ago
parent
commit
3a1be65c93
  1. 3
      openstack_dashboard/test/helpers.py

3
openstack_dashboard/test/helpers.py

@ -277,6 +277,9 @@ class APITestCase(TestCase):
def stub_keystoneclient(self):
if not hasattr(self, "keystoneclient"):
self.mox.StubOutWithMock(keystone_client, 'Client')
# NOTE(saschpe): Mock the 'auth_token' property specifically,
# MockObject.__init__ ignores properties altogether:
keystone_client.Client.auth_token = 'foo'
self.keystoneclient = self.mox.CreateMock(keystone_client.Client)
return self.keystoneclient

Loading…
Cancel
Save