Port password tests to Python 3
* load_template_source(): use io.open() with an encoding instead of open(), to have the same behaviour on Python 2 and Python 3 * assertRedirectsNoFollow(): remove an useless assertion on the response status code which is already tested a few lines below. The assertion used code/100 which returns a float on Python 3, whereas an int was expected. * add_logout_reason(): don't encode reason to UTF-8 on Python 3 * tox.ini: add openstack_dashboard.dashboards.settings.password to Python 3.4 Partial-Implements: blueprint porting-python3 Change-Id: Iff8997917b5d812952150b2abe89ddd12deab0c0
This commit is contained in:
parent
8cd862767a
commit
c63d7a6390
@ -14,6 +14,7 @@
|
||||
Wrapper for loading templates from "templates" directories in panel modules.
|
||||
"""
|
||||
|
||||
import io
|
||||
import os
|
||||
|
||||
import django
|
||||
@ -54,8 +55,8 @@ class TemplateLoader(tLoaderCls):
|
||||
def load_template_source(self, template_name, template_dirs=None):
|
||||
for path in self.get_template_sources(template_name):
|
||||
try:
|
||||
with open(path) as file:
|
||||
return (file.read().decode(settings.FILE_CHARSET), path)
|
||||
with io.open(path, encoding=settings.FILE_CHARSET) as file:
|
||||
return (file.read(), path)
|
||||
except IOError:
|
||||
pass
|
||||
raise TemplateDoesNotExist(template_name)
|
||||
|
@ -42,7 +42,9 @@ def add_logout_reason(request, response, reason):
|
||||
# Store the translated string in the cookie
|
||||
lang = translation.get_language_from_request(request)
|
||||
with translation.override(lang):
|
||||
reason = six.text_type(reason).encode('utf-8')
|
||||
reason = six.text_type(reason)
|
||||
if six.PY2:
|
||||
reason = reason.encode('utf-8')
|
||||
response.set_cookie('logout_reason', reason, max_age=10)
|
||||
|
||||
|
||||
|
@ -227,8 +227,6 @@ class TestCase(horizon_helpers.TestCase):
|
||||
Asserts that the given response issued a 302 redirect without
|
||||
processing the view which is redirected to.
|
||||
"""
|
||||
assert (response.status_code / 100 == 3), \
|
||||
"The response did not return a redirect."
|
||||
self.assertEqual(response._headers.get('location', None),
|
||||
('Location', settings.TESTSERVER + expected_url))
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
1
tox.ini
1
tox.ini
@ -39,6 +39,7 @@ commands =
|
||||
openstack_dashboard.dashboards.project.images.images.tests.CreateImageFormTests \
|
||||
openstack_dashboard.dashboards.project.images.tests.ImagesAndSnapshotsUtilsTests \
|
||||
openstack_dashboard.dashboards.project.stacks.tests.TemplateFormTests \
|
||||
openstack_dashboard.dashboards.settings.password \
|
||||
openstack_dashboard.test.api_tests.base_tests.APIDictWrapperTests \
|
||||
openstack_dashboard.test.api_tests.base_tests.APIResourceWrapperTests \
|
||||
openstack_dashboard.test.api_tests.base_tests.ApiHelperTests \
|
||||
|
Loading…
Reference in New Issue
Block a user