From 9e09cfab2e1ec0b3e22f007eb2b7530e1c253dbe Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Wed, 30 Sep 2015 12:55:59 +1000 Subject: [PATCH] Fix horizon/test selenium tests for Django 1.8 This fixes the dummy user used in the Selenium tests for Django 1.8 updates (_meta.pk.to_python() etc strike again). It also addresses the refactoring of horizon.utils back into angular code. This aspect of the patch, along with the general structure of the test base.html, needs to be revisited, but fixing that structure correctly is outside of the scope of this patch. Also the ObjDictWrapper was enhanced to allow easier debugging of test failures, and simplified to reduce LOC achieving the same functionality. Change-Id: I5a50ad89163a8cce06959d36314a836c4bd3592c Closes-Bug: 1501163 --- horizon/test/dummy_auth/backend.py | 10 +++++++++- horizon/test/templates/base.html | 17 ++++++++++++++++- horizon/test/utils.py | 29 ++++++++++------------------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/horizon/test/dummy_auth/backend.py b/horizon/test/dummy_auth/backend.py index 208a979a8a..45b0ca8d71 100644 --- a/horizon/test/dummy_auth/backend.py +++ b/horizon/test/dummy_auth/backend.py @@ -31,7 +31,15 @@ class DummyBackend(object): pk=1111, save=lambda *args, **kwargs: None, is_authenticated=lambda: True, - has_perms=lambda perms: True) + has_perms=lambda perms: True + ) + + _user._meta = utils.ObjDictWrapper( + pk=utils.ObjDictWrapper( + value_to_string=lambda s: s.pk, + to_python=lambda s: s.pk + ) + ) def authenticate(self, *args, **kwargs): return self._user diff --git a/horizon/test/templates/base.html b/horizon/test/templates/base.html index 92df3c8bad..345e931701 100644 --- a/horizon/test/templates/base.html +++ b/horizon/test/templates/base.html @@ -11,6 +11,7 @@ + @@ -96,8 +97,22 @@ + - + + + + {% block sidebar %} {% include 'horizon/common/_sidebar.html' %} diff --git a/horizon/test/utils.py b/horizon/test/utils.py index 3b1a856f66..ea2b254ee7 100644 --- a/horizon/test/utils.py +++ b/horizon/test/utils.py @@ -10,28 +10,19 @@ # License for the specific language governing permissions and limitations # under the License. -import six - -class ObjDictWrapper(object): +class ObjDictWrapper(dict): """ObjDictWrapper is a container that provides both dictionary-like and object-like attribute access. """ - def __init__(self, **kwargs): - for key, value in six.iteritems(kwargs): - setattr(self, key, value) + def __getattr__(self, item): + if item in self: + return self[item] + else: + raise AttributeError(item) - def __getitem__(self, item): - return getattr(self, item) + def __setattr__(self, item, value): + self[item] = value - def __setitem__(self, key, value): - setattr(self, key, value) - - def __delitem__(self, key): - delattr(self, key) - - def __contains__(self, item): - return hasattr(self, item) - - def __iter__(self): - return iter(six.itervalues(self.__dict__)) + def __repr__(self): + return '' % super(ObjDictWrapper, self).__repr__()