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
This commit is contained in:
Richard Jones 2015-09-30 12:55:59 +10:00
parent 0f39dea2c7
commit 9e09cfab2e
3 changed files with 35 additions and 21 deletions

View File

@ -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

View File

@ -11,6 +11,7 @@
<script src='{{ STATIC_URL }}horizon/lib/jquery/jquery.js' type='text/javascript' charset="utf-8"></script>
<script src='{{ STATIC_URL }}horizon/lib/jquery/jquery-migrate.js' type='text/javascript' charset="utf-8"></script>
<script src="{{ STATIC_URL }}horizon/lib/jquery/jquery.tablesorter.js"></script>
<script src="{{ STATIC_URL }}horizon/lib/angular/angular.js" type="text/javascript" charset="utf-8"></script>
<script src='{{ STATIC_URL }}horizon/js/horizon.js' type='text/javascript' charset='utf-8'></script>
@ -96,8 +97,22 @@
<script src='{{ STATIC_URL }}horizon/js/horizon.tables_inline_edit.js'></script>
<script src='{{ STATIC_URL }}horizon/js/horizon.tabs.js'></script>
<script>
angular.module('test_app', []).run(updateHorizon);
updateHorizon.$inject = ['$rootScope', '$compile'];
function updateHorizon($rootScope, $compile) {
horizon.utils = {loadAngular: loadAngular};
function loadAngular(element) {
$compile(element)($rootScope);
$rootScope.$apply();
}
}
</script>
</head>
<body>
<body ng-app="test_app">
{% block sidebar %}
{% include 'horizon/common/_sidebar.html' %}

View File

@ -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 '<ObjDictWrapper %s>' % super(ObjDictWrapper, self).__repr__()