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:
parent
0f39dea2c7
commit
9e09cfab2e
|
@ -31,7 +31,15 @@ class DummyBackend(object):
|
||||||
pk=1111,
|
pk=1111,
|
||||||
save=lambda *args, **kwargs: None,
|
save=lambda *args, **kwargs: None,
|
||||||
is_authenticated=lambda: True,
|
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):
|
def authenticate(self, *args, **kwargs):
|
||||||
return self._user
|
return self._user
|
||||||
|
|
|
@ -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.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-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/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>
|
<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.tables_inline_edit.js'></script>
|
||||||
<script src='{{ STATIC_URL }}horizon/js/horizon.tabs.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>
|
</head>
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
<body ng-app="test_app">
|
||||||
|
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
{% include 'horizon/common/_sidebar.html' %}
|
{% include 'horizon/common/_sidebar.html' %}
|
||||||
|
|
|
@ -10,28 +10,19 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
|
class ObjDictWrapper(dict):
|
||||||
class ObjDictWrapper(object):
|
|
||||||
"""ObjDictWrapper is a container that provides both dictionary-like and
|
"""ObjDictWrapper is a container that provides both dictionary-like and
|
||||||
object-like attribute access.
|
object-like attribute access.
|
||||||
"""
|
"""
|
||||||
def __init__(self, **kwargs):
|
def __getattr__(self, item):
|
||||||
for key, value in six.iteritems(kwargs):
|
if item in self:
|
||||||
setattr(self, key, value)
|
return self[item]
|
||||||
|
else:
|
||||||
|
raise AttributeError(item)
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __setattr__(self, item, value):
|
||||||
return getattr(self, item)
|
self[item] = value
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __repr__(self):
|
||||||
setattr(self, key, value)
|
return '<ObjDictWrapper %s>' % super(ObjDictWrapper, self).__repr__()
|
||||||
|
|
||||||
def __delitem__(self, key):
|
|
||||||
delattr(self, key)
|
|
||||||
|
|
||||||
def __contains__(self, item):
|
|
||||||
return hasattr(self, item)
|
|
||||||
|
|
||||||
def __iter__(self):
|
|
||||||
return iter(six.itervalues(self.__dict__))
|
|
||||||
|
|
Loading…
Reference in New Issue