diff --git a/openstack_dashboard/dashboards/project/vg_snapshots/tests.py b/openstack_dashboard/dashboards/project/vg_snapshots/tests.py index d66185335c..d14709792b 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 e5caffd291..d80b4fb42a 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 6d2292673e..19afd7c02d 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.