diff options
author | Akihiro MOTOKI <motoki@da.jp.nec.com> | 2013-07-25 21:38:31 +0900 |
---|---|---|
committer | Akihiro MOTOKI <motoki@da.jp.nec.com> | 2013-07-25 21:45:17 +0900 |
commit | a06e263b60779739654ebf1020da59f231ca5da2 (patch) | |
tree | be1810391397acb98e87dc3ae81a307fe3b282fa | |
parent | 699926413ccfd89207b22fd3c1f5db771665fd37 (diff) | |
download | tuskar-ui-a06e263b60779739654ebf1020da59f231ca5da2.tar.gz |
Ignore non-existing attr in APIResourceWrapper __repr__
Fixes bug 1202415
__repr__ was added to APIResourceWrapper in the recent commit,
but it searches all attributes in _attrs list. When an attribute
defined in _attrs actually does not exist, __repr__() fails.
This commit changes __repr__ to ignore non-existing attributes.
Change-Id: Iebaeae78f3763d87f3993ba5c4bbed4c23e84c45
-rw-r--r-- | openstack_dashboard/api/base.py | 6 | ||||
-rw-r--r-- | openstack_dashboard/test/api_tests/base_tests.py | 7 |
2 files changed, 10 insertions, 3 deletions
diff --git a/openstack_dashboard/api/base.py b/openstack_dashboard/api/base.py index 17ef4ee3..3edb5226 100644 --- a/openstack_dashboard/api/base.py +++ b/openstack_dashboard/api/base.py @@ -91,9 +91,9 @@ class APIResourceWrapper(object): def __repr__(self): return "<%s: %s>" % (self.__class__.__name__, - dict((attr, - getattr(self, attr)) - for attr in self._attrs)) + dict((attr, getattr(self, attr)) + for attr in self._attrs + if hasattr(self, attr))) class APIDictWrapper(object): diff --git a/openstack_dashboard/test/api_tests/base_tests.py b/openstack_dashboard/test/api_tests/base_tests.py index c6aa0460..d488757c 100644 --- a/openstack_dashboard/test/api_tests/base_tests.py +++ b/openstack_dashboard/test/api_tests/base_tests.py @@ -73,6 +73,13 @@ class APIResourceWrapperTests(test.TestCase): with self.assertRaises(AttributeError): resource.baz + def test_repr(self): + resource = APIResource.get_instance() + resource_str = resource.__repr__() + self.assertIn('foo', resource_str) + self.assertIn('bar', resource_str) + self.assertNotIn('baz', resource_str) + class APIDictWrapperTests(test.TestCase): # APIDict allows for both attribute access and dictionary style [element] |