summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkihiro Motoki <amotoki@gmail.com>2021-02-24 23:32:07 +0900
committerVishal Manchanda <manchandavishal143@gmail.com>2021-09-16 11:18:00 +0000
commit9526289b76d9c5d5bd38a64317f2f8c9ad79cfd4 (patch)
treed252aba65fbadc5f3ecc7acf764faee69c9c59ba
parentbbaf21c4dffe064626aace3d7cdc4a191786da65 (diff)
downloadhorizon-9526289b76d9c5d5bd38a64317f2f8c9ad79cfd4.tar.gz
Support Django 3.2 support (2)
In Django 3.2 CookieStorage stores messages in the RFC 6265 compliant format [1][2]. This means that horizon messages pass through cookies are encoded in a different way that messages are encrypted. Previously horizon UT interpretes messages in cookies literally in its own way, but the change on CookieStorage in Django 3.2 broke it. Horizon should not depend on its own way. The suggested way I believe is to use a method defined in django.contrib.messages.storage.cookie.CookieStorage. [1] https://docs.djangoproject.com/en/3.2/releases/3.2/#miscellaneous [2] https://github.com/django/django/commit/2d6179c819010f6a9d00835d5893c4593c0b85a0 Change-Id: I3e5e12265d0bc7b753bbe1f57acdd663b9dd3587
-rw-r--r--openstack_dashboard/dashboards/project/vg_snapshots/tests.py9
-rw-r--r--openstack_dashboard/dashboards/project/volume_groups/tests.py3
-rw-r--r--openstack_dashboard/test/helpers.py12
3 files changed, 17 insertions, 7 deletions
diff --git a/openstack_dashboard/dashboards/project/vg_snapshots/tests.py b/openstack_dashboard/dashboards/project/vg_snapshots/tests.py
index d66185335..d14709792 100644
--- a/openstack_dashboard/dashboards/project/vg_snapshots/tests.py
+++ b/openstack_dashboard/dashboards/project/vg_snapshots/tests.py
@@ -71,11 +71,10 @@ class GroupSnapshotTests(test.TestCase):
args=[vg_snapshot.id])
res = self.client.post(url, formData)
self.assertNoFormErrors(res)
- # There are a bunch of backslashes for formatting in the message from
- # the response, so remove them when validating the error message.
- self.assertIn('Unable to create group "%s" from snapshot.'
- % new_cg_name,
- res.cookies.output().replace('\\', ''))
+ self.assertCookieMessage(
+ res,
+ 'Unable to create group "%s" from snapshot.' % new_cg_name,
+ 'Expected failure.')
self.assertRedirectsNoFollow(res, INDEX_URL)
mock_group_snapshot_get.assert_called_once_with(
diff --git a/openstack_dashboard/dashboards/project/volume_groups/tests.py b/openstack_dashboard/dashboards/project/volume_groups/tests.py
index e5caffd29..d80b4fb42 100644
--- a/openstack_dashboard/dashboards/project/volume_groups/tests.py
+++ b/openstack_dashboard/dashboards/project/volume_groups/tests.py
@@ -108,8 +108,7 @@ class VolumeGroupTests(test.TestCase):
res = self.client.post(url, formData)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
- self.assertIn("Unable to create group.",
- res.cookies.output())
+ self.assertCookieMessage(res, "Unable to create group.")
self.mock_extension_supported.assert_called_once_with(
test.IsHttpRequest(), 'AvailabilityZones')
diff --git a/openstack_dashboard/test/helpers.py b/openstack_dashboard/test/helpers.py
index 6d2292673..19afd7c02 100644
--- a/openstack_dashboard/test/helpers.py
+++ b/openstack_dashboard/test/helpers.py
@@ -24,6 +24,7 @@ import traceback
from unittest import mock
from django.conf import settings
+from django.contrib.messages.storage import cookie as cookie_storage
from django.contrib.messages.storage import default_storage
from django.core.handlers import wsgi
from django.test.client import RequestFactory
@@ -38,6 +39,7 @@ from requests.packages.urllib3.connection import HTTPConnection
from horizon import base
from horizon import conf
+from horizon import exceptions
from horizon.test import helpers as horizon_helpers
from openstack_dashboard import api
from openstack_dashboard import context_processors
@@ -438,6 +440,16 @@ class TestCase(horizon_helpers.TestCase):
len(errors), 0,
"No errors were found on the workflow")
+ def assertCookieMessage(self, response, expected_msg, detail_msg=None):
+ data = response.cookies["messages"]
+ storage = cookie_storage.CookieStorage(None)
+ messages = [m.message for m in storage._decode(data.value)]
+ if detail_msg is not None:
+ _expected = exceptions._append_detail(expected_msg, detail_msg)
+ else:
+ _expected = expected_msg
+ self.assertIn(_expected, messages)
+
class BaseAdminViewTests(TestCase):
"""Sets an active user with the "admin" role.